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 |
Figure 19-4. An exported Word document with the Crystal icon.
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.