Skip to main content

How to: Export Reports to PDF Files

  • 3 minutes to read

This topic describes how to use ExpressPrinting System to export reports to PDF and customize pagination, security, and digital signature settings.

End-User Export Options

A user can click the “Export to PDF” button in the Print Preview dialog to export a report. This button invokes the “PDF Export Options” dialog lists all available export options.

VCL Printing System: The PDF Export Options Dialog

The user can click OK to confirm the selected settings and invoke the Save As shell dialog.

You can save user changes made within the PDF Export Options dialog for use in future application runs. Refer to the following topic for details: How to Persist Settings Between Application Runs.

Export a Report to PDF in Code

Call any of the following methods:

These methods load PDF export options from the target control’s report link or a link passed as a parameter. You can either use these settings or invoke the “PDF Export Options” dialog to allow an end user to change them. Refer to the method descriptions for details.

Additionally, you can handle a component printer’s OnBeforeExportToPDF event to adjust the export settings or cancel a report export operation based on a certain condition.

Code Example

The following code example exports a report to a digitally signed PDF document with password protection.

uses
..., dxX509Certificate, dxPSPDFExportCore;
//...
var
  ASettings: TdxPSPDFReportExportOptions;
begin
  ASettings := TdxPSPDFReportExportOptions.Create;  // Creates default export settings
  // Loads an X.509 certificate from a file to add a digital signature
  ACertificate := TdxX509Certificate.Create('123.pfx', '123456');
  try
    ASettings.Author := 'DevExpress VCL';  // Specifies the author of an exported PDF document
    ASettings.Keywords := 'PDF, VCL, DevExpress';  // Sets keywords related to content
    ASettings.CompressStreams := True;  // Enables the loseless Deflate compression for PDF document content
    ASettings.SecurityOptions.UserPassword := '123';  // Defines a user password
    ASettings.SecurityOptions.Enabled := True;  // Enables password protection
    ASettings.SignatureOptions.Reason := 'Approved';  // Adds a reason to a digital signature
    ASettings.SignatureOptions.Certificate := ACertificate;  // Assigns the previously loaded certificate
    ASettings.SignatureOptions.Enabled := True;  // Adds a digital signature
    // Exports the report to a PDF file in the application directory without user interaction
    dxComponentPrinter1Link1.ExportToPDF('output.pdf', False, ASettings);
  finally
    ASettings.Free;  // Destroys the default export settings to free up reserved memory
    ACertificate.Free;  // Releases the previously loaded certificate
  end;
end;

Limitations

The ExpressPrinting System can generate PDF documents only according to v1.4 of the PDF standard.