aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Java Printing PDF in Background Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Printing PDF in Background" Watch "Java Printing PDF in Background" New topic
Author

Java Printing PDF in Background

KR Gol
Greenhorn

Joined: Apr 20, 2006
Posts: 3
Hi All,

I am trying to write a program that prints PDF files in a directory without asking user for Print Dialog, Background printing.

I used, DocFlavor URL.PDF. But it is simply printing gibberish and repeating the printing forever...
However, a text document is working fine.
I don't see any MIME types application/pdf fromt he list of flavors supported from my printer. However, if I print from ACrobat Reader it works as we all know.

Any help???!!!

Here is the code:
private void doPrint(String pdfFile) {
FileInputStream psStream = null;
try {
psStream = new FileInputStream(pdfFile);
} catch (FileNotFoundException ffne) {
}
if (psStream == null) {
return;
}
URL fileURL = null;
try {
fileURL = new File(pdfFile).toURL();
System.out.println(fileURL);
}catch(MalformedURLException mue) {
mue.printStackTrace();
}

DocFlavor psInFormat = DocFlavor.INPUT_STREAM.PDF;
DocFlavor urlFileFlavor = DocFlavor.URL.PCL;

Doc myDoc = new SimpleDoc(fileURL, urlFileFlavor, null);

PrintRequestAttributeSet aset =
new HashPrintRequestAttributeSet();

aset.add(new Copies(1));
aset.add(MediaSizeName.EXECUTIVE);

//aset.add(Sides.DUPLEX);
//PrintService[] services =
//PrintServiceLookup.lookupPrintServices(psInFormat, aset);
PrintService services =
PrintServiceLookup.lookupDefaultPrintService();
if (services != null) {
System.out.println("Service :"+services.getName());
System.out.println("Is this supported:"+services.isDocFlavorSupported(psInFormat));
getSupportedPrintFlavors(services);
this.getSupportedPrintAttributes(services);
DocPrintJob job = services.createPrintJob();
try {
job.print(myDoc, aset);
//throw new PrintException("IGNORE THIS!");

} catch (PrintException pe) {
pe.printStackTrace();
}

}
}


Long Live Java!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Printing PDF in Background