pdf printing
-
i am sending a pdf file to printer (using streaming) but it gives binary output. anyone know why this is happening or is there an another way to print an existing pdf file in C#. thanks
You can't just send a raw file to the printer (unless it's text or postscript and the driver is setup to recognize it correctly)! While a PDF is mostly PS, it is also compressed and mangled. You need to have a program or library to print PDFs correctly. There is no support for this in the .NET base class library (has nothing to do with C#, which is only a language that targets the CLR), nor should there be (too specialized). If Adobe Acrobat (including Reader) is installed, you can customize your Toolbox in VS.NET, click the COM tab, and add the Acrobat Control for ActiveX (which creates a couple interop assemblies and references them automatically). You can then use the
LoadFile
method to load a PDF then call thePrint
method. The out-of-process server for Acrobat (not Reader) doesn't appear to easily expose this type of access to the object model. There are also libraries out there for .NET that can generate and print PDFs. Just http://www.google.com/search?&q=print+pdf+C%23[^]. One library that popuped up was http://itextsharp.sourceforge.net/[^].-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
You can't just send a raw file to the printer (unless it's text or postscript and the driver is setup to recognize it correctly)! While a PDF is mostly PS, it is also compressed and mangled. You need to have a program or library to print PDFs correctly. There is no support for this in the .NET base class library (has nothing to do with C#, which is only a language that targets the CLR), nor should there be (too specialized). If Adobe Acrobat (including Reader) is installed, you can customize your Toolbox in VS.NET, click the COM tab, and add the Acrobat Control for ActiveX (which creates a couple interop assemblies and references them automatically). You can then use the
LoadFile
method to load a PDF then call thePrint
method. The out-of-process server for Acrobat (not Reader) doesn't appear to easily expose this type of access to the object model. There are also libraries out there for .NET that can generate and print PDFs. Just http://www.google.com/search?&q=print+pdf+C%23[^]. One library that popuped up was http://itextsharp.sourceforge.net/[^].-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
thanks for your assistance. i tried to use Acrobat Control for ActiveX but gives "Catastrophic error".i searched for an example but could not found an example with "pdflib". :omg:
Worked fine for me in the past. What are you doing to the control? Also, don't search for "pdflib". Use generic terms. I even gave you an example search string (you can even click on it to launch it) in which several solutions were returned.
-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----