Back to Devexpress

Generate Documents from Scratch with DevExpress PDF Document API

officefileapi-118794-pdf-document-api-document-generation.md

latest9.0 KB
Original Source

Generate Documents from Scratch with DevExpress PDF Document API

  • Nov 07, 2025
  • 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.

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
     // Create an empty document
     processor.CreateEmptyDocument("..\\..\\Result.pdf");
}
vb
Using processor As PdfDocumentProcessor = New PdfDocumentProcessor()
     ' Create an empty document.
     processor.CreateEmptyDocument("..\..\Result.pdf")
End Using

Add Graphics Content to a Page

Populate a document with graphic content:

  • Create a PdfGraphics objectusing one of the PdfDocumentProcessor.CreateGraphics*System methods. Each method creates a graphics context based on a specific coordinate system (page, user, or world).

  • Call the Draw method for corresponding elements (for example, the PdfGraphics.DrawString overload method draws a text string at the specified location with the specified SolidBrush and Font objects).

  • Render a page with created graphics by calling the PdfDocumentProcessor.RenderNewPage overload method.

View Example: Generate a Document Layout from Scratch

csharp
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.CreateGraphicsPageSystem()) {
     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);
}
vb
Imports DevExpress.Drawing
Imports DevExpress.Pdf
Imports System.Drawing

Using processor As PdfDocumentProcessor = New PdfDocumentProcessor()
     ' Create an empty document.
     processor.CreateEmptyDocument("..\..\Result.pdf")
     ' Create and draw PDF graphics.
     Using graph As PdfGraphics = processor.CreateGraphicsPageSystem()
     DrawGraphics(graph)
     ' Render a page with graphics.
     processor.RenderNewPage(PdfPaperSize.Letter, graph)
     End Using
End Using

Private Shared Sub DrawGraphics(ByVal graph As PdfGraphics)
     ' Draw text lines on the page.
     Dim black As DXSolidBrush = CType(DXBrushes.Black, DXSolidBrush)
     Dim font1 As DXFont = New DXFont("Times New Roman", 32, DXFontStyle.Bold)
     graph.DrawString("PDF Document Processor", font1, black, 180, 150)

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

     Dim font3 As DXFont = 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)
End Sub

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.

csharp
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
    processor.CreateEmptyDocument("..\\..\\Result.pdf", new PdfCreationOptions()
    {
        Compatibility = PdfCompatibility.PdfA2b
    });
}
vb
Imports (PdfDocumentProcessor processor = New PdfDocumentProcessor())
{
    Private Function PdfCreationOptions() As processor.CreateEmptyDocument("..\\..\\Result.pdf",Shadows
         Compatibility = PdfCompatibility.PdfA2b
    End Function
    )
}

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

How to: Generate a PDF Document Layout with a Watermark from Scratch

How to: Protect a PDF Document with a Password