I am looking for a way to print the contents of a JavaFX TableView. I understand that JavaFX doesn\'t have Printing capabillities just yet (what a disapointment). I have fou
Snip the area you want
Rectangle rect = new Rectangle(0,0,dataDisplayAreaAnchorPane.getWidth(),dataDisplayAreaAnchorPane.getHeight());
dataDisplayAreaAnchorPane.setClip(rect);
WritableImage writableImage;
writableImage = new WritableImage((int) dataDisplayAreaAnchorPane.getPrefWidth(),
(int) dataDisplayAreaAnchorPane.getPrefHeight());
dataDisplayAreaAnchorPane.snapshot(null, writableImage);
eventDispatcher.printLandscape(writableImage);
**------------------------------------**
Resize according to A4 paper size and print
public void print(WritableImage writableImage, Stage primaryStage) {
ImageView imageView =new ImageView(writableImage);
Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
double scaleX = pageLayout.getPrintableWidth() / imageView.getBoundsInParent().getWidth();
double scaleY = pageLayout.getPrintableHeight() / imageView.getBoundsInParent().getHeight();
imageView.getTransforms().add(new Scale(scaleX, scaleY));
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null) {
boolean successPrintDialog = job.showPrintDialog(primaryStage.getOwner());
if(successPrintDialog){
boolean success = job.printPage(pageLayout,imageView);
if (success) {
job.endJob();
}
}
}
}