I'm trying to print a label on a Dymo Labelwriter 450 with a Java Application. But I have a problem with the area on which it really print...
Here is what I get :
As you can see there is nothing printed on the right of the label... (It should be printed "Thingsplay")
And here is the code I'm using :
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();
}
}
}
}
}
At first, when I installed the printer driver and went into the "print options" I saw that the available paper was set on "30252 Address" and I couldn't change that (I'm using 11354 Multi Purpose Label). But I saw on the internet that I had to change the default print options which I did :
Despite all that when I print with the printDialog()
option the paper format is set on "30886 CD Label" ... And even when I change the format here it still print as the image shown above :
Note that when I print on a PDF I have the whole text correctly printed.
I tried to change the margins using paper.setImageableArea()
method but I still can't print on the right side of the label.