在VB.Net中将水晶报表转换为pdf

时间:2015-10-06 18:19:20

标签: vb.net pdf crystal-reports

如何将 Crystal报表转换为 VB.Net 中的 PDF 文件,

我使用的是Crystal Report版本 10.0.0533

我的代码是

Private Sub ExpData()
    If RepRs.BOF Or RepRs.EOF Then
        MsgBox("No Details Found", MsgBoxStyle.Information)
        RepRs.Close()
        Exit Sub
    End If
    RepRs.MoveFirst()

    Dim RepDoc As New ReportDocument
    Dim rptLoc As String = ""
    rptLoc = My.Application.Info.DirectoryPath & "\Reports\SalesBillACInvoice.rpt"
    RepDoc.Load(rptLoc)
    RepDoc.SetDataSource(RepRs)

    Reports.CRViewer.ReportSource = RepDoc

    Reports.Show()  'I want to export here instead of showing...
End Sub

2 个答案:

答案 0 :(得分:0)

就这样做,

创建新文件夹以在应用程序启动路径中保存PDF文件,文件夹名称为PDF。

删除此行

Reports.Show()

添加此代码

Try
    Dim CrExportOptions As ExportOptions
    Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
    Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
    Dim FilePath As String = Application.StartupPath & "\PDF\" & "SalesBillACInvoice.pdf"
    CrDiskFileDestinationOptions.DiskFileName = FilePath
    CrExportOptions = RepDoc.ExportOptions
    With CrExportOptions
        .ExportDestinationType = ExportDestinationType.DiskFile
        .ExportFormatType = ExportFormatType.PortableDocFormat
        .DestinationOptions = CrDiskFileDestinationOptions
        .FormatOptions = CrFormatTypeOptions
    End With
    RepDoc.Export()
Catch ex As Exception
    MsgBox(ex.ToString)
End Try

答案 1 :(得分:0)

这是我使用的技术。无需服务器端文件夹。

        RepDoc.SetDataSource(RepRs) 'Add dataset to report
        RepDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, HttpContext.Current.Response, True, "AttachmentName")
        RepDoc.Close()
        RepDoc.Dispose()

http://www.c-sharpcorner.com/UploadFile/mahesh/ExportCRtoPDF10062006161918PM/ExportCRtoPDF.aspx