在我的JavaFX应用程序中,我正在使用JavaFX 8打印API来打印一个节点,尽管我已经设置了A4纸张的页面布局,但是我仍然遇到了打印区域的问题...以下是我的代码:
public static void printNode(final Node node) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, 0,0,0,0 );
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null && job.showPrintDialog(node.getScene().getWindow()) ) {
boolean success = job.printPage(pageLayout, node);
if (success) {
job.endJob();
}
}
以下是我想打印的节点快照:
以下是我打印节点时得到的内容:
Caused by: java.lang.IllegalArgumentException: Margins must be >= 0 at javafx.print.Printer.createPageLayout(Printer.java:346) at classes.JavaFxPrint.printNode(JavaFxPrint.java:31)
- KacemSys