我可以在纸上成功打印表格,但是例如,如果我还要label
在同一张纸上的表格上方打印,该如何实现呢?这是我的打印代码:
private void print(Node node) {
Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.HARDWARE_MINIMUM);
PrinterJob job = PrinterJob.createPrinterJob();
double scaleX = pageLayout.getPrintableWidth() / node.getBoundsInParent().getWidth();
Scale scale = new Scale(scaleX, 1);
node.getTransforms().add(scale);
if (job != null && job.showPrintDialog(node.getScene().getWindow())) {
boolean success = job.printPage(pageLayout, node);
if (success) {
job.endJob();
}
}
node.getTransforms().remove(scale);
}
我print
在按钮中这样调用方法:
printButton.setOnAction(e -> print(table));
有任何想法吗?
只需将节点放入“窗格”之类的容器中,然后打印此窗格即可。窗格本身就是一个节点。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句