Tech Specs
How-to C#
How-to VB.NET
C# PDF: How to HTML5 Viewer & Editor PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Text box
Home ›› XDoc.PDF ›› C# PDF: Add Text Box

C#.NET PDF SDK - Add Text Box to PDF Page in C#.NET

C# Explanation to How to Add Text Box to PDF Page in C# Project with .NET PDF Library

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

Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:


       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.


       If using x86, the platform target should be x86.

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

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);

.NET Class Namespace Required

Add necessary references:









Use corresponding namespaces;

  using RasterEdge.Imaging.Basic;

  using RasterEdge.XDoc.PDF;