英文:
Is there a way to print multiple nodes on one paper using javaFX?
问题
我可以成功地在纸上打印表格,但如果我还想在同一张纸上打印例如“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));
有什么想法吗?
英文:
I can successfully print table on paper, but if I want to print also for example label
above that table on the same paper, how to achieve that?
This is my code for printing:
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);
}
I call print
method in button like this:
printButton.setOnAction(e -> print(table));
Any ideas?
答案1
得分: 1
只需将您的节点放入类似 Pane 的容器中,然后打印此容器。该容器本身就是一个节点。
英文:
Just place your nodes into a container like a Pane and then print this pane. The pane is a Node itself.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论