The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

Document Generation

  • 4 min to read

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

Firstly, create a document that has no pages by creating a PdfDocumentProcessor object and calling one of the PdfDocumentProcessor.CreateEmptyDocument overload methods.

These methods can be called using a stream, a file path (see the code snippet below), creation options (represented by an instance of the PdfCreationOptions class) or save options (represented by an instance of the PdfSaveOptions class).

Populate a document with graphic content:

  • Draw graphics on a page by creating a PdfGraphics object using the PdfDocumentProcessor.CreateGraphics method and calling 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).

    Note

    You need to reference the DevExpress.Pdf.Drawing assembly to draw graphic content on a page because it requires an instance of the PdfGraphics class.

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

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T244516.


void DoSomething()
{
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
     processor.CreateEmptyDocument("..\\..\\Document.pdf");

     using (PdfGraphics graph = processor.CreateGraphics()) {
          DrawGraphics(graph);
          processor.RenderNewPage(PdfPaperSize.Letter, graph);
     }
}
}

private void DrawGraphics(PdfGraphics graph)
{
     SolidBrush black = (SolidBrush)Brushes.Black;
     using (Font font = new Font("Times New Roman", 32, FontStyle.Bold))
     {
          graph.DrawString("PDF Document Processor", font, black, 180, 150);
     }
}

See the PDF Graphics topics for more information about 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 a Document's 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