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

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Printing PDF in Background" Watch "Java Printing PDF in Background" New topic

Java Printing PDF in Background

KR Gol

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) {
URL fileURL = null;
try {
fileURL = new File(pdfFile).toURL();
}catch(MalformedURLException mue) {

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));

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

} catch (PrintException pe) {


Long Live Java!!!
I agree. Here's the link:
subject: Java Printing PDF in Background