我正在实现JFX打印应用程序接口使用兄弟QL720NW打印机与62毫米宽的纸张大小,由于某些原因我得到了“差边距”异常。我该如何处理下面的代码:
try
{
Printer printer = Printer.getDefaultPrinter();
Paper photo = PrintHelper.createPaper("LabelPrinter", 62.0, 89.8, Units.MM);
PageLayout pageLayout = printer.createPageLayout(photo, PageOrientation.LANDSCAPE, Printer.MarginType.HARDWARE_MINIMUM);
PrinterAttributes attr = printer.getPrinterAttributes();
PrinterJob job = PrinterJob.createPrinterJob();
double scaleX = pageLayout.getPrintableWidth() / node.getBoundsInParent().getWidth();
double scaleY = pageLayout.getPrintableHeight() / node.getBoundsInParent().getHeight();
Scale scale = new Scale(scaleX, scaleY);
node.getTransforms().add(scale);
JobSettings jobsettings = job.getJobSettings();
jobsettings.setPageLayout(pageLayout);
if (job != null) {
boolean success = job.printPage(node);
if (success) {
job.endJob();
}
}
node.getTransforms().remove(scale);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}用于打印的Node是一个简单的标签,我将其用于测试目的。在我得到一个打印输出之后,我将实现一个更大的节点来打印所需的确切参数。
如果这个代码是正确的,请告诉我。或者需要一些重构。
提前感谢
发布于 2017-03-10 00:05:29
对于任何寻求答案的人来说,答案都在实际打印机的打印设置中,这里有一个解决方案的链接:https://forum.sambapos.com/t/how-to-change-the-printer-size-paper/10442/11
https://stackoverflow.com/questions/42664787
复制相似问题