如何在dymo标签的整个宽度上打印?

时间:2018-08-09 07:16:03

标签: java printing dymo

我正在尝试使用Java应用程序在Dymo Labelwriter 450上打印标签。 但是我对它实际打印的区域有疑问...

这就是我得到的:

enter image description here

如您所见,标签的右边没有打印任何内容(应打印为“ 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多用途标签) 。但是我在互联网上看到必须更改默认的打印选项:

Available Paper

Default print options

尽管所有使用printDialog()选项进行打印时,纸张格式都已设置在“ 30886 CD标签”上。即使在此更改格式,它仍将按照上图显示:

enter image description here

请注意,当我在PDF上打印时,我会正确打印整个文本。 我尝试使用paper.setImageableArea()方法更改页边距,但仍然无法在标签的右侧打印。

0 个答案:

没有答案