Skip to main content

Generate Documents from Scratch with DevExpress PDF Document API

  • 5 minutes to read

This topic describes how to generate a document layout from scratch.

Create an Empty PDF File

Create a PdfDocumentProcessor object and call one of the PdfDocumentProcessor.CreateEmptyDocument overload methods. This method creates an empty PDF file with no pages.

using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
     // Create an empty document
     processor.CreateEmptyDocument("..\\..\\Result.pdf");
}

Add Graphics Content to a Page

Populate a document with graphic content:

View Example: Generate a Document Layout from Scratch

using DevExpress.Drawing;
using DevExpress.Pdf;
using System.Drawing;


using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
     // Create an empty document.
     processor.CreateEmptyDocument("..\\..\\Result.pdf");

     // Create and draw PDF graphics.
     using (PdfGraphics graph = processor.CreateGraphics()) {
     DrawGraphics(graph);

     // Render a page with graphics.
     processor.RenderNewPage(PdfPaperSize.Letter, graph);
     }
}


static void DrawGraphics(PdfGraphics graph) {
     // Draw text lines on the page. 
     DXSolidBrush black = (DXSolidBrush)DXBrushes.Black;
     DXFont font1 = new DXFont("Times New Roman", 32, DXFontStyle.Bold);
     graph.DrawString("PDF Document Processor", font1, black, 180, 150);

     DXFont font2 = new DXFont("Arial", 20);
     graph.DrawString("Display, Print and Export PDF Documents", font2, black, 168, 230);

     DXFont font3 = new DXFont("Arial", 10);
     graph.DrawString("The PDF Document Processor is a non-visual component " +
                    "that provides the application programming interface of the PDF Viewer.", font3, black, 16, 300);
}

See the following topic for more information on PDF Graphics: PDF Graphics

The PDF Document API provides additional settings to customize document generation. See the sections below.

Embed Fonts

The PDF Document API component creates a document with embedded fonts by default.

To prohibit embedding all fonts, set the PdfCreationOptions.DisableEmbeddingAllFonts property to true and pass a PdfCreationOptions object containing this setting as a parameter to one of the PdfDocumentProcessor.CreateEmptyDocument overload methods.

Use the PdfCreationOptions.NotEmbeddedFontFamilies property to specify which font families should not be embedded in a document.

Tip

If you get the No usable version of the ICU libraries was found Aborted message when you try to run your application on Linux, register the DXEXPORT_ICU_VERSION_OVERRIDE environment variable and set it to the current library version, as shown below:

export DXEXPORT_ICU_VERSION_OVERRIDE=65.1?

Specify Compatibility Mode

The following compatibility modes are supported:

  • PDF (ISO 32000-1:2008 ) - default mode
  • PDF/A-1b (ISO 19005-1)
  • PDF/A-2b (ISO 19005-2:2011)
  • PDF/A-3b (ISO 19005-3:2012)

To create a PDF/A-compatible document, set the PdfCreationOptions.Compatibility property to either PdfCompatibility.PdfA1b, PdfCompatibility.PdfA2b or PdfCompatibility.PdfA3b. Then, call the PdfDocumentProcessor.CreateEmptyDocument overload method and pass a PdfCreationOptions object containing this setting as a parameter.

using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    processor.CreateEmptyDocument("..\\..\\Result.pdf", new PdfCreationOptions()
    {
        Compatibility = PdfCompatibility.PdfA2b
    });
}

PDF/A has the following limitations:

  • Non-embedded fonts are not supported;
  • PDF/A-1b and PDF/A-2b documents cannot contain file attachments;
  • Encryption is forbidden;
  • Transparency is not allowed in a PDF/A-1b document (all transparency information is ignored, and no exceptions are raised).

Specify Encryption Settings and Signature

The PDF Document API can protect a document with user and owner passwords. These passwords are used to prevent users from accessing or modifying PDF documents. All required settings to protect a document are contained in the PdfEncryptionOptions object, which can be accessed via the PdfSaveOptions.EncryptionOptions property. To encrypt the document with these settings, call the PdfDocumentProcessor.CreateEmptyDocument overload method and pass the PdfSaveOptions object containing these settings as a parameter. See the Document Protection topic for more information.

Use the PdfSaveOptions.Signature property to specify a signature. See the Sign Document topic to learn more.

See Also