aspose file tools*
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
Author

Problems in printing a PDF file in java

thinkmack
Greenhorn

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.
Thanks
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);
}
is.close();
}
catch (PrintException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
Sean MacLean
author
Ranch Hand

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

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
thinkmack
Greenhorn

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.
 
 
subject: Problems in printing a PDF file in java