Printing JavaFX tableview with PrinterJob -
i want print tableview onto a4 in landscape format. want tableview scale itselfe on a4 page.
i managed this:
printer printer = printer.getdefaultprinter(); printerjob printerjob = printerjob.createprinterjob(); //set layout a4 , landscape pagelayout pagelayout = printer.createpagelayout(paper.a4, pageorientation.landscape, printer.margintype.default); printerjob.getjobsettings().setpagelayout(pagelayout); system.out.println(pagelayout.getprintablewidth()); system.out.println(pagelayout.getprintableheight()); final double scalex = pagelayout.getprintablewidth() / _menuplantable.getboundsinparent().getwidth(); final double scaley = pagelayout.getprintableheight() / _menuplantable.getboundsinparent().getheight(); _menuplantable.gettransforms().add(new scale(scalex, scaley)); if(printerjob.showprintdialog(_controlstage) && printerjob.printpage(_menuplantable)) { _menuplantable.gettransforms().remove(gettransforms().size()); printerjob.endjob(); } else{ _menuplantable.gettransforms().remove(gettransforms().size()); }
the result looks this: image
you can see table cut off , right bound alot bigger left.
tipps?
check answer , may hardware limitation issue
from javadocs :
a client needs know margin values legal should first obtain pagelayout using hardware_minimum margins.
if printer cannot support layout specified, adjust returned layout supported configuration
edited : had same problem , this solution worked great me
the result got .
Comments
Post a Comment