aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Printing PDF via PS|PCL using javax.print Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Printing PDF via PS|PCL using javax.print" Watch "Printing PDF via PS|PCL using javax.print" New topic
Author

Printing PDF via PS|PCL using javax.print

Dmitri Fedorchenko
Greenhorn

Joined: Apr 06, 2006
Posts: 1
Hey everyone!
There is a big problem with printing PDFs. I've found a decision - transfrom document to PS or PCL format with FOP and then send it to printer. But here the problems begin. Everything seems to work correct with DocFlavor.INPUT_STREAM.AUTOSENSE, unless document is sent to printer. The job is deleted immediately during spooling. I've tried to send binary text stream, but the result is the same - printer deletes the job, while spooling it. Anybody has any ideas?

public void doPrint(String theFileName)
{
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();

PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if (service != null)
{
try
{
DocPrintJob job = service.createPrintJob();

// the class is defined below
PrintJobWatcher pjDone = new PrintJobWatcher(job);
FileInputStream fis;
fis = new FileInputStream("d:/temp.txt");
// Open the file
InputStream is = new BufferedInputStream(fis);

DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(is, flavor, das);
job.print(doc, pras);

// Wait for job to spool
pjDone.waitForDone();
// It is now safe to close the input stream
is.close();
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (PrintException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Printing PDF via PS|PCL using javax.print
 
Similar Threads
help in java printing
Landscape Printing
Printing .tiff Files
How to get List of Client Printers
To print pdf file