0

I want to print my tableView onto a A4 in Landscape format. I also want the tableView to scale itselfe on to this A4 page.

I managed to do this:

Printer printer = Printer.getDefaultPrinter();
PrinterJob printerJob = PrinterJob.createPrinterJob();


//set layout to A4 and 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 like this: IMAGE

You can clearly see that my table is cut off and the right bound is alot bigger than the left.
Any tipps?

Vulkanos
  • 193
  • 19

1 Answers1

0

Check this answer , this may help hardware limitation issue

From the Javadocs :

A client that needs to know what margin values are legal should first obtain a PageLayout using the HARDWARE_MINIMUM margins.

If the printer cannot support the layout as specified, it will adjust the returned layout to a supported configuration

Edited : I had the same problem and this Solution worked great for me

The Result i got .

Community
  • 1
  • 1