Trung Kien Nguyen
Trung Kien Nguyen

Reputation: 11

Unable to change paper size for Brother QL-700 in Java

I am working on a Java application that needs to print labels using a Brother QL-700 label printer. I am using the Java Printing API and have set the paper size to 62mm x 29mm in my code using the following code:

PageFormat pageFormat = job.defaultPage();
Paper paper = pageFormat.getPaper();
double width = 620;
double height = 290;
double margin = 0;
paper.setSize(width, height);
paper.setImageableArea(margin, margin, width, height);
pageFormat.setPaper(paper);

However, when I print using a 62mm roll paper, the printer outputs a label that is 10cm long. When I switch to a DK-11209 label that has a size of 62mm x 29mm, the printer reports that the paper size is incorrect and that I have specified 62mm x 100mm in my code.

I have tried various ways of setting the paper size, such as using values in inches or points, but nothing seems to work. I have also tried querying the printer for supported media sizes using the following code:

PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
Media[] res = (Media[]) printService.getSupportedAttributeValues(Media.class, null, null);
for (Media media : res) {
    if (media instanceof MediaSizeName) {
        MediaSizeName msn = (MediaSizeName) media;
        MediaSize ms = MediaSize.getMediaSizeForName(msn);
        float width = ms.getX(MediaSize.INCH);
        float height = ms.getY(MediaSize.INCH);
        System.out.println(media + ": width = " + width + "; height = " + height);
    }
}

But the list of supported media sizes does not include 62mm x 29mm, even though the printer's manual (https://www.brother.eu/-/media/product-downloads/devices/label-printers/ql/cz/ql-700_broura.pdf) states that it supports this size.

I have ensured that all paper sizes are correctly set in both the Brother software and the printer itself. When printing with P-touch Editor or printing a test page, everything works perfectly. [enter image description here](https://i.sstatic.net/lgb3e.png)

Can anyone help me figure out how to set the correct paper size for the Brother QL-700 printer in Java? Thank you in advance for any suggestions.

Upvotes: 1

Views: 245

Answers (1)

You might get a better result using a dedicated java library for Brother QL printers that directly communicates with the printer through USB (disclaimer: I'm the author of this library since I faced the same issue and others as well).

In particular, the library better handles continuous label rolls.

Example usage :

    // Create or load one or more images
BufferedImage image = ...;

// Create a print job
BrotherQLJob job = new BrotherQLJob()
        .setAutocut(true)
        .setDither(true)
        .setDelay(1000)
        .setImages(List.of(image));

// Print the job, using the first detected USB Brother printer
BrotherQLConnection connection = new BrotherQLConnection();
try (connection) {
    // Open the connection with the printer
    connection.open();
    
    // Check the printer state (optional)
    BrotherQLStatus status = connection.requestDeviceStatus();
    if (status.getStatusType() != BrotherQLStatusType.READY) {
        // Printer is not ready !
        return;
    }
        
    // Note : this checks the printer state before printing
    connection.sendJob(job, (pageNumber, s) -> {
        // Called when a page is printed.
        // Return true to continue with next page, false otherwise
        return true;
    });
    
} catch (BrotherQLException e) {
    // Error while printing, See e.getMessage()
    ...        
}

Upvotes: 1

Related Questions