Kbase P101902: How to export a Crystal Reports report to PDF or any other Crystal Reports Export Format ?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  07/07/2010 |
|
Status: Verified
GOAL:
How to export a Crystal Reports report to PDF without using the Crystal Report Viewer or prompting the user?
GOAL:
How to export a Crystal Reports report from Progress using the Crystal Report ActiveX Designer Run Time?
FACT(s) (Environment):
Progress 9.1x
OpenEdge 10.x
Windows
FIX:
This solution demonstrates how to export a Crystal Report to a file, disk, or any other 'Crystal Reports Export Destination Type' in any 'Crystal Report Export Format Type' desired. Although the sample code exports a Crystal Report to a PDF file, ALL the 'Crystal Reports Export Destination Type' constants and ALL the 'Crystal Reports Format Type' constants are defined in two separate include files to allow the developer easy access to the values required to select the desired Export Destination and Format:
1) Create an include file {CRExportDestinationType.i} to globally define the Crystal Reports Export Destination Type constants.
/* CRExportDestinationType.i */
/* Crystal CRExportDestinationType constants */
&GLOBAL-DEFINE crEDTApplication 5
&GLOBAL-DEFINE crEDTDiskFile 1
&GLOBAL-DEFINE crEDTEMailMAPI 2
&GLOBAL-DEFINE crEDTEMailVIM 3
&GLOBAL-DEFINE crEDTLotusDomino 6
&GLOBAL-DEFINE crEDTMicrosoftExchange 4
&GLOBAL-DEFINE crEDTNoDestination 0
2) Create an include file {CRExportFormatType.i} to globally define the Crystal Reports Export Format Type constants.
/* CRExportFormatType.i */
/* Crystal CRExportFormatType constants */
&GLOBAL-DEFINE crEFTCharSeparatedValues 7
&GLOBAL-DEFINE crEFTCommaSeparatedValues 5
&GLOBAL-DEFINE crEFTCrystalReport 1
&GLOBAL-DEFINE crEFTCrystalReport70 33
&GLOBAL-DEFINE crEFTDataInterchange 2
&GLOBAL-DEFINE crEFTExactRichText 35
&GLOBAL-DEFINE crEFTExcel50 21
&GLOBAL-DEFINE crEFTExcel50Tabular 22
&GLOBAL-DEFINE crEFTExcel70 27
&GLOBAL-DEFINE crEFTExcel70Tabular 28
&GLOBAL-DEFINE crEFTExcel80 29
&GLOBAL-DEFINE crEFTDataInterchange 2
&GLOBAL-DEFINE crEFTExcel80Tabular 30
&GLOBAL-DEFINE crEFTExcel97 36
&GLOBAL-DEFINE crEFTExplorer32Extend 25
&GLOBAL-DEFINE crEFTHTML32Standard 24
&GLOBAL-DEFINE crEFTHTML40 32
&GLOBAL-DEFINE ccrEFTLotus123WK1 12
&GLOBAL-DEFINE crEFTLotus123WK3 13
&GLOBAL-DEFINE crEFTLotus123WKS 11
&GLOBAL-DEFINE crEFTNoFormat 0
&GLOBAL-DEFINE crEFTODBC 23
&GLOBAL-DEFINE crEFTPaginatedText 10
&GLOBAL-DEFINE crEFTPortableDocFormat 31
&GLOBAL-DEFINE crEFTRecordStyle 3
&GLOBAL-DEFINE crEFTTabSeparatedText 9
&GLOBAL-DEFINE crEFTTabSeparatedValues 6
&GLOBAL-DEFINE crEFTText 8
&GLOBAL-DEFINE crEFTWordForWindows 14
&GLOBAL-DEFINE crEFTXML 37
3) Use the procedure ExportACrystalReportToPDF.p to export the file named CustomerReport.rpt to a PDF file named CustomerReprot.pdf.
/* ExportCrystalReportToPDF.p */
{CRExportDestinationType.i}.
{CRExportFormatType.i}.
DEFINE VARIABLE crApplication AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE crReport AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE crExportOptions AS COM-HANDLE NO-UNDO.
CREATE "CrystalRuntime.Application" crApplication.
CREATE "CrystalRuntime.Report" crReport.
ASSIGN
/* Open the Crystal Reports Report Object */
/* Include the source report file's path if different from the working directory.*/
crReport = crApplication:OpenReport("CustomerReport.rpt")
/* Get the handle of the Report's ExportOptions Object */
crExportOptions = crReport:ExportOptions
/* Set the ExportOptions Objec.t's desired properties: */
/* Set the ExportOptions ExportOptions DiskFileName */
/* Include the target PDF file's path if different from the working directory. */
crExportOptions:DiskFileName = "ExportedFileName.pdf"
/* Set the ExportOptions DestinationType to Disk File */
crExportOptions:DestinationType = {&crEDTDiskFile}
/* Set the ExportOptions FormatType to PDF Format */
crExportOptions:FormatType = {&crEFTPortableDocFormat}
/* Set the ExportOptions PDFExportAllPages to TRUE */
crExportOptions:PDFExportAllPages = TRUE.
/* No information message will be displayed if the line below is commented out */
/* crReport:DisplayProgressDialog = FALSE. */
/* Export the report without prompting the user. */
/* Use EXPORT(TRUE) to prompt the user. */
crReport:EXPORT(FALSE).
RELEASE OBJECT crExportOptions.
RELEASE OBJECT crReport.
RELEASE OBJECT crApplication.
ASSIGN crExportOptions = ?
crReport = ?
crApplication = ?..