officefileapi-118873-word-processing-document-api-export-to-pdf.md
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:
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);
}
}
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraPrinting
Imports System.IO
'...
Using wordProcessor As New RichEditDocumentServer()
' Load a DOCX document.
wordProcessor.LoadDocument("Documents\MovieRentals.docx")
' Specify export options.
Dim options As New PdfExportOptions()
options.DocumentOptions.Author = "Mark Jones"
options.Compressed = False
options.ImageQuality = PdfJpegImageQuality.Highest
' Export the document to a stream.
Using pdfFileStream As New FileStream("Document_PDF.pdf", FileMode.Create)
wordProcessor.ExportToPdf(pdfFileStream, options)
End Using
End Using
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?
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)
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.
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:
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: Export Document as Accessible PDF.
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.
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: Export Document as Accessible PDF.
Use the options below to decrease the size of the exported PDF file.
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.
Use the Do Not Embed These Fonts option to specify fonts that should not be embedded in the output PDF file.
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:
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.
Use Document Options to specify information that should be embedded as Document Properties in the exported PDF file.
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.
You can save a document as a tagged (accessible) PDF document. Accessible PDF formats allow users to use screen readers and other assistive technologies to read information from PDF documents.
You can generate PDF files that conform to the following standards:
For more information review the following help topic: How to: Export Document as Accessible PDF.
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.Docx);
// 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");
}
Imports DevExpress.XtraRichEdit
Imports System.Drawing
Using wordProcessor As New RichEditDocumentServer()
' Load a DOCX document.
wordProcessor.LoadDocument("Documents\MovieRentals.docx", DocumentFormat.Docx)
' 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")
End Using
Glyph Shaping does not work for non-embedded fonts.
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.
OpenType Variable fonts (TrueType and CFF flavored), and OpenType SVG fonts are not supported.
See Also