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 printer 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.
Related
I'm trying to generate a PDF that can be viewed interactively in Adobe Reader, but also, upon printing, selects different paper trays based on the page. (Some pages are supposed to use stationery, whereas other must not.)
PDF itself apparently doesn't support this form of metadata by design (as discussed e.g. here), but apparently, JDF is an appropriate format, and can be embedded as XML in the PDF.
What's less clear to me is if Adobe Reader does anything useful with that metadata: if a PDF with embedded JDF information is printed, does it parse the JDF and choose paper trays? Can I use PDF portfolios for this purpose instead?
My goal is to both let the user view the PDF in Adobe Reader interactively, and, upon printing, automatically selecting different paper trays.
(The far less convenient alternative would be to write a custom app to do the printing.)
You are right, PDF describes the artwork while the JDF describes the metadata about print. However, JDF is targeted to industrial printing systems rather than for desktop printers. As far as I know does Adobe Acrobat Reader not support this kind of feature based on a JDF.
In order to control the different paper trays of your printer, you may setup your printer several times - one for each tray and switch the flag "default printer" in the background programmatically.
Another idea could be to use the Acrobat Reader only for viewing purposes and using the command line for printing.
There are concepts of how to put metadata into the PDF directly (see: https://confluence.cip4.org/display/PUB/PDF+Intent), but it could take a while until this specification is gonna to be implemented.
I am generating PDF file using migradoc library in a .NET webpage. PDF gets generated as expected. When I save the PDF from chrome to file system and print it using "Actual size" option, the resulting print is same as PDF preview.
Problem is when I directly print it from chrome, apparently it gets resized, therefore the output PDF doesn't look Identical as preview (Some table borders gets disappeared). Any helping idea is appreciated.
You're essentially printing from two different sources. When you print the PDF document (from your file system) as "Actual Size," that size is going to be dictated by the bounding box/page dimensions specified in the document at the time that it was saved to a file.
When you print your document image directly from Chrome, it's Chrome's print options and display options that will be in effect; e.g. Portrait vs. Landscape, to cite one obvious choice you can make. The Chrome print output will be determined by the settings in effect at the time the print job is generated.
Is there any way in C# to get the documents sent to the printer from another program and use those documents again for something else?
I want to build an application which can get invoice sent to the printer by some point of sale system and gives opportunity to send that invoice to customer's email.
Well, you could print to the XPS printer and have it create a file. Then, let the system print the XPS file using the standard application. This may or may not work depending on some factors:
Is there XPS support on the system?
Did the user change the default application that handles XPS files? Maybe printing is no longer possible...
Is XPS a file format you want to send to the users?
etc.
That said, of course you could do the same thing with PDF, but you'd have to have access to an application that can actually print PDF. It has been asked multiple times here how to "send PDF bytes" to a printer - you can't. There are solutions, but in the end you have to answer this question for yourself:
Is it really worth the hassle or isn't it just easier to print the document and then create it again as PDF (for examples) to send to the user?
It seems like there should be more information on this, but I can't seem to find the right words to search by.
Basically, I have a C# application that prints off a filled out form. I take user input and draw them over a image of the form then print it off. This application works perfectly for all but one of the workstations that use it.
The text on the form doesn't print in the correct location, rather it seems to be offset by and additional .25" on the x and y axis while the image of the form prints of perfectly. All workstations print to the same shared printer and use the same application.
I'm not sure what settings would cause the printer to print the text in a different location.
Is there a way to configure my application or the users workstation so I won't need to created a "personalized" version of the application for that workstation?
Thank you for help.
If you can't find the reason in different drivers or resolutions, an alternative might be to generate a PDF and then send that to the printer. That way you have control of the output page and can preview it as well. There are many libraries for generating PDF files. If you're generating HTML, you can use the free wkhtmltopdf to convert from HTML to PDF. I'm sure there are many others as well. Good luck!
I've searched Stackoverflow and google and found many ways
how I can print stuff in C#.
The best way for me would be to populate blank white windows form
with some label, textbox and picturebox elements and print it as a windows form.
This way is very poor because it prints in 72 DPI, and is not flexible for multiple
pages print.
Next way that I found that would be good is using iTextSharp, but there is a problem
that iTextSharp only generates PDF-s, and you have to open it in PDF viewer and print
from there.
I love this way of thinking where I create a paragraph, and then fill it with text and graphic, so I found this thread
http://www.devarticles.com/c/a/C-Sharp/Printing-Using-C-sharp/
where it discusses how to create your own printing engine in C#, something like iTextSharp,
but very lightweight...
Now that I've said that, I want to know is there any ready to use printing engine that would be like iTextSharp, made for printing, not for PDF generation? What is the best way to print something, without using reporting services like CrystalReports.
I think Crystal Reports wouldn't work for my case cause I don't want to print generic reports, but some text and graphics that I need to dynamicaly generate every time I need to print.
I found that it was much easier to do printing using the printing stuff in WPF.
EDIT
XPS is the page description format that Microsoft included into .NET with .NET 3.0. It is nominally part of WPF, and is integrated with the WPF form layout model. But you can create XPS documents in memory and send them to printers, from any .NET app, including a WinForms App.
An example:
http://statestreetgang.net/post/2008/03/Creating-an-XPS-document-in-memory-via-the-DOM.aspx
It is approximately equivalent to the iTextSharp capability you explored, except:
you can do it all in memory if you like, no need to save to a filesystem file. Of course if you want to save to a filesystem file, you can do that too.
you don't need an external viewer in order to start the print.
If you are new in programming and you have some data like from Data Base, and you want to print it after retrieving it from Data Base. Then just follow this link it will guide you step by step.
Print Data in Dot Net (C#,Vb.net)