Read this article in your language IT | EN | DE | ES
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Export a Crystal Report to a PDF file with custom export format options</Title>
<Author>Business Objects</Author>
<Description>The following code example exports a Crystal Report to a PDF file with custom export format options. For this code snippet to compile, add a reference to CrystalDecisions.CrystalReports.Engine.dll and CrystalDecisions.Shared.dll.</Description>
<HelpUrl>http://www.businessobjects.com/products/dev_zone/net/default.asp</HelpUrl>
<Shortcut>crExportRptWithOptions</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>FileName</ID>
<ToolTip>Replace this string with the name of the report file you want to export from.</ToolTip>
<Default>"C:\My Crystal Reports\Report Name.rpt"</Default>
</Literal>
<Literal>
<ID>DestinationFileName</ID>
<ToolTip>Replace this string with the file name you want to export the report to.</ToolTip>
<Default>"C:\My Crystal Reports\Report Name.pdf"</Default>
</Literal>
<Literal>
<ID>usePageRange</ID>
<ToolTip>Set this boolean to true if the FirstPageNumber and LastPageNumber should be used.</ToolTip>
<Default>true</Default>
</Literal>
<Literal>
<ID>startPage</ID>
<ToolTip>Replace this number with the first page number to print; use 0 to specify whole report.</ToolTip>
<Default>1</Default>
</Literal>
<Literal>
<ID>endPage</ID>
<ToolTip>Replace this number with the last page number to print; use 0 to specify whole report.</ToolTip>
<Default>5</Default>
</Literal>
<Literal Editable="false">
<ID>ReportDocumentClass</ID>
<Function>SimpleTypeName(CrystalDecisions.CrystalReports.Engine.ReportDocument)</Function>
</Literal>
<Literal Editable="false">
<ID>ExportOptionsClass</ID>
<Function>SimpleTypeName(CrystalDecisions.Shared.ExportOptions)</Function>
</Literal>
<Literal Editable="false">
<ID>ExportDestinationTypeClass</ID>
<Function>SimpleTypeName(CrystalDecisions.Shared.ExportDestinationType)</Function>
</Literal>
<Literal Editable="false">
<ID>ExportFormatTypeClass</ID>
<Function>SimpleTypeName(CrystalDecisions.Shared.ExportFormatType)</Function>
</Literal>
<Literal Editable="false">
<ID>PdfRtfWordFormatOptionsClass</ID>
<Function>SimpleTypeName(CrystalDecisions.Shared.PdfRtfWordFormatOptions)</Function>
</Literal>
<Literal Editable="false">
<ID>DiskFileDestinationOptionsClass</ID>
<Function>SimpleTypeName(CrystalDecisions.Shared.DiskFileDestinationOptions)</Function>
</Literal>
</Declarations>
<Code Language="csharp">
<![CDATA[$ReportDocumentClass$ report = new $ReportDocumentClass$();
$ExportOptionsClass$ exportOptions = new $ExportOptionsClass$();
$PdfRtfWordFormatOptionsClass$ pdfExportFormatOptions = new $PdfRtfWordFormatOptionsClass$();
$DiskFileDestinationOptionsClass$ diskDestinationOptions = new $DiskFileDestinationOptionsClass$();
// Set the export format and format options
exportOptions.ExportFormatType = $ExportFormatTypeClass$.PortableDocFormat;
pdfExportFormatOptions.FirstPageNumber = $startPage$;
pdfExportFormatOptions.LastPageNumber = $endPage$;
pdfExportFormatOptions.UsePageRange = $usePageRange$;
exportOptions.ExportFormatOptions = pdfExportFormatOptions;
// Set the disk file options.
exportOptions.ExportDestinationType = $ExportDestinationTypeClass$.DiskFile;
diskDestinationOptions.DiskFileName = @$DestinationFileName$;
exportOptions.DestinationOptions = diskDestinationOptions;
report.Load(@$FileName$);
report.Export(exportOptions);
report.Close();$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
137f6c19-fe7b-47a9-8cb6-08a4c2243512|0|.0
C#
c#, CrystalReport, snippets