use of javafx.print.PrinterJob in project Gargoyle by callakrsos.
the class AgendaSample1 method print.
/** Scales the node based on the standard letter, portrait paper to be printed.
* @param node The scene node to be printed.
*/
public void print() {
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null) {
agenda.print(job);
job.endJob();
}
}
use of javafx.print.PrinterJob 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.PrinterJob 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();
}
use of javafx.print.PrinterJob in project jphp by jphp-compiler.
the class UXPrinter method print.
@Signature
public boolean print(Node node) {
PrinterJob printerJob = PrinterJob.createPrinterJob(getWrappedObject());
boolean success = printerJob.printPage(node);
if (success) {
printerJob.endJob();
}
return success;
}
use of javafx.print.PrinterJob in project cryptomator by cryptomator.
the class RecoveryKeyDisplayController method printRecoveryKey.
@FXML
public void printRecoveryKey() {
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null && job.showPrintDialog(window)) {
PageLayout pageLayout = job.getJobSettings().getPageLayout();
String headingText = String.format(localization.getString("recoveryKey.printout.heading"), vaultName);
Text heading = new Text(headingText);
heading.setFont(Font.font("serif", FontWeight.BOLD, 20));
heading.setFontSmoothingType(FontSmoothingType.LCD);
Text key = new Text(recoveryKey);
key.setFont(Font.font("serif", FontWeight.NORMAL, 16));
key.setFontSmoothingType(FontSmoothingType.GRAY);
TextFlow textFlow = new TextFlow();
textFlow.setPrefSize(pageLayout.getPrintableWidth(), pageLayout.getPrintableHeight());
textFlow.getChildren().addAll(heading, key);
textFlow.setLineSpacing(6);
if (job.printPage(textFlow)) {
LOG.info("Recovery key printed.");
job.endJob();
} else {
LOG.warn("Printing recovery key failed.");
}
} else {
LOG.info("Printing recovery key canceled by user.");
}
}
Aggregations