views:

805

answers:

3

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

+2  A: 

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

Mark Redman
The C# wrapper sounds handy, I'd appreciate it.Thanks
Ryan ONeill
Just send me an email, address on my profile page.
Mark Redman
+2  A: 

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.

Akash Kava
That does sounds like an easy option!
Mark Redman
I thought there were issues with the window staying open and the newest version not having print support via the cmd line. I'll check though, thanks.
Ryan ONeill
Adobe has an API, however it is simple that actually Adobe has an activex control that you can use it easily in .NET WinForms, and I think that can be used without shipping anything extra, you will have to investigate, its documented here http://www.adobe.com/devnet/acrobat/pdfs/Acrobat_SDK_developer_faq.pdf
Akash Kava
It works in the latest version, but means I'll have to do a little work to hide the window and kill the process in the background. But that's a ton better than installing another component.
Ryan ONeill
From Adobe 'In order to use the OLE objects made available by Acrobat, you must have the full Acrobat product installed on your system and the Acrobat.tlb file included in the project references for your Visual Basic project.'. So no go on the purely programmatic route.
Ryan ONeill
A: 

I have the same problem and not convenient to have the result file written inside directory because the Vista or Windows 7 security doesn't allow writing file into directory without changing permission authority. my user is not smart enough to do the changing of permission therefore I need to get it work straight after installation.

ALEX