Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems in printing a PDF file in java

 
thinkmack
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not all printer CAN print pdf files. Is yours compatible?
 
thinkmack
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes my printer is configured to print Pdf's.Can someone plz help as i have a deadline today.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic