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

C#.NET PDF SDK - Insert Text to PDF Document in C#.NET


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




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


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.




C#.NET Project DLLs: Insert Text Content to PDF



In order to run the sample code, the following steps would be necessary.


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;


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.




C#.NET Sample Code: Insert Text Character to PDF 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);





C#.NET Sample Code: Insert Text String to PDF 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);





public int AddChar(char value, Font font, int pageIndex, PointF postion)

Description:
     Add a char value at specified page position with specified font.

Parameters:

Return:
     Error code, 0 if success.



public int AddChar(char value, Font font, int pageIndex, PointF postion, Color fontColor)

Description:
     Add a char value at specified page position with specified font and color.

Parameters:

Return:
     Error code, 0 if success.



public int AddChar(char value, PSType1Font fontType, float fontSize, PointF postion, Color fontColor, int pageIndex)

Description:
     Add a char value at specified page position with specified font and color

Parameters:

Return:
     Error code, 0 if success.



public int AddString(String value, Font font, int pageIndex, PointF postion, Color fontColor)

Description:
     Add a string at specified page position with specified font and color.

Parameters:

Return:
     Error code, 0 if success.



public int AddString(String value, PDFPage page, PSType1Font fontType, float fontSize, PointF postion, Color fontColor)

Description:
     Add a string text value at specified page position with specified font and color

Parameters:

Return:
     Error code, 0 if success.