Creating and Editing PDF Documents |
ExpertPdf Anywhere creates PDF documents from scratch and changes existing ones with one document model, the classes in the ExpertPdf.Anywhere.PdfDocument namespace. The same model represents the result of an HTML to PDF conversion, so a converted document can be changed with the same classes before it is saved (see Customizing a Converted Document).
You add pages and place content on them - text in any installed or bundled font, images, lines and shapes, HTML rendered by Chromium, the content of Word and RTF documents - then add bookmarks, links, attachments and templates repeated on the pages, and save the document as PDF, PDF/A, PDF/X, tagged and accessible PDF (PDF/UA-1 or PDF/UA-2) or a ZUGFeRD / Factur-X invoice, password protected or digitally signed. The library runs on Windows, Linux and macOS.
A new document: new Document(), or Document for a PDF/A or PDF/X document. Pages are added with AddPage.
An existing document: the constructors that take a file path or a stream, with a password for an encrypted document. Elements can be added to the pages the document already has and to new pages.
Adding content: create a page element (TextElement, ImageElement, HtmlToPdfElement, ...) and add it to a page or a template with AddElement(PageElement). See Overview.
Saving: Save writes a file or a stream, and Save returns the bytes of the PDF.
Closing: Document implements IDisposable. Create it in a using block, or call Close when you no longer need it.
The code below creates a document with one page, adds a text and an HTML fragment rendered below it, and saves the document. Arial is drawn with the metric-compatible Liberation Sans font that the library bundles when the host does not have Arial.
using ExpertPdf.Anywhere; using ExpertPdf.Anywhere.Drawing; using ExpertPdf.Anywhere.PdfDocument; LicensingManager.LicenseKey = "your license key"; using (Document document = new Document()) { document.DocumentInformation.Title = "Hello"; PdfPage page = document.AddPage(); PdfFont font = document.AddFont(new Font("Arial", 16)); page.AddElement(new TextElement(0, 0, "Hello from ExpertPdf Anywhere", font)); // HTML content below the text HtmlToPdfElement html = new HtmlToPdfElement(0, 40, "<p>Text, <b>styles</b> and images from <i>HTML</i></p>", null); page.AddElement(html); document.Save("hello.pdf"); }
Pages of any size and orientation, mixed in one document, inserted, removed and rotated. See Document Class and PdfPage Class.
Templates repeated on the pages: headers, footers, watermarks, page numbers. See Template Class.
HTML content rendered by Chromium in a page area, continued on the next pages when it does not fit. See HTML to PDF Converter Element.
The content of a Word or RTF document in a page area. See Word to PDF Element.
Text, fonts, images and shapes. See Text Element and Fonts, Image Element and Shape Elements.
Bookmarks, links, named destinations, page labels and a table of contents with page numbers. See Bookmarks and Document Class.
Merging documents and extracting pages. See Merge and Split.
PDF/A, PDF/X, tagged PDF and PDF/UA. See PDF Standards and Tagged PDF.
ZUGFeRD / Factur-X electronic invoices. See Electronic Invoices.
Passwords, permissions and digital signatures. See Digital Signature Element and Passwords and Encryption.