How can I programatically print a DataReport to a pdf file?

a 夏天 提交于 2019-12-25 01:16:03

问题


I'm updating old VB6 code to save its DataReports out to a PDF, rather than bringing up a print dialog.

I cannot simply write the PDF within the code (using a VB6 PDF library, etc.), since all our software already uses DataReports, and writing print code for each one would be tedious, at best. Currently, the process requires an employee to print the DataReport to a PDF print driver, naming it manually and saving it to where it needs to go. I need to automate this all, so that the name and location of the saved PDF can be specified programatically, rather than entered by hand.

The best solution would be if DataReport simply had a .SaveToPdf(filename) routine. Worst-case scenario, I see myself automating the process using SendKeys. However, this solution needs to work in an environment with multiple possible printers (so the PDF print driver might not be the default,) and on Windows XP, Vista, or 7.

I've fruitlessly tried Googling the problem, which returns only tutorials on how to do it by hand, much as we do now.


回答1:


You might consider using a PDF Printer Driver that allows you to configure silent "printing" to a preset directory using auto-generated names.

For an example of such a product, see:

http://www.iteksoft.com/modules.php?op=modload&name=Sections&file=index&req=viewarticle&artid=21




回答2:


I would create a dialog that lets the user enter the printer (driver) name, directory to save to, and a file naming guideline, then save that to either a local ini file or the registry. You would then need two print buttons / menus. One to print straight to the printer using the default (saved) settings, and one that opens the print window they see now so they can perform a custom print.

Remember an ellipsis on a menu item indicates additional dialogs, Print vs Print...




回答3:


Just use Crystal Report Viewer Control and follow the steps:

Set objRpt = objApp.OpenReport("type report path and name")

objRpt.DiscardSavedData
dim filepath as string
filepath = report path & report filename

With objRpt

    .ExportOptions.FormatType = crEFTPortableDocFormat
    .ExportOptions.DestinationType = crEDTDiskFile
    .ExportOptions.DiskFileName = 'filepath string goes here
    .ExportOptions.PDFExportAllPages = True
    .Export False
End With

Follow these steps and the export is done.



来源:https://stackoverflow.com/questions/6255048/how-can-i-programatically-print-a-datareport-to-a-pdf-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!