views:

1858

answers:

7

I know about

  • PDFRenderer
  • ICEpdf
  • JPedal
  • Ghostscript to convert PDF->PS, then print with javax.print.*

My primary concern is printing a PDF file to a printer. The other features like displaying, PDF modifications, ... are nice-to-have.

All libraries promise similar features, but I'm afraid that when I choose one I might encounter problems when it is to late.

  • What are the pros and cons of each library above?
  • Are there other/better alternatives?

EDIT: For clarification: I already have PDF files, i.e. they have been created. Now I want to render them, either to a raster image or directly to a printer.

EDIT 2: Until now two answers suggest Apache FOP for PDF printing. I didn't know it is possible. How do I print a PDF file with Apache FOP after I've created it with Apache FOP?

+2  A: 

I don't understand why you need a special PDF library for printing. I would have guessed that the javax.print API would be all you'd need, and that a PDF generation capability like iText or XSL-FO would be what you'd ask for. Your question confuses me.

So you're already able to generate PDFs acceptably well?

duffymo
Yah, I would have to agree. What is being asked here; How to print, or specific programming problems that relate to PDF generation/rendering?
Scanningcrew
I would agree as well the question is confusing. If you are asking about a good PDF generation library, I have had success with iText (in both Java and .NET).
Andy Webb
iText rulez, use iText :)
J-16 SDiZ
You need to have a printer that directly supports PDF in binary format to "simply" use this option. If your printer does not support PDF, you need to use a lib.
Stephen
+3  A: 

You might think that Java would support PDF printing out of the box, but I couldn't get it to work with the print API until I switched to pdfrenderer. The blog post here (http://www.juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/) has some code for using pdfrenderer with the Java Print API which worked for me. It also has a comment of kind-of-support from iText author Bruno Lowagie.

I haven't done any PDF rendering with pdfrenderer however. My employment of it was to create a PDF version of the current screen of data with iText and send it straight to the printer; a kind of heavyweight print function.

I can't speak for the other two libraries but pdfrenderer worked very well for me.

banjollity
A: 

If you know XSL-FO, or XML and XSLT, you could use FOP. http://xmlgraphics.apache.org/fop/download.html

I've used FOP several times to great success. The first time was to create bills for the electric company I worked for. After that I've used it for making printing labels, bingo cards to annoy my family at Christmas, and a few other things that I just can't remember right now. It can be used programatically or from the command line. It's also pretty simple to use. You'll just have to look at the documentation.

Brent Parker
How do I perform the print? Which parameter do I have to provide to start printing? How can I set the targetet printer?
DR
http://www.cs.helsinki.fi/group/xmltools/formatters/fop/fop-0.20.5/build/site/output.htmlThat site has some sample code for writing out to a printer with FOP. It looks to me to be pretty simple, but I've never tried directly printing with FOP. I've only used it in the creation of PDF files.
Brent Parker
As mentioned above, there is also the PDF Renderer project.https://pdf-renderer.dev.java.net/They have some good code examples if you click on the link about halfway down the page.
Brent Parker
+1  A: 

Ghostscript is not a pure Java solution so you are building in a native dependency. Both IcePdf have free versions, demo versions and sample code so you can easily try both. The 'best' solution rather depends on the PDFs, what you are trying to achieve and what budget you have...

A: 

Any reason you wouldn't just use Acrobat Reader to print? It's got command line arguments for initiating print jobs...

Kevin Day
It is very buggy in my experience. Printing opens up the whole reader (which takes longer with every new version).
jle
+1  A: 

You can use OpenOffice in server mode. Check out JODConverter. You can not only open and print pdfs with openoffice, but you can also convert from various formats to pdf. The benefit is that it is free and it has a very Java friendly API.

jle
+1  A: 

I have not tried this But a you can find one way to work on PDF is the PDFbox. It is Java PDF library provided by Apache Software Foundation.

http://incubator.apache.org/pdfbox/

Umesh Aawte