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