在JavaFX中,我想将照片打印到10x15纸张上.有一些Paper constansts,但没有100x150 mm的常数.
是否可以创建自己的Paper以在PageLayout中使用它?
谢谢.
PageLayout pageLayout = printer.createPageLayout(Paper.JAPANESE_POSTCARD, PageOrientation.LANDSCAPE, Printer.MarginType.EQUAL);
double scaleX = pageLayout.getPrintableWidth() / node.getBoundsInParent().getWidth();
double scaleY = pageLayout.getPrintableHeight() / node.getBoundsInParent().getHeight();
node.getTransforms().add(new Scale(scaleX, scaleY));
PrinterJob job = PrinterJob.createPrinterJob(printer);
if (job != null) {
System.out.println("Job created!");
boolean success = job.printPage(node);
if (success) {
System.out.println("Job successfully finished!");
job.endJob();
} else {
System.out.println("Job NOT successful!");
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以使用类PrintHelper,它可以访问Paper的包私有构造函数.
Paper photo = PrintHelper.createPaper("10x15", 100, 150, Units.MM);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3479 次 |
| 最近记录: |