Articles in this section
Category / Section

How to modify the size of the annotation in PDF using C# and VB.NET

4 mins read

The Syncfusion Essential® PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can modify the size of the annotation in a PDF using C# and VB.NET.

Steps to modify the size of the annotation in a PDF programmatically:

  1. Create a new C# Windows Forms application project. Create new Windows forms application
  2. Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from NuGet.org. Install Nuget packages
  3. Include the following namespaces in the Form.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Interactive;
using Syncfusion.Pdf.Parsing;
using System.Drawing;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Pdf.Interactive
Imports Syncfusion.Pdf.Parsing
Imports System.Drawing

 

  1. Use the following code snippet to modify the size of the annotation in an existing PDF document.

C#

// Loads the document
PdfLoadedDocument lDoc = new PdfLoadedDocument("Annotation.pdf");
// Gets the first page of the document
PdfLoadedPage page = lDoc.Pages[0] as PdfLoadedPage;
// Gets the annotation collection
PdfLoadedAnnotationCollection annotations = page.Annotations;
foreach(PdfLoadedAnnotation annot in annotations)
{
    // Select the Free text annotation in collection and change its size
    if(annot is PdfLoadedFreeTextAnnotation)
    {
       PdfLoadedFreeTextAnnotation freeTextAnnot = annot as PdfLoadedFreeTextAnnotation;
       RectangleF annotBounds = freeTextAnnot.Bounds;
       freeTextAnnot.Bounds = new RectangleF(annotBounds.X, annotBounds.Y, 200, 100);   
      }
}
// Save and close the document
lDoc.Save("ModifiedAnnot.pdf");
lDoc.Close(true);
// This will open the PDF file so, the result will be seen in default PDF Viewer
Process.Start( "ModifiedAnnot.pdf");

 

VB.NET

'Loads the document
Dim lDoc As PdfLoadedDocument = New PdfLoadedDocument(("Annotation.pdf"))
'Gets the first page of the document
Dim page As PdfLoadedPage = CType(lDoc.Pages(0), PdfLoadedPage)
'Gets the annotation collection
Dim annotations As PdfLoadedAnnotationCollection = page.Annotations
For Each annot As PdfLoadedAnnotation In annotations
    'Select the Free text annotation in collection and change its size
    If (TypeOf annot Is PdfLoadedFreeTextAnnotation) Then
        Dim freeTextAnnot As PdfLoadedFreeTextAnnotation = CType(annot,PdfLoadedFreeTextAnnotation)
        Dim annotBounds As RectangleF = freeTextAnnot.Bounds
        freeTextAnnot.Bounds = New RectangleF(annotBounds.X, annotBounds.Y, 200, 100)
    End If
Next
'Save and close the document
lDoc.Save("ModifiedAnnot.pdf")
lDoc.Close(True)
'This will open the PDF file so, the result will be seen in default PDF Viewer
Process.Start("ModifiedAnnot.pdf")

 

A complete working sample can be downloaded from ModifyAnnotationSize.zip

The loaded PDF with annotation is shown below: Loaded PDF with annotation

By executing the program, you will get the PDF document as follows. Screenshot of output PDF file

Take a moment to peruse the documentation, where you can find other options like adding annotation to PDF, flatten annotation, modifying annotation, and removing annotation with code examples.

Refer here to learn more about PDF annotation.

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from a trial setup or from 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 create Excel exploded pie chart in C#, VB.NET.

You can refer to our PDF feature tour page to learn about its other groundbreaking feature representations. You can also explore our documentation 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