Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

19.09 Exporting to PDF, RTF, Word

Formatting for PDF, RTF, and Word Documents

Exporting a report to PDF, RTF or Word gives you the option to specify the page range. You can set the starting and ending page or simply print out the entire report. Note that all pages must be consecutively numbered. For example, you can’t export the first few pages of a report and the last few pages of a report. Table 19-7 shows the properties used for setting the page range.

Table 19-7. PdfRtfWordFormatOptions Properties.

Property Description
FirstPageNumber The first page number to export
LastPageNumber The last page number to export
UsePageRange Boolean that enables/disables the use of page ranges

When exporting to Word, the process automatically inserts a footer at the bottom of each page that shows “Powered by Crystal” and the Crystal Decisions logo. If you want a continuous flow of data and you don’t want these page footers appearing in your spreadsheet, you have to open the document afterwards and clean it up manually. There is no way to keep this from happening prior to the export. See Figure 19-4 for an example.




Figure 19-4. An exported Word document with the Crystal icon.
Listing 19-5. Set the export formatting to PDF
Public Sub SetFormatPdfRtfWord(ByRef MyReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal UsePageRange As Boolean, ByVal FirstPageNumber As Integer, ByVal LastPageNumber As Integer)
'Change the next line if you want the format to be RTF or Word
MyReport.ExportOptions.ExportFormatType = _
CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat
'The following lines stay the same regardless of formatting
Dim Options As New CrystalDecisions.Shared.PdfRtfWordFormatOptions
Options.UsePageRange = UsePageRange
If UsePageRange Then
Options.FirstPageNumber = FirstPageNumber
Options.LastPageNumber = LastPageNumber
End If
MyReport.ExportOptions.FormatOptions = Options
End Sub

The listing first sets the format type to PDF. If you want to export to RTF or Word, then change this line to be the appropriate enumeration needed. After setting the format type, create an options object and set the page range. If all the pages are going to be exported, then set the UsePageRange property to False. Otherwise, to print page ranges set it to True and also set the FirstPageNumber and LastPageNumber properties.