ReportViewer.PrintDialog() throws exception when printing to Adobe PDF
I am working on a WinForms app that uses the ReportViewer
control to show a few Reporting Services reports. On these screens, we allow the user to print the report by calling the PrintDialog()
method on the ReportViewer like so:
_reportViewer.PrintDialog();
This works fine in most cases, it brings up the standard windows print dialog, the user chooses what printer they want to print to, and it prints. However, when the user chooses to print to PDF using "Adobe PDF", it throws a Win32Exception: The specified datatype is invalid
. The file dialog to choose where to save the pdf doesn't even come up.
This only happens with Adobe PDF printer. I installed NitroPDF and used their PDF pri开发者_如何学JAVAnter and it works without a problem.
Does anybody have an idea on what could be causing this to happen?
Edit:
Here is the stack trace:
at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at Microsoft.Reporting.WinForms.ReportViewer.PrintDialog(PrinterSettings printerSettings)
at Microsoft.Reporting.WinForms.ReportViewer.PrintDialog()
This doesn't truly fix the problem but solves it in the users' eyes.
Trap the error thrown by the PDF Printer then invoke the Export to PDF functionality built into Reporting Services. It doesn't error in Winforms even when printing to the PDF Printer does. From the user perspective they "printed to pdf" like normal and the experience is identical. It's a work around that works. :-)
AFAIK the ReportViewer control just renders each page as a bitmap image. So when printing to PDF, if the resolution is high, it could be a huge bitmap. Maybe AdobePDF has problems with large bitmaps, Adobe have so many other bugs! Try lowering the resolution as a test?
I have an application that uses the ReportServer API to get the page bitmaps and chunks them into parts to be handled by a custom print processor
Could it be that the contents of the report are creating this problem. I mean to say that the report may contain certain characters that Adobe PDF printer is not able to recognize.
Can you try to print a very simple/basic/blank report and see if that works.
精彩评论