Export to PDF

  • 6 minutes to read

Use the RichEditDocumentServer.ExportToPdf method to save a document in PDF format. You can pass a PdfExportOptions class instance to this method to define export options.

The following code sample specifies PDF export options and converts a document to PDF format:

View Example

using DevExpress.XtraRichEdit;
using DevExpress.XtraPrinting;
using System.IO;
//...

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    // Load a DOCX document.
    wordProcessor.LoadDocument("Documents\\MovieRentals.docx");

    // Specify export options.
    PdfExportOptions options = new PdfExportOptions();
    options.DocumentOptions.Author = "Mark Jones";
    options.Compressed = false;
    options.ImageQuality = PdfJpegImageQuality.Highest;

    // Export the document to a stream.
    using (FileStream pdfFileStream = new FileStream("Document_PDF.pdf", FileMode.Create))
    {
        wordProcessor.ExportToPdf(pdfFileStream, options);
    }
}

Tip

If you get the No usable version of the ICU libraries was found Aborted message when you 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?

PDF Document Versions

When you export a document to PDF, the version of the output PDF file depends on the specified security options. You can save a document as a PDF file with one of the following versions:

PDF 1.4 (default)
Used if you do not enable Password Security. (Supported in Adobe Acrobat 5.0 or later)
PDF 1.6
Used if you enable Password Security and set the PdfPasswordSecurityOptions.EncryptionLevel property to AES128 or ARC4. (Supported in Adobe Acrobat 7.0 or later)
PDF 1.7
Used if you enable Password Security and set the PdfPasswordSecurityOptions.EncryptionLevel property to AES256. (Supported in Adobe Acrobat 9.0 or later)

Export Options

Page Range

The Page Range option specifies the range of pages that should be exported as a PDF file. For example, the “1,3,5-12” range exports the first, third, and all the pages from 5 to 12.

PDF/A Compatibility

You can use the Pdf/A Compatibility option to make the output PDF file compatible with the PDF/A specification. To do this, set this option to one of the following values:

  • PDF/A-1a (based on PDF/A-1b with conformance for accessibility)
  • PDF/A-1b (ISO 19005-1)
  • PDF/A-2a (based on PDF/A-2b with conformance for accessibility)
  • PDF/A-2b (ISO 19005-2:2011)
  • PDF/A-3a (based on PDF/A-3b with conformance for accessibility)
  • PDF/A-3b (ISO 19005-3:2012)

The exported PDF file conforms to ISO 32000-1:2005 if this option is set to None (default).

When you create a PDF/A compatible document, you can add additional metadata to the exported PDF file.

Refer to the following topic for more information on how to save a document as a PDF file that conforms to the PDF/A specification: How to: Convert a Word Document to PDF Format.

Limitations

The following PDF export options are not supported for PDF/A compatible documents:

If you export a document to a PDF/A compatible document in code, use the Validate method to check whether the specified export options can be used for PDF/A compatible documents.

PDF/UA Compatibility

Use the Pdf/UA Compatibility option to make the output PDF file compatible with the PDF/UA specification. If you set this option to PDF/UA1, the resulting file meets the ISO 14289 standard that defines requirements for accessible PDF documents.

Refer to the following topic for more information on how to save a document as a PDF file that conforms to the PDF/UA specification: How to: Convert a Word Document to PDF Format.

Limitations

File Size Optimization

Use the options below to decrease the size of the exported PDF file.

Image Quality

Enable the Convert Images To JPEG option to convert all images to JPEG. An image is converted to JPEG if the size of a JPEG image is smaller than the original image size. When the option is enabled, you can specify the Image Quality option to change the image quality and set the Rasterization Resolution option to define the image resolution.

Never Embedded Fonts

Use the Do Not Embed These Fonts option to specify fonts that should not be embedded in the output PDF file.

Password Security

Use the Password Security options to specify an open password and define permissions to copy, print, and use screen readers for the exported PDF file. To encrypt PDF document content, set the encryption level to one of the following algorithms:

  • 128-bit AES (Advanced Encryption Standard)—the default algorithm
  • 256-bit AES (Advanced Encryption Standard)
  • 128-bit ARC4 (Alleged Rivest Cipher 4)

Digital Signature

You can sign a document with an X.509 certificate when you export it to PDF. The specified signature information is saved to the document’s PDF Signature Options.

Document Options

Use Document Options to specify information that should be embedded as Document Properties in the exported PDF file.

Show Print Dialog On Open

Enable the Show Print Dialog On Open option to invoke a print dialog when users open the exported PDF file. Do not use this option in web applications because most modern browsers disable scripts in PDF.

Specify Background Color for a PDF Document

You can fill the background for the output PDF file with a custom color. Enable the PrintingOptions.EnablePageBackgroundOnPrint option and call the SubDocument.SetPageBackground method to specify the page background color.

using DevExpress.XtraRichEdit;
using System.Drawing;

using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer())
{
    // Load a DOCX document.
    wordProcessor.LoadDocument("Documents\\MovieRentals.docx", DocumentFormat.OpenXml);

    // Enable printing the page background.
    wordProcessor.Options.Printing.EnablePageBackgroundOnPrint = true;

    // Specify the document background color.
    wordProcessor.Document.SetPageBackground(Color.Blue);

    // Export the document to PDF.
    wordProcessor.ExportToPdf("Document.pdf");
}

Limitations

  • Glyph Shaping does not work for non-embedded fonts.
  • Support for right-to-left languages with non-embedded fonts requires that your application runs under full trust.
  • Export of vector WMF images is not supported. Only EMF and EMF+ are available.
  • In Adobe Reader, hyperlinks in exported PDF files work only if the Create links from URLs option is enabled.

    To access this option in the program’s Edit menu, click Preferences and switch to General in the invoked dialog.

    export_PDF

See Also