有没有办法使用 javaFX 在一张纸上打印多个节点?
Is there a way to print multiple nodes on one paper using javaFX?
我可以在纸上成功打印 table,但是如果我还想在同一张纸上打印上面的 label
,例如 table,如何实现?
这是我的打印代码:
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));
有什么想法吗?
只需将您的节点放入像窗格这样的容器中,然后打印此窗格。窗格本身就是一个节点。
我可以在纸上成功打印 table,但是如果我还想在同一张纸上打印上面的 label
,例如 table,如何实现?
这是我的打印代码:
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));
有什么想法吗?
只需将您的节点放入像窗格这样的容器中,然后打印此窗格。窗格本身就是一个节点。