Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

To print pdf file

 
srikanth pidikiti
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import javax.print.*;
import javax.print.attribute.*;
import java.io.*;

public class Printing {
public static void main(String args[]) throws Exception {
String filename = args[0];
PrintRequestAttributeSet pras =
new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF;
PrintService printService[] =
PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,
printService, defaultService, flavor, pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
job.print(doc, pras);
Thread.sleep(10000);
}
System.exit(0);
}
}

The Above program gives the error whenever am printing pdf
for other files like png,gif it will execute sucessfully

plz rectify my error or else send me the code to print the pdf file as soon as possible

advance thanks,
Srikanth
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This does not belong in the SCJD forum...
Moving to Java in General (Intermediate)
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Above program gives the error whenever am printing pdf

What is the text of the error? Which line in the code throws it?

Java error/exception messages can be very informative, so when you get one, copy the text so you can examine it at leisure and post it when asking such questions.

Bill
 
Joe Ess
Bartender
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm looking into my crystal ball and seeing an unsupported flavor exception. I believe DocFlavor is intended to indicate the capabilities of the printer, not the content of the document. Try using DocFlavor.INPUT_STREAM.AUTOSENSE.
[ June 14, 2006: Message edited by: Joe Ess ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic