Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Printing PDF via PS|PCL using javax.print

 
Dmitri Fedorchenko
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic