How to use the graphics clipping using ByteScout PDF SDK

  • Home
  • /
  • Articles
  • /
  • How to use the graphics clipping using ByteScout PDF SDK

This example demonstrates how to use the graphics clipping using ByteScout PDF SDK.

Program.vb:
VB

'*******************************************************************
'       ByteScout PDF SDK
'                                                                   
'       Copyright © 2016 Bytescout, http://www.bytescout.com        
'       ALL RIGHTS RESERVED                                         
'                                                                   
'*******************************************************************

Imports System.Drawing
Imports Bytescout.PDF

''' <summary>
''' This example demonstrates how to use the graphics clipping.
''' </summary>
Class Program

    Shared Sub Main()

        ' Create new document
        Dim pdfDocument = New Document()
        pdfDocument.RegistrationName = "demo"
		pdfDocument.RegistrationKey = "demo"
        ' Add page
        Dim page = New Page(PaperFormat.A4)
        pdfDocument.Pages.Add(page)
        
        Dim center = New PointF(200, 200)

        ' Create clipping path from circle
        Dim path = New Path()
        path.AddCircle(center, 100)
        page.Canvas.SetClip(path)

        ' Paint Bytescout.PDF.Rectangle over the clipping circle.
        ' Only part of the Bytescout.PDF.Rectangle intersecting the clipping circle will be drawn.
        Dim brush = New Bytescout.PDF.SolidBrush(New ColorRGB(255, 0, 0))
        page.Canvas.DrawRectangle(brush, center.X - 50, center.Y - 50, 200, 200)

        ' Save document to file
        pdfDocument.Save("result.pdf")

        ' Cleanup 
        pdfDocument.Dispose()

        ' Open document in default PDF viewer app
        Process.Start("result.pdf")

    End Sub

End Class 

Program.cs:
C#

//*******************************************************************
//       ByteScout PDF SDK		                                     
//                                                                   
//       Copyright © 2016 ByteScout - http://www.bytescout.com       
//       ALL RIGHTS RESERVED                                         
//                                                                   
//*******************************************************************

using System;
using System.Diagnostics;
using System.Drawing;
using Bytescout.PDF;
using SolidBrush = Bytescout.PDF.SolidBrush;

namespace Clipping
{
	/// <summary>
	/// This example demonstrates how to use the graphics clipping.
	/// </summary>
	class Program
	{
		static void Main()
		{
			// Create new document
			Document pdfDocument = new Document();
			pdfDocument.RegistrationName = "demo";
			pdfDocument.RegistrationKey = "demo";
			// Add page
			Page page = new Page(PaperFormat.A4);
			pdfDocument.Pages.Add(page);

			PointF center = new PointF(200, 200);

			// Create clipping path from circle
			Path path = new Path();
			path.AddCircle(center, 100);
			page.Canvas.SetClip(path);

			// Paint rectangle over the clipping circle.
			// Only part of the rectangle intersecting the clipping circle will be drawn.
			SolidBrush brush = new SolidBrush(new ColorRGB(255, 0, 0));
			page.Canvas.DrawRectangle(brush, center.X - 50, center.Y - 50, 200, 200);

			// Save document to file
			pdfDocument.Save("result.pdf");

			// Cleanup 
			pdfDocument.Dispose();

			// Open document in default PDF viewer app
			Process.Start("result.pdf");
		}
	}
} 

prev
next