File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes The problem of printing PDF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "The problem of printing PDF" Watch "The problem of printing PDF" New topic

The problem of printing PDF

allen gu

Joined: Jan 13, 2003
Posts: 6
The source is,
try {
FileInputStream jpegStream;
jpegStream = new FileInputStream("2.PDF");
if (jpegStream == null){
System.out.println("Image size: "+ jpegStream.available());
DocFlavor myFormat = DocFlavor.INPUT_STREAM.PDF;
Doc myDoc = new SimpleDoc(jpegStream, myFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(1));
// aset.add(MediaName.ISO_A4_WHITE);
// aset.add(Sides.ONE_SIDED);
PrintService services = PrintServiceLookup.lookupDefaultPrintService();
System.out.println("Print service: "+services.toString());
DocPrintJob job = services.createPrintJob();
job.print(myDoc, aset);
} catch (Exception pe) {
the result is
Image size: 12274
Print service: Win32 Printer : FinePrint 2000
sun.print.PrintJobFlavorException: invalid flavor
But when i print JPG file,then myFormat = DocFlavor.INPUT_STREAM.JPEG;
that's OK!
Now who can help me ?? thanx!
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

If your dataobject is a jpeg, why do you specify PDF as format?
a rose is a rose is a rose and a jpg is a jpg and not a pdf.
I agree. Here's the link:
subject: The problem of printing PDF
jQuery in Action, 3rd edition