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

How To: Export Document to PDF format

  • 2 minutes to read

User Interface

End-users can use the Print Preview command in the Ribbon UI to invoke the Preview window. In that window the Export - Export To - PDF File command displays the PDF Export Options dialog and subsequently allows specifying the file name and location to save a document as PDF file.

API

Export to PDF is performed using the RichEditControl.ExportToPdf method.

Note

A complete sample project is available at: The RichEditControl’s common API

The following code loads the sample document, specifies export options using the PdfExportOptions settings and exports it to PDF. It invokes the default PDF viewer to display the resulting document.

The RichEditControl instance is passed to the BarItem.ItemClick event handler using the BarItem.Tag property.

static void buttonCustomAction_ItemClick_PDF(object sender, ItemClickEventArgs e) {
    RichEditControl richEdit = e.Item.Tag as RichEditControl;
    richEdit.LoadDocument("Documents\\Grimm.docx");
    //Set the required export options:
    DevExpress.XtraPrinting.PdfExportOptions options = new DevExpress.XtraPrinting.PdfExportOptions();
    options.DocumentOptions.Author = "Mark Jones";
    options.Compressed = false;
    options.ImageQuality = DevExpress.XtraPrinting.PdfJpegImageQuality.High;
    //Export the document to the file:
    richEdit.ExportToPdf("resultingDocument.pdf", options);
    //Export the document to the file stream:
    using (FileStream pdfFileStream = new FileStream("resultingDocumentFromStream.pdf", FileMode.Create)) {
        richEdit.ExportToPdf(pdfFileStream, options);
    }

    System.Diagnostics.Process.Start("resultingDocument.pdf");
}