如何将报告导出为pdf格式 [英] how to export the reports into pdf format

查看:271
本文介绍了如何将报告导出为pdf格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi ..
我已经以Windows窗体创建了一个水晶报表和一个水晶报表查看器.
我在form2中有两个form1和form2我保留了一个名为print的按钮.
当我按下此按钮时,应将文档打印为.pdf格式.
而不使用Crystal Report查看器的打印按钮.
请帮助我

hi..
i''ve created a crystal report and one crystal report viewer in windows form.
i''ve two form form1 and form2 in form2 i''ve kept one button called print.
when i press this button it should print the document into .pdf format.
without using the crystal report viewers print button.
please help me

推荐答案

下面的函数将实现您想要的功能,您需要对其稍作调整(必须翻译一些变量)和一些东西可能不需要您(设置参数/重新连接),但我确定您可以根据需要进行调整.

The function below will do what you want, you''ll need to adjust it a bit tho (had to translate some variables) and some things might not be needed for you (setting params / reconnecting ) but I''m sure you''ll be able to adjust it to your needs.

Public Shared Sub PrintToPDF(ByVal Reportname As String, ByVal params As List(Of ReportParameters), Optional ByVal path As String = "")
        Try
            Dim rpt As New ReportDocument
            If Reportnaam.EndsWith(".rpt") Then Reportnaam = Reportnaam.Replace(".rpt", "")
            Dim file As String = 'path to the report file
            If IO.File.Exists(file) = False Then
                'report could not be found
                Exit Sub
            End If
            rpt.Load(file)
            rpt = reconnectreport(rpt)
            If params IsNot Nothing AndAlso params.Count > 0 Then
                For Each c As ReportParameters In params
                    rpt.SetParameterValue(c.ParamNaam, c.ParamValue)
                Next
            End If
            If String.IsNullOrEmpty(path) Then
                Dim ofd As New SaveFileDialog
                ofd.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
                ofd.Filter = ".pdf|PDF"
                If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                    Dim path As String = ofd.FileName
                    If path.EndsWith(".pdf") = False Then path &= ".pdf"
                    pad = path
                End If
            End If
            If Not String.IsNullOrEmpty(pad) Then
'exports the report to pdf
                rpt.ExportToDisk(ExportFormatType.PortableDocFormat, pad)
            End If
            'rpt.Dispose()
            'rpt = Nothing
        Catch ex As Exception
            JoroLogging.AddLog(ex, GetCurrentMethod.DeclaringType.Name, GetCurrentMethod.Name)
        End Try
    End Sub 


这篇关于如何将报告导出为pdf格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆