wood burning stoves 2.0*
The moose likes Java in General and the fly likes To print pdf file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "To print pdf file" Watch "To print pdf file" New topic
Author

To print pdf file

srikanth pidikiti
Greenhorn

Joined: Apr 14, 2006
Posts: 12
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

Joined: Aug 03, 2002
Posts: 7729
This does not belong in the SCJD forum...
Moving to Java in General (Intermediate)


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
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

Joined: Oct 29, 2001
Posts: 8836
    
    7

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 ]

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To print pdf file
 
Similar Threads
How to get List of Client Printers
Landscape Printing
Need help Printing
help in java printing
help in java printing