java - PDFBox Freezes at Print() Command -


i'm trying use pdfbox print existing pdf file. here's code:

public void sendtoprinter(){     file pdffile = new file("example.pdf");      try {         pddocument pd = pddocument.load(pdffile);         pd.print();         pd.close();     } catch (ioexception | printerexception ex) {         system.out.println("error: couldn't find pdf or printers");     } } 

when run it, however, program freezes @ pd.print(). no exceptions thrown, no print dialog appears. doesn't anything. has had problem before?

specs: mac os x yosemite, pdfbox v1.8.9, jdk1.8.0_05, hp photosmart printer

for having same problem. print() command worked when put pdf work onto thread. reference:

public void sendtoprinter() {          //create new task         task task = new task<boolean>() {             @override             public boolean call() {                  //reference pdf file                 file pdffile = new file("file.pdf");                  try {                     //load pdf & create printer job                     pddocument pd = pddocument.load(pdffile);                     printerjob job = printerjob.getprinterjob();                     job.setpageable(new pdfpageable(pd));                      //show native print dialog & wait user hit "print"                     if (job.printdialog()) {                         job.print();                     }                      pd.close();                 } catch (ioexception | printerexception ex) {                 }                  return true;             }         };         //run task on new thread         new thread(task).start();  } 

Comments