How do I send a PDF in a MemoryStream to the printer in .Net?

不打扰是莪最后的温柔 提交于 2020-01-03 02:27:46

问题


I have a PDF created in memory using iTextSharp and contained in a MemoryStream. I now need to translate that MemoryStream PDF into something the printer understands.

I've used Report Server in the past to render the pages to the printer format but I cant use it for this project.

Is there a native .Net way of doing this? For example, GhostScript would be OK if it was a .Net assembly but I don't want to bundle any non .Net stuff along with my installer.

The PrintDocument class in .Net is great for sending content to the printer but I still need to translate it from a PDF stream into GDI at the page level.

Any good hints?

Thanks in advance

Ryan


回答1:


Alternate and easier way to do would be save your pdf into temp file and give following command in Process.Start that will take pdf straight to printing as mentioned in this Adobe Reader Print Throough Command Line

Process.Start("AcroRd32.exe /t \"C:\test.pdf\"");

I would say this is the best way because Adobe surely will print it in right manner, rather then depending upon any other tools, they are good but they are not 100% correct.




回答2:


You will need a RIP like GhostScript to interpret the PDF. I can give you C# wrapper tha wraps dll calls to print directly to a printer, but there are redistribution licenses associated with GhostScript.

I have used the leadTools Raster Imaging Pro for .Net to interpret PDF's, you will need to check its printing capabilities though. This is an expensive option and is not royalty free (this actually uses GhostScript internally, but is very wrapped up amongst the LeadTools dlls. This library works well and gets around the licensing.

Not sure Acrobat Reader has an API that can be used? You could investigate that.

HTH



来源:https://stackoverflow.com/questions/1392852/how-do-i-send-a-pdf-in-a-memorystream-to-the-printer-in-net

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