XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
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 comment
  |  
Home ›› XDoc.PDF ›› C# PDF: Add Text

C#.NET PDF SDK - Annotate Text on PDF Page in C#.NET


C# Control Enable Users to Add Text Annotation to PDF Page in .NET Application Using C# Programming Language




A best PDF annotation SDK control for Visual Studio .NET can help to add text to PDF document using C#


Provide evaluation library to edit PDF text annotation online in ASP.NET web project


Able to add text to adobe PDF document in Visual C# .NET WinForms class


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


Free online C# source code for annotating text on PDF page in C#.NET framework application


Able to create text annotation on selected page or specified position


Support to edit PDF text comments color, size and font


Adding text is the most direct method to add or supplement information on current PDF page. RasterEdge XDoc.PDF SDK provides this annotation functionality to help C# users add any texts to any position on PDF pages.


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 comment 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_11.pdf";

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

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

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

annot.Content = @"This is a text annotation";

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

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




C# read text comment annotation from pdf document





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

PDFDocument doc = new PDFDocument(inputFilePath);
List<IPDFAnnot> annots = PDFAnnotHandler.GetAllAnnotations(doc);
foreach (IPDFAnnot annot in annots)
{
    if (annot is PDFAnnotText)
    {
        PDFAnnotText obj = (PDFAnnotText)annot;
        Console.WriteLine("Text Color: " + obj.TextColor.ToString());
        Console.WriteLine("Text Boundary: " + obj.Boundary.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:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;