我正在尝试使用 Java 应用程序在 Dymo Labelwriter 450 上打印标签。但我对它真正打印的区域有疑问......
这是我得到的:
如您所见,标签右侧没有打印任何内容...(应该打印“Thingsplay”)
这是我正在使用的代码:
public class LabelWriter {
private static final boolean printToPDF = false;
private static final Logger logger = LogManager.getLogger();
public static final String PRINTERNAME = "DYMO LabelWriter";
public static final String PDF_PRINTER = "Print to PDF";
PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat pageFormat = printerJob.defaultPage();
Paper paper = new Paper();
public void printLabel(final String text) {
final double widthPaper = (2.244 * 72);
final double heightPaper = (1.254 * 72);
paper.setSize(widthPaper, heightPaper);
paper.setImageableArea(0, 0, widthPaper, heightPaper);
pageFormat.setPaper(paper);
pageFormat.setOrientation(PageFormat.PORTRAIT);
PrintService[] printService = PrinterJob.lookupPrintServices();
for (int i = 0; i < printService.length; i++) {
System.out.println(printService[i].getName());
if ((printToPDF && printService[i].getName().contains(PDF_PRINTER)) || (!printToPDF && printService[i].getName().contains(PRINTERNAME))) {
try {
printerJob.setPrintService(printService[i]);
printerJob.setPrintable(new CustomPrintable(widthPaper, heightPaper, text), pageFormat);
if (printerJob.printDialog()) {
printerJob.print();
}
} catch (PrinterException e) {
e.printStackTrace();
}
}
}
}
}
起初,当我安装打印机驱动程序并进入“打印选项”时,我看到可用纸张设置在“30252 地址”上,但我无法更改(我使用的是 11354 多用途标签)。但是我在互联网上看到我必须更改我所做的默认打印选项:
尽管如此,当我使用该printDialog()
选项打印时,纸张格式设置在“30886 CD 标签”上......即使我在这里更改格式,它仍然打印如上图所示:
请注意,当我在 PDF 上打印时,我正确打印了整个文本。我尝试使用paper.setImageableArea()
方法更改边距,但仍然无法在标签右侧打印。