[英]How to print Pane in JavaFX?
How can I print my Pane
that has Label
inside of it? 如何打印其中带有
Label
Pane
? I want to print it using my POS Printer 55mm. 我想使用55mm的POS打印机进行打印。 I have this kind of code to print, but it prints nothing to me:
我有要打印的这种代码,但对我却什么也没打印:
void print2(Node node){
PrinterJob job = PrinterJob.createPrinterJob();
Printer printer = Printer.getDefaultPrinter().getDefaultPrinter();
PageLayout pageLayout = printer.createPageLayout(Paper.A6, PageOrientation.PORTRAIT, Printer.MarginType.DEFAULT);
JobSettings jobSettings = job.getJobSettings();
jobSettings.setPageLayout(pageLayout);
boolean printed = job.printPage(node);
if (printed) {
job.endJob();
}
}
The code does not look bad. 代码看起来不错。 There are a few points I would recommend to check out:
我建议您检查以下几点:
In fact, I had good experiences with a slightly more simple code like this (sorry, it is DIN A5 paper size example, but worked): 实际上,我在使用像这样的简单代码方面有很好的经验(对不起,这是DIN A5纸张尺寸示例,但是可以用):
PrinterJob printerJob = PrinterJob.createPrinterJob();
if (printerJob != null) {
PageLayout pageLayout = printerJob.getPrinter().createPageLayout(Paper.A5, PageOrientation.LANDSCAPE, 0, 0, 0, 0);
boolean success = printerJob.printPage(pageLayout, root);
if (success) {
printerJob.endJob();
}
}
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.