Reputation: 21
How can I print my Pane
that has Label
inside of it? I want to print it using my POS Printer 55mm. 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();
}
}
Upvotes: 0
Views: 1933
Reputation: 341
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):
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!
Upvotes: 1