How to flatten the annotation on a specific layer from an existing PDF?
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.
Using this library, you can flatten the annotation on a specific layer from an existing PDF in C# and VB.NET. This application uses the following annotation for flattening.
Steps to flatten the annotation on a specific layer form existing PDF programmatically in C#:
-
Create a new C# console application project.
-
Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org.
-
Include the following code snippet in main method of Program.cs file to flatten the annotation on a specific layer.
C#
//Load the existing PDF document PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Sample.pdf"); //Get all the pages foreach (PdfLoadedPage loadedPage in loadedDocument.Pages) { //Flatten all the annotations in the page foreach (PdfLoadedAnnotation annotation in loadedPage.Annotations) { //Check for the circle annotation if (annotation is PdfLoadedCircleAnnotation) { //Flatten the circle annotation annotation.Flatten = true; //remove annotation layer from loadedDocument loadedDocument.Layers.Remove(annotation.Layer); } } } //Save and close the PDF document instance loadedDocument.Save("FlattenOutput.pdf"); loadedDocument.Close(true);
'Load the existing PDF document Dim loadedDocument As New PdfLoadedDocument("Sample.pdf") 'Get all the pages For Each loadedPage As PdfLoadedPage In loadedDocument.Pages ' Flatten all the annotations in the page For Each annotation As PdfLoadedAnnotation In loadedPage.Annotations ' Check for the circle annotation If TypeOf annotation Is PdfLoadedCircleAnnotation Then ' Flatten the circle annotation annotation.Flatten = True ' Remove annotation layer from loadedDocument loadedDocument.Layers.Remove(annotation.Layer) End If Next Next 'Save and close the PDF document instance loadedDocument.Save("FlattenOutput.pdf") loadedDocument.Close(True)
By executing the program, you will get the PDF document as follows.
A complete work sample for flattening the annotation on a specific layer form existing PDF can be downloaded from Flatten-Annotation-specific_layer.zip
Take a moment to peruse the documentation, where you can find options like adding layers in a PDF document, adding annotation to layer, nested layers, and toggling the visibility of layers with code examples.
Refer here to explore the rich set of Essential Studio project.
Note:
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.
Conclusion
I hope you enjoyed learning about how to flatten the annotation on a specific layer from an existing PDF.
You can refer to our WinForms PDF page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
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, Direct-Trac, or feedback portal. We are always happy to assist you!