This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Java in General and the fly likes Problems in printing a PDF file in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "Problems in printing a PDF file in java" Watch "Problems in printing a PDF file in java" New topic

Problems in printing a PDF file in java


Joined: Sep 30, 2002
Posts: 2
Im trying to print a PDF file to a printer using the javax.print classes, but the printed output is always some junk characters..
I also tried to conver the PDF file to the PS file and then tried printin, this also did not work.
Do i need to set the attribute of the page ?
Does java support printing a PDF document ? Im just wondering if im missing out something.
NB : Here is the code i had used
DocFlavor flavor = DocFlavor.BYTE_ARRAY.PDF;
InputStream is = FileInputStream("ReadMe.pdf");
PrintService service[] = PrintServiceLookup.lookupPrintServices(flavor,null);
// Create the print job
if(service != null && service.length > 0)
job = service[0].createPrintJob();
Doc doc = new SimpleDoc(is, flavor, null);
if( job != null)
job.print(doc, null);
catch (PrintException e)
catch (IOException e)
Sean MacLean
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
Thanks for participating here at the Ranch. However, the name you are using does not comply with our naming convention described at . Please log in with a new name, which meets these requirements.
You can change your name here.
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Not all printer CAN print pdf files. Is yours compatible?

"JavaRanch, where the deer and the Certified play" - David O'Meara

Joined: Sep 30, 2002
Posts: 2
Yes my printer is configured to print Pdf's.Can someone plz help as i have a deadline today.
It is sorta covered in the JavaRanch Style Guide.
subject: Problems in printing a PDF file in java