views:

1643

answers:

9

We are looking into silent printing of PDF documents from within Java. The printing will be invoked from the desktop and not through a browser so we cannot use JavaScript. PDF Renderer is an operational solution but their rendering quality is not acceptable. iText does not seem to be pluggable with the Java print service. There are some commercial Java libraries, jPDFPrint by Qoppa, JPedal, and ICEpdf which we have not tried out yet.

Does anybody have any experience with PDF silent printing from Java?

A: 

This looks promising.

Jim Blizard
The rendering quality of PDF Renderer is not acceptable.
Paul Reiners
A: 

Have a look at www.pdflib.com. Its comercial but PDFlib Lite is available for free for open source projects. It has bindings for java.

RED SOFT ADAIR
+3  A: 

Apache PDFBox. It is currently in incubation, but the PDF printing functionality has been around before that. Internally, it uses the Java Print Services to create a print job, and it also supports silent printing.

Do note that it requires Fontbox as well, and the current (upcoming 0.8.0 release) has included graceful fallback for documents with Type 0 fonts. Type 1 fonts are printed correctly; however in 0.7.3, attempts to print documents with Type 0 fonts will result in an exception being thrown.

Vineet Reynolds
I tried this, but the pdf's printed at least mainly blank (sometimes completely blank pages, sometimes just a section).
Stephen
Well, the command line (PrintPDF) seems to work and print everything (even if it makes a mess of my transparent PNG image)
Stephen
That's a bit strange, considering that command line printing seems to have worked (except for the PNG image). I'll check how PNGs are represented in the PDFBox model. By the way, are you trying this with 0.7.3 or a later release?
Vineet Reynolds
It was a few older generated pdf's in particular... perhaps it was due to using a prior version of flying saucer to generate the pdf. Newly generated pdf's are fine. BTW +1 - it's working now...
Stephen
Version 0.8.0. As for +1, I would vote, but apparently I already have, and too long ago too :(. I hope it was already an up vote.
Stephen
A: 

Check Jasper Reports at http://jaspersoft.com/jasperreports

JuanZe
+1  A: 

Maybe I'm misunderstanding, but why not just use the Print Service API directly? The following works for me (assumes you have the PDF document as a byte array):

DocFlavor flavor = DocFlavor.BYTE_ARRAY.PDF;
PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
if (services.length > 0)
{
    DocPrintJob printJob = services[0].createPrintJob();
    Doc document = new SimpleDoc(pdfBytes, flavor, null)
    printJob.print(document, null);
}
else
{
    System.out.println("No PDF printer available.");
}
Dan Dyer
this only works if your printer natively supports PDF - few do
Kevin Day
All the ones I've tried under Linux seem to work. Under Windows I had to update the drivers.
Dan Dyer
A: 

There is an example using JPedal at http://www.jpedal.org/support%5FegSP.php

You will need the commercial version of IcePdf if you want full font support.

A: 

I have experience with making Acrobat (Reader or Full) do the printing, but it's anything but silent (it is unattended, though - just depends on how 'silent' the silent requirement is). If there's interest, I can shoot you the native code that makes the required DDE calls.

Kevin Day
Could you please show the code?
asalamon74
A: 

iText is intended for creating PDF files (per a post I saw from the author), and thus probably isn't what you want.

I've used Qoppa's jPDFPrint quite successfully for exactly this purpose, but it's not cheap. If you can afford it, it's the most robust solution I've found thus far. I've also been very impressed with the level of support; they even generated some custom sample code for me.

I tried PDFBox, but found that it doesn't support the "Shrink to printable area" page scaling that you get with Acrobat. Not everyone will care about this feature, but it's essential for me.

rfeague
A: 

of you are using windows platform, you can use CLPrint http://www.commandlinepdf.com this is great tool fot automate pdf printing via command line or some programming language.