printing - JavaFX8 Print API : how to set correctly the Printable area -


in javafx application , i'm using javafx 8 printing api print node , getting problem of printing area , despite have set pagelayout a4 paper .... here code :

public static  void printnode(final node node) throws nosuchmethodexception, instantiationexception, illegalaccessexception, invocationtargetexception {         printer printer = printer.getdefaultprinter();            pagelayout pagelayout = printer.createpagelayout(paper.a4, pageorientation.portrait, 0,0,0,0 );               printerjob job = printerjob.createprinterjob();         if (job != null  && job.showprintdialog(node.getscene().getwindow()) ) {              boolean success = job.printpage(pagelayout, node);                                if (success) {                 job.endjob();             }         } 

and here snapshot of node want print : enter image description here

and here getting when print node enter image description here

in method need hardware able margins. if set margins 0, printer has non printable margin around sheet.

you can view margins if print them out:

system.out.println("pagelayout: " + pagelayout.tostring()); 

and not able set margins value less zero. need scale node printed. node scaled, printed , unscaled.

  public static void printnode(final node node) throws nosuchmethodexception, instantiationexception, illegalaccessexception, invocationtargetexception {     printer printer = printer.getdefaultprinter();     pagelayout pagelayout         = printer.createpagelayout(paper.a4, pageorientation.portrait, printer.margintype.hardware_minimum);     printerattributes attr = printer.getprinterattributes();     printerjob job = printerjob.createprinterjob();     double scalex         = pagelayout.getprintablewidth() / node.getboundsinparent().getwidth();     double scaley         = pagelayout.getprintableheight() / node.getboundsinparent().getheight();     scale scale = new scale(scalex, scaley);     node.gettransforms().add(scale);      if (job != null && job.showprintdialog(node.getscene().getwindow())) {       boolean success = job.printpage(pagelayout, node);       if (success) {         job.endjob();        }     }     node.gettransforms().remove(scale);   } 

inspired solution found here: https://carlfx.wordpress.com/2013/07/15/introduction-by-example-javafx-8-printing/


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -