Skip to main content
A newer version of this page is available. .

How To: Convert a DOCX Document to PDF format

This example demonstrates how to export a document to PDF format using the RichEditDocumentServer.ExportToPdf method.

To set the export options, an PdfExportOptions instance can be used. It provides a number of properties, such as PdfExportOptions.ImageQuality and PdfExportOptions.ConvertImagesToJpeg, allowing you to adjust the required settings for export.

server.LoadDocument("Documents\\MovieRentals.docx", DocumentFormat.OpenXml);
//Specify export options:
PdfExportOptions options = new PdfExportOptions();
options.DocumentOptions.Author = "Mark Jones";
options.Compressed = false;
options.ImageQuality = PdfJpegImageQuality.Highest;
//Export the document to the stream: 
using (FileStream pdfFileStream = new FileStream("Document_PDF.pdf", FileMode.Create))
{
    server.ExportToPdf(pdfFileStream, options);
}
System.Diagnostics.Process.Start("Document_PDF.pdf");