To add text to a PDF document, do the following:
- Create a PDFXpress object and initialize it.
- Create a Document object from an existing PDF file.
- Create an AddTextOptions object.
- Set the AddTextOptions:
- FontSize – we chose 14
- FontWeight – we chose bold
- Call AddText() on the Document object.
- Create a SaveOptions object.
- Call Save() on the Document object to save the PDF with text added.
C# Example | Copy Code |
---|---|
using System; using Accusoft.PdfXpressSdk; namespace Text { class AddText { static void Main(string[] args) { using (PdfXpress pdf = new PdfXpress()) { pdf.Initialize(@"C:\Users\Public\Documents\Accusoft\PDFXpress\v5.0\Support\Font", @"C:\Users\Public\Documents\Accusoft\PDFXpress\v5.0\Support\CMap"); using (Document doc = new Document(pdf, "C:\\myfile.pdf")) { AddTextOptions options = new AddTextOptions(); options.FontSize = 14; options.FontWeight = FontWeight.Bold; doc.AddText(options, 0, "Hello world!"); //set the save options SaveOptions so = new SaveOptions(); so.Filename = "C:\\text.pdf"; so.Overwrite = true; so.Linearized = true; //save the document doc.Save(so); } } } } } |