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

How to: Export a Workbook to PDF

Important

The Workbook class in defined in the DevExpress.Docs.v17.2.dll assembly. Make sure you added a reference for this library to your project before using the workbook functionality. Note that use of this library in production code requires a license to the DevExpress Document Server or DevExpress Universal Subscription. Refer to the DevExpress Subscription page for pricing information.

This example demonstrates how to save a workbook in PDF format.

using (FileStream pdfFileStream = new FileStream("Documents\\Document_PDF.pdf", FileMode.Create))
{
    workbook.ExportToPdf(pdfFileStream);
}

To export a workbook to PDF, use the Workbook.ExportToPdf method.

However, to export embedded charts, it is necessary to register the following services:

  • DevExpress.XtraSpreadsheet.Services.Implementation.ChartControllerFactoryService
  • DevExpress.XtraSpreadsheet.Services.Implementation.ChartImageService

The code snippet below illustrates how to accomplish the task.

Imports DevExpress.Spreadsheet
Imports DevExpress.XtraPrinting
Imports DevExpress.XtraSpreadsheet.Services
Imports DevExpress.XtraSpreadsheet.Services.Implementation
            Dim workbook As New Workbook()

            'Register required services. 
            workbook.AddService(GetType(IChartControllerFactoryService), New ChartControllerFactoryService())
            workbook.AddService(GetType(IChartImageService), New ChartImageService())

            workbook.LoadDocument("testDocument.xlsx")
            workbook.ExportToPdf("resultingDocument.pdf")
See Also