To print Crystal Reports to PDF for specific pages, such as page 1 and page 2, you can use the Crystal Reports ExportToDisk method with the PDF format. Here's how you can do it in your VB.NET code:
Assuming you have a Crystal Report Viewer control named CrystalReportViewer1 on your form and you want to export page 1 and page 2 to separate PDF files:
Imports System.IO
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Load and display the Crystal Report as shown in the previous example.
End Sub
Private Sub ExportToPDFPagesButton_Click(sender As Object, e As EventArgs) Handles ExportToPDFPagesButton.Click
Dim rpt As New SiswaReport ' Replace with the actual report name.
' Export page 1 to a PDF file.
Dim exportOptions As New ExportOptions()
Dim pdfOptions As New PdfRtfWordFormatOptions()
pdfOptions.FirstPageNumber = 1 ' Set the first page to export.
pdfOptions.LastPageNumber = 1 ' Set the last page to export.
exportOptions.ExportFormatOptions = pdfOptions
exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat
' Specify the path and file name for the PDF file.
Dim pdfPathPage1 As String = "Page1.pdf"
' Export the report to PDF (page 1).
rpt.ExportToDisk(ExportFormatType.PortableDocFormat, pdfPathPage1)
' Export page 2 to a PDF file.
pdfOptions.FirstPageNumber = 2 ' Set the first page to export.
pdfOptions.LastPageNumber = 2 ' Set the last page to export.
' Specify the path and file name for the PDF file.
Dim pdfPathPage2 As String = "Page2.pdf"
' Export the report to PDF (page 2).
rpt.ExportToDisk(ExportFormatType.PortableDocFormat, pdfPathPage2)
' Optionally, you can open the PDF files using the default PDF viewer.
If File.Exists(pdfPathPage1) Then
Process.Start(pdfPathPage1)
End If
If File.Exists(pdfPathPage2) Then
Process.Start(pdfPathPage2)
End If
End Sub
End Class
0 comments:
Post a Comment