Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2008

Tip: Looking for answers? Try searching our database.

Printing PDF files in Java

Thread view: 
Andrew - 11 May 2005 08:35 GMT
Does anyone have experience printing PDFs from within a Java program?

I naively thought that, given that Java and PDFs normally play so well
together, that this would be a very straight-forward thing to do. Certainly
there are lots of available tools to create, edit, and read PDFs in Java, but
printing support seems to be sadly lacking.

I've looked at the javax.print API, but my conclusion from all I have read on
the web/forums/mailing lists and that I have tried myself, it doesn't yet
support printing PDFs. (If this is no longer true, can someone please explain
how to achieve it?!). As an additional note, I'm looking ideally for a solution
that is cross-platform, but for now, I'd even settle for something that will
work on WinXP.

I've tried using an external call to Acrobat, but my installed version (6.0)
doesn't seem to support the command line switches that are mentioned in a few
places on the web.

As some context, I produce my PDF file using Apache FOP (start with an XML
file, use an XSLT stylesheet to create XHTML, then another stylesheet to
generate XSL:FO, then use FOP to generate my PDF file). This is all working
just fine. I can view and print my PDFs perfectly in Acrobat and Acrobat
Reader. I need the layout specification ability of XSL:FO and FOP, as well as
the intermediate formats for other reasons, so please don't tell me to use
iText/Jasper Reports/<insert other PDF generation tool here> instead of FOP. My
problem is with printing PDFs, not generating them.  :-)

In the absence of java PDF printing support, I'm currently using XPDF's pdftops
tool (making an external Runtime.exec call) to convert my PDF to PostScript,
and then printing the postscript file using the javax.print APIs.

This works OK, but not perfectly (I have some issues with page margins when
converting to postscript), and I feel like there MUST be a better way. I have
tried using FOP to produce PostScript from the XSL:FO files, but this doesn't
seem to work for my data (it just processes for ever without creating any
useful output).

I have also looked to some commercial tools - Smart JPrint almost works, but
does strange things with JPEG files (it inverts the colours, so that the images
are printed looking like photo negatives, rather than photo images). ActiveTree
(the makers of Smart JPrint) are currently looking into the issue to see
whether it's a specific problem with JPrint, or an issue with my PDFs.

Other commercial tools like JPedal are simply too expensive for my needs.

So, what I'm most interested in is: Has anyone found a good solution for
printing PDFs in Java. I need a solution that silently prints PDFs, without any
associated GUI components, buttons to click etc. that minimally works on WinXP,
but ideally would work anywhere Java does.

Thanks for any help you can offer! (Feel free to either post answers/clarifications here, or to send me email: andrew *at* bebox *dot* nu)

Cheers,
Andrew
Murray - 11 May 2005 11:32 GMT
> Does anyone have experience printing PDFs from within a Java program?
...

> As some context, I produce my PDF file using Apache FOP (start with an XML
> file, use an XSLT stylesheet to create XHTML, then another stylesheet to
> generate XSL:FO, then use FOP to generate my PDF file).

...

Do you need:
   a) the ability to print *any* PDF, e.g. you somehow provide a PDF file
to your program and it prints it, or
   b) do you want to print the PDF documents that you're generating via
FOP?

If b), then couldn't you use the FOP AWTRenderer instead of PDFRenderer? It
implements Printable and Pageable so it should be easy to plug it into the
printing API.

If a) then the GPL jPedal might do the trick. Though you mention jPedal is
too expensive, so I assume GPL won't work for you ...
Andrew - 12 May 2005 07:15 GMT
>> Does anyone have experience printing PDFs from within a Java program?
>...

>> As some context, I produce my PDF file using Apache FOP (start with an XML
>> file, use an XSLT stylesheet to create XHTML, then another stylesheet to
>> generate XSL:FO, then use FOP to generate my PDF file).

>...

Hi Murray,

Thanks for the reply.

>Do you need:
>    a) the ability to print *any* PDF, e.g. you somehow provide a PDF file
>to your program and it prints it, or

Ideally yes. For now, the PDFs are coming from FOP, but I'd like to be able to
print pre-existing PDF files too.

>    b) do you want to print the PDF documents that you're generating via
>FOP?

Yes as well, and this would be a useful start.

>If b), then couldn't you use the FOP AWTRenderer instead of PDFRenderer? It
>implements Printable and Pageable so it should be easy to plug it into the
>printing API.

I haven't tried the AWTRenderer yet. Do you have any feel for how mature it is?
If it's like the PDFRenderer, great, but if it's like the PS renderer, then i
doubt it's worth the investigation time (at this point in time - I'm really
looking forward to the day that active development on FOP becomes visible
again!)

>If a) then the GPL jPedal might do the trick. Though you mention jPedal is
>too expensive, so I assume GPL won't work for you ...

I've looked at the GPL version of jPedal, but the problem is that only the
enterprise version seems to support printing (at least that's what I understand
from reading their website:  http://www.jpedal.org/versions.html

I must confess, though, that I haven't actually downloaded jPedal and tried for
myself. If anyone out there has experience and can tell me definitively whether
the GPL version supports PDF printing, please shout! :-)

Thanks again for the suggestions, Murray.

Cheers,
Andrew
lcaison - 10 Oct 2008 15:53 GMT
Andrew

Have you looked at the library jPDFPrint by Qoppa Software?

They are commercial but don't require to buy an enterprise license. If you
are printing PDF documents from the server, jPDFPrint starts at $350 per CPU.
If you are distributing to end-users, they have a tier pricing model that
could be more affordable than jPedal. It's 100% java so it works on any
platform that supports Java including Windows XP.

>Does anyone have experience printing PDFs from within a Java program?
>
[quoted text clipped - 50 lines]
>Cheers,
>Andrew


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.