Articles in this section
Category / Section

How to use C# to conduct PDF path clipping with the exclude option?

7 mins read

The Syncfusion Essential® PDF is a feature-rich and high-performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. This library also offers functionality to merge, split, stamp, forms, compress, and secure PDF files.

 

you can perform PDF path clipping with the exclude option in the PDF document in the ASP.NET Core platform using C#.

 

Steps to perform PDF path clipping with exclude option using C#

  1. Create a new ASP.NET Core MVC application.

 

Create a new ASP.Net Core application

 

  1. Install the Syncfusion.Pdf.Net.Core NuGet packages as a reference to your .NET Core project from NuGet.org.

Install the Syncfusion PDF NetCore NuGet

 

  1. Add a new button (Create Document) in the Index.cshtml as shown in the following image:

 

Create a Button to generate the PDF

cshtml:

@{
Html.BeginForm("GeneratePDF", "Home", FormMethod.Get);
    {
        <div>
            <input type="submit" value="Create Document" style="width:150px;height:27px;margin-top: 50px;" />
        </div>
    }
    Html.EndForm();
} 
  1.  Include the following namespaces in the HomeController.cs file.

 

using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using System.IO;

 

  1. Add Add a new action method GeneratePDF in the HomeController.cs and include the following code sample to perform exclude clipping in a PDF file and download it.

 

// Create a PDF Document.
PdfDocument doc = new PdfDocument();
 
// Add pages to the document
PdfPage page = doc.Pages.Add();
 
// Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
 
// Create PDF font.
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular);
 
// Create PDF path.
PdfPath path = new PdfPath();
 
// Add outer clipping region.
path.AddRectangle(new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height));
 
// Add inner clipping region.
path.AddEllipse(new RectangleF(10, 10, 150, 70));
 
// Clip path in the graphics
graphics.SetClip(path, PdfFillMode.Alternate);
  1. Build and run the application, the website will open in the browser, then, you can achieve the exclude clipping behavior from the PDF document.

 

Output Browser window

 

  1. By executing the program, you will get the PDF document as follows:

 

Output pdf

 

A complete work sample can be downloaded from ExcludeClipping.zip

 

Take a moment to peruse the documentation. You can find the other options like add text, various formats of imagestables and shapes. Also,  add, modify and remove interactive elements such as bookmarksannotations and attachments and features like encrypt and decrypt PDF document and digitally sign a PDF file with code examples.

Refer to this link to explore a rich set of Syncfusion Essential® PDF features.


Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion:

I hope you enjoyed learning about how to use C# to conduct PDF path clipping with the exclude option.

 

You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied