use of javafx.print.PageLayout in project jgnash by ccavanaugh.
the class JavaFXUtils method printImageView.
/**
* Sends an {@code ImageView} to a printer.
*
* @param imageView {@code ImageView} to print
*/
public static void printImageView(final ImageView imageView) {
final PrinterJob job = PrinterJob.createPrinterJob();
if (job != null) {
// Get the default page layout
final Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout = job.getJobSettings().getPageLayout();
// Request landscape orientation by default
pageLayout = printer.createPageLayout(pageLayout.getPaper(), PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
job.getJobSettings().setPageLayout(pageLayout);
if (job.showPageSetupDialog(MainView.getPrimaryStage())) {
pageLayout = job.getJobSettings().getPageLayout();
// determine the scaling factor to fit the page
final double scale = Math.min(pageLayout.getPrintableWidth() / imageView.getBoundsInParent().getWidth(), pageLayout.getPrintableHeight() / imageView.getBoundsInParent().getHeight());
imageView.getTransforms().add(new Scale(scale, scale));
if (job.printPage(imageView)) {
job.endJob();
}
} else {
job.cancelJob();
}
}
}
use of javafx.print.PageLayout in project Gargoyle by callakrsos.
the class FxUtil method printJob.
/********************************
* 작성일 : 2016. 6. 29. 작성자 : KYJ
*
* print 처리.
*
* @param window
* @param target
********************************/
public static void printJob(Window window, Node target) {
Printer printer = Printer.getDefaultPrinter();
// PrinterAttributes printerAttributes = printer.getPrinterAttributes();
//
Paper a4 = Paper.A4;
// Paper a4 = PrintHelper.createPaper("Rotate A4", Paper.A4.getHeight(),
// Paper.A4.getWidth(), Units.MM);
PageLayout pageLayout = printer.createPageLayout(a4, PageOrientation.REVERSE_PORTRAIT, MarginType.DEFAULT);
PrinterJob printerJob = PrinterJob.createPrinterJob();
// JobSettings jobSettings = printerJob.getJobSettings();
// jobSettings.setPrintSides(PrintSides.TUMBLE);
ImageView imageView = new ImageView();
// 화면 사이즈에 맞게 크기 조절.
Callback<SnapshotResult, Void> callback = param -> {
final WritableImage image = param.getImage();
imageView.setImage(image);
final double scaleX = pageLayout.getPrintableWidth() / imageView.getBoundsInParent().getWidth();
final double scaleY = pageLayout.getPrintableHeight() / imageView.getBoundsInParent().getHeight();
imageView.getTransforms().add(new Scale(scaleX, scaleY));
return null;
};
target.snapshot(callback, null, null);
if (printerJob.showPrintDialog(window) && printerJob.printPage(pageLayout, imageView))
printerJob.endJob();
}
Aggregations