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 Editor Library
How to add, insert text into existing PDF file page content, header, footer using C#.net with example


Providing C# Demo Code for Adding and Inserting Text to PDF File Page with .NET PDF Library





In this tutorial, you learn how to add text content to existing PDF file in the C# ASP.NET MVC Web, Windows applications.

  • Add text character, string
  • Add text paragraph
  • Add a text hyperlink
  • Add a text annotation object
  • Add text, such as page numbers to PDF page header and footer

How to add, insert text in PDF file using C#

  1. Download XDoc.PDF Text Editor C# library
  2. Install C# library to add text inside PDF document
  3. Step by Step Tutorial


























  • Best and multifunctional Visual Studio .NET PDF SDK supports adding and inserting text content to adobe PDF document in C#
  • Able to inserting text to PDF in Visual C# .NET class using free trial components and library for .NET framework
  • .NET Core PDF C# library includes: c# remove text from pdf, get coordinates of text in pdf c#, extract text from pdf c#, replace text in pdf c#, c# pdf add image.
  • Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
  • Able to add a single text character and text string to PDF files using online source codes in C#.NET class program
  • Insert formatted text and plain text to PDF page using .NET XDoc.PDF component in C#.NET class
  • Supports adding text to PDF in preview without adobe reader installed in ASP.NET
  • Powerful .NET PDF edit control allows modify existing scanned PDF text
  • Ability to change text font, color, size and location and output a new PDF document


XDoc.PDF for .NET empowers C# developers to add multiple text processing functions to PDF document imaging application, such as inserting text to PDF, deleting text from PDF, searching text in PDF, extracting text from PDF, and so on. On this tutorial page, we will demonstrate how to use C#.NET class code to add and insert text to PDF file page.

In general, C# developers can add text character and text string to a certain position of PDF document page. In the following parts, detailed C# class demos are provided.









Add text to PDF content using C#


With XDoc.PDF sdk, you can easily add, insert text chars, text string to pdf page with specified location, and text style format.







Add, insert text character to existing PDF document using C#.NET


This C# coding example describes how to add a single text character to PDF document.



//  open a document
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
//  get a text manager from the document object
PDFTextMgr textMgr = PDFTextHandler.ExportPDFTextManager(doc);

//  set char value
char aChar = 'A';
//  set text font
Font font = new Font("Arial", 36F, FontStyle.Regular);
//  get the first page from the document
int pageIndex = 0;
//  move cursor to (400F, 100F)
PointF cursor = new PointF(400F, 100F);

//  add a character to the page
textMgr.AddChar(aChar, font, pageIndex, cursor);

//  output the new document
String outputFilePath = Program.RootPath + "\\" + "output.pdf";
doc.Save(outputFilePath);




Add, insert text String to existing PDF document using C#.NET


If you want to add a text string to PDF file, please try this C# demo.



//  open a document
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
PDFDocument doc = new PDFDocument(inputFilePath);
//  get a text manager from the document object
PDFTextMgr textMgr = PDFTextHandler.ExportPDFTextManager(doc);

//  set string value
String msg = "Hello World";
//  set text font
Font font = new Font("Arial", 36F, FontStyle.Italic);
//  get the first page from the document
int pageIndex = 0;
//  move cursor to (400F, 100F)
PointF cursor = new PointF(400F, 100F);
//  set font color: red
Color fontColor = Color.Red;

//  add a string to the page
textMgr.AddString(msg, font, pageIndex, cursor, fontColor);

//  output the new document
String outputFilePath = Program.RootPath + "\\" + "output.pdf";
doc.Save(outputFilePath);




Add text paragraph to a new PDF file


The above two examples explain how to add text content to an exsting PDF document. If you create a new PDF document from scratch, you can use PDF builder class PDFBuildHandler to add text line, text paragraph.

Please go to page How to add a paragraph of text to PDF from scratch for details









Add a hyperlink to PDF document using C#


In PDF document, a hyperlink is linked with an area inside the PDF page. The following C# example source code explains how to a link to a pdf page.



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

//  Open file
PDFDocument doc = new PDFDocument(inputFilePath);
//  Get a text manager from the document object
PDFTextMgr textMgr = PDFTextHandler.ExportPDFTextManager(doc);

//  Set string value
String msg = "Go to Google.com";
String hyperlink = "https://www.google.com";
//  Set text font
Font font = new Font("Arial", 36F, FontStyle.Italic);
//  Get the first page from the document
int pageIndex = 0;
//  Move cursor to (100F, 200F)
PointF cursor = new PointF(100F, 200F);
//  Set font color: red
Color fontColor = Color.Red;

//  Add a string with hyperlink to the page
textMgr.AddHyperlink(msg, hyperlink, font, pageIndex, cursor, fontColor);

//  Save file
doc.Save(outputFilePath);








C#: add text object to PDF


Besides adding text to PDF content, you can also add text object to the PDF document, such as text annotation, text box annotation, text annotation at cursor.









Add textbox annotation


If you want to add a textbox annotation to PDF file, please try this C# example source code.



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




Add text annotation


If you want to add a text annotation to PDF file, please try this C# example source code.



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




Add text annotation at cursor


If you want to add a text annotation at cursor to PDF file, please try this C# example source code.



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

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

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

annot.Position = new PointF(300F, 500F);

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

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






Add dynamic text (page number, date) to PDF page header and footer using C#


If you need add dynamic text content (page number, date) to PDF page header and footer region, please go to How to add, edit PDF file page header, footer using c# for details