28

I am after a library which can accept an already created PDF file and send it directly to the printer. I don't want the user to need Adobe Reader or anything else installed, the application will generate a PDF and I want to print it.

4

7 Answers 7

5

Sorry, my first answer (since deleted -- FGITW answer saying just use iTextSharp) assumed it was PDF FAQ #1 when in fact it was PDF FAQ #~5, mea culpa...

There's no system-provided native PDF processing, so outside of using an app such as FoxIt or Acrobat -- which you shouldn't discount too quickly - people who use PDF will have one or the other and will be choosy about which one they prefer as they're not all equal, esp if you get into more advanced features and their associated licensing and monetisation schemes.

Not aware of any specific libraries that address this requirement, though the other question I've linked to above should have a good answer. ... researches; time passes... An answer on the other question says PDFSharp should suit, the sample looks straightforward.

On reflection based on looking at Pdfsharp's FAQ wiki, iTextSharp has similar stuff for generating TIFFs/images as PDFSharp has.

An alternative which may or may not be in scope is to generate and/or convert to e.g., an XPS file, which does have built in printing support (pretty sure .NET 3.5, and possibly earlier have it as a standard component in the Client Profile).

One point that shouldn't be missed in this all is that the Lowagie book (iText In Action) is excellent and if you're going to be doing anything in reading, writing or providing PDF forms, you should have it on your shelf. Similarly, if you do go the FLOSS library route, iText has to be seriously considered.

1
  • 3
    Actually, you bring up a good point, converting to another format, png even, may be easier to print.
    – Craig
    Feb 13, 2011 at 21:25
4

I'm not aware of any free/open source libraries available to do this, but after evaluating a handful, I went with cete DynamicPDF Print Manager.NET. It was by far the most efficient in terms of system resources, namely RAM. The other products I tried were from Tall Components, Gnostice, and BCL EasyPDF SDK. All of these used large amounts of RAM compared to cete's product. The Print Manger has good documentation is was easy to use.

You may also be able to call gsprint from .NET, part of gsview, which is FOSS GUI for GhostScript. I did not go this route, but also noticed it seemed to use more system resources than Dynamic PDF. If you could probably have package it with your software so to the user it's more transparent. I know it doesn't fit your criteria, but this seems to be the only possible free solution available.

In case you come across PDFSharp, note that it uses Adobe Reader to print.

Apache's PDFBox has a command line PrintPDF utility that you may also be able to call from .NET. I came across it after I purchased Print Manager, so I haven't tried it yet.

Update: You can use Sumatra PDF to print silently from the command line. I suspect it rasterizes the PDF before sending to the printer, but for smaller files that should work.

8
  • Thanks, I will have a look although the price is very $$$
    – Craig
    Feb 13, 2011 at 21:33
  • True, it's too bad there isn't anything free. I'm using it in the enterprise world so it actually was much cheaper than Adobe's $30,000 server products.
    – jmmr
    Feb 13, 2011 at 21:38
  • 1
    @jrm82: You obv have exp of the product, but you sure it still uses AR to print? the sample doesnt smell of it? Ah, you're right - stackoverflow.com/questions/883456/printing-pdfs-with-pdfsharp Feb 13, 2011 at 21:42
  • 1
    @Ruben Last time I checked it out it did. I looked at the source, there was even and amusing comment that said something about "Now do some magic to print with Adobe reader"
    – jmmr
    Feb 13, 2011 at 21:50
  • 3
    @Ruben I think DoSomeVeryDirtyHacksToMakeItWork(); was the red flag for me :)
    – jmmr
    Feb 13, 2011 at 21:59
3

I hope this will help someone. After looking online I found this great open source library (C#) and it works perfect for me.

https://github.com/tonyedgecombe/RawPrint

    using RawPrint;

    Printer.PrintFile("Printer Name", @"C:\Path\To\Print\File.prn");

Best of luck,

1
  • this worked like a charm for my purpose, but experiencing file access errors with that method, I solved using Printer.PrintRawStream
    – edestrero
    Jul 22, 2021 at 14:47
1

I created a small .Net 4.0 library called PDFFilePrint, you can fetch this through the nuget package manager or you can call "install-package PDFFilePrint" in the nuget package manager console. Here is a link to the package.

0

You can try PDFView4NET. It supports printing of PDF files and conversion of PDF pages to images.

Disclaimer: I work for the company that develops PDFView4NET.

0

There are a few commercial libraries out there. I for example would recommend http://pdfprinting.net.

P.S. I work for the company offering that solution.

0

Free PDFiumViewer comes via Nuget and has print capabilities, see code sample here.

Real easy to use - took me long time to find though - so I post it for people searching in the "wrong" question:

https://stackoverflow.com/a/41751184/586754

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.