How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Text Edit Library
How to add, delete, update text box to existing pdf file using C# .net


C# Explanation to How to Add Text Box to PDF Page in C# Project with .NET PDF Library. ASP.NET Annotate PDF function is based on C# PDF Annotate SDK.





In this C# tutorial, you learn how to add, read, extract, remove Text Box annotation from existing PDF file.

How to insert, extract, remove Text Box annotation to PDF file in C#

  1. Download XDoc.PDF Text Comment C# library
  2. Install C# library to edit Text box annotation to PDF document
  3. Step by Step Tutorial








  • A best PDF annotator for Visual Studio .NET supports to add text box to PDF file in Visual C#.NET project
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Provide .NET SDK library for adding text box to PDF document in .NET WinForms application
  • A web based PDF annotation application able to add text box comments to adobe PDF file online in ASP.NET
  • Support to use C# source code to add text box to specified PDF position in C#.NET framework
  • Able to create a fillable and editable text box to PDF document in C#.NET class
  • Support to change font color in PDF text box
  • Ability to change text size in PDF text box


Adding text box is another way to add text to PDF page. With RasterEdge XDoc.PDF annotation control, users can also perform this work on PDF page in their C# program.

Since RasterEdge XDoc.PDF SDK is based on .NET framework 2.0, users are enabled to use it in any type of a 32-bit or 64-bit .NET application, including ASP.NET web service and Windows Forms for any .NET Framework version from 2.0 to 4.5.





C# add text box annotation to pdf document


You can use the C# class PDFAnnotTextBox to create a text box annotation which contains text. You can position it anywhere on the PDF page and adjust it to any size.

The C# sample code below will instruct how to add, insert a "Text Box annotation" to an existing PDF file.

  • Get the PDF page object PDFPage to add text annotation
  • Create a new PDFAnnotTextBox object
  • Set the text box annotation width, height and left top point location on the PDF page
  • Save the PDF document



String inputFilePath = Program.RootPath + "\\" + "2.pdf";
String outputFilePath = Program.RootPath + "\\" + "Annot_9.pdf";

//  open a PDF file
PDFDocument doc = new PDFDocument(inputFilePath);
//  get the 1st page
PDFPage page = (PDFPage)doc.GetPage(0);

//  create the annotation
PDFAnnotTextBox annot = new PDFAnnotTextBox();

annot.Boundary = new RectangleF(100F, 100F, 400F, 300F);

//  add annotation to the page
PDFAnnotHandler.AddAnnotation(page, annot);

//  save to a new file
doc.Save(outputFilePath);




C# read text box annotation from pdf document


String inputFilePath = Program.RootPath + "\\" + "Annot_9.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);
foreach (IPDFAnnot annot in annots)
{
    if (annot is PDFAnnotTextBox)
    {
        PDFAnnotTextBox obj = (PDFAnnotTextBox)annot;
        Console.WriteLine("Textbox Boundary: " + obj.Boundary.ToString());
        Console.WriteLine("Textbox Border Color: " + obj.LineColor.ToString());
        Console.WriteLine("Textbox Border Width: " + obj.LineWidth);
        Console.WriteLine("Textbox Fill Color: " + obj.FillColor.ToString());
    }
}




C# delete all annotations from pdf document


String inputFilePath = Program.RootPath + "\\" + "1_Annots.pdf";

PDFDocument doc = new PDFDocument(inputFilePath);
//  get all annotations in the 1st page
PDFPage page = (PDFPage)doc.GetPage(0);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(page);
//  remove all annotations in the 1st page
PDFAnnotHandler.DeleteAnnotation(doc, annots);