在JavaFX中,我想将照片打印到10x15的纸张上。有一些纸张常量,但没有100x150毫米常数。
是否可以创建自己的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!");
}
}
Paper的构造函数是程序包专用的,因此您不能创建该类中列出的标准尺寸以外的Paper尺寸。
但是,您可以使用反射创建自定义尺寸:
Constructor<Paper> c = Paper.class.getDeclaredConstructor(String.class,
double.class, double.class, Units.class);
c.setAccessible(true);
Paper photo = c.newInstance("10x15", 100, 150, MM);
我还没有测试是否可以正常工作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句