Click or drag to resize

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.

Creating, loading and saving a document
  • 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.

Quick start

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");
}
What the document model offers
See Also