Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. pdf printing

pdf printing

Scheduled Pinned Locked Moved C#
csharp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    amadeonMk
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • A amadeonMk

      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

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      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 the Print 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-----

      A 1 Reply Last reply
      0
      • H Heath Stewart

        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 the Print 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-----

        A Offline
        A Offline
        amadeonMk
        wrote on last edited by
        #3

        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:

        H 1 Reply Last reply
        0
        • A amadeonMk

          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:

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          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-----

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups