java printing - printing a pdf (Beginning Java forum at Coderanch) (original) (raw)

I've been googling information on how to print a pdf in java, and it seems that the java print api is used more for printing from a swing app. What I'm needing to do is send a pdf document to the printer upon user request.

I would like my app to work as follows

- User selects pdf to be printed
- Program determines pages to be printed and deducts amount from user account
- If sufficient money, program sends job to printer automatically without popping up the print screen.
- If printed successfully, then program tells user it was printed.

I'm able to figure out the rest of the pieces, in regards to user input and determining pages of the pdf, except I don't see how I will be able to print the pdf.

If someone could point me to some resources on java printing that i might not be finding, or help me with some information on this, I would truly appreciate it.

I've tried to use this code

but all that I get is junk characters spread across 15 or so pages, for a pdf file that simply says "Hello World". I can open the pdf file on my computer, and print it ok, but when using the above code, it just prints out junk. I'm wondering if anyone can point me somewhere that can help me understand how I might need to format or setup the pdf so that I can print it correctly. My program could be run on any number of Linux systems, with a multitude of printer types.