Modify Existing Pdf Documents | |
Select.Pdf Library for .NET can be used to load and modify existing pdf documents. The following sample code shows how to load a pdf document from a local file from the disk:
The PdfDocument object also provides constructors that can be used to load the pdf document from a stream.
Once a pdf document is loaded, all operations described in this documentation can applied to it: add new pages to the document, remove existing pages, add new elements to new or existing pages, add new pdf templates.
A damaged document is repaired when it is loaded, as PDF viewers do. Set AutoRepair to False to refuse such documents instead; a repaired document is saved in full, so a digital signature it carried no longer verifies.
This sample code shows how to use SelectPdf Library for .NET to load an existing document, add a new page to it and a new text element.
// the initial file string file = "doc1.pdf"; // load the pdf document PdfDocument doc = new PdfDocument(file); // add a new page to the document PdfPage page = doc.AddPage(); // create a new pdf font (component standard font) PdfFont font = doc.Fonts.Add(PdfStandardFont.Helvetica); font.Size = 20; // create text element and add it to the new page PdfTextElement text = new PdfTextElement(100, 100, "Sample text added to an existing pdf document.", font); page.Add(text); // save pdf document doc.Save("Sample.pdf"); // close pdf document doc.Close();