0
由於某些原因,我使用Brother QL720NW打印機使用62毫米寬的紙張尺寸來實現JFX打印API,但出現「壞邊距」異常。我該如何去圓這個這裏是代碼:JFX打印API,打印到Brother QL 720NW
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());
}
用於打印的節點是一個簡單的標籤,我使用用於測試目的。打印完成後,我將實施一個更大的節點來打印所需的確切參數。
讓我知道這段代碼是否正常。或者需要一些重構。
在此先感謝
這裏是有人認爲面臨的一個鏈接同樣的問題 - 希望它可以提供手頭問題的清晰畫面:https://www.java-forums.org/javafx/95904-illegalargumentexception-bad-margins-when-printing-dymo-labelwriter-450-a。 HTML – xavier
尋找印刷API的內部,有一些計算髮生,並且「壞毛利來自這裏」PageLayout.java這個問題似乎在計算中。任何人都可以幫助自定義紙張尺寸發生什麼? – xavier