13
votes

We have acquired a brother QL-700 printer recently and we are doing some sticker printing through this machine.

The paper that we have been feeding is a 62mm-wide sticker roll without "length" restriction.

The issue is, no matter how I do (I've tried Book, PrintRequestAttributeSet), I couldn't use Java to tells the printer dialog window to use the correct paper size for the printer. I couldn't make it, for example, exact 62mm × 40mm as we needed. It always "snap" to a nearest paper as it like:

Here is the code in question:

PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
Paper p = pf.getPaper();
p.setSize(UnitConv.mm2pt(62), UnitConv.mm2pt(40));
p.setImageableArea(0, 0, UnitConv.mm2pt(62), UnitConv.mm2pt(40));
pf.setPaper(p);
pf.setOrientation(PageFormat.LANDSCAPE);

job.setPrintable(this, pf);

if (job.printDialog()) {
    try {
        job.print();
    } catch (Exception PrintException) {
        PrintException.printStackTrace();
    }
}



I can confirm that the printer can print at any length as we like, as shown in the screenshot below (Using Brother's P-touch editor). Notice although it's adjustable, but the 36mm was preset by the software itself:

So Question:

How to force the "length" of the paper to be exact 40mm?

Relevant: custom paper size for labelprinter (Brother QL 570)

Edit

I did a media size query (code) and here is the list of media that it can support:

17 mm x 54 mm: width = 0.67; height = 2.12
17 mm x 87 mm: width = 0.67; height = 3.42
23 mm x 23 mm: width = 0.9066535; height = 0.9066535
iso-b10: width = 1.2204725; height = 1.7322835
29 mm x 90 mm: width = 1.14; height = 3.5366535
38 mm x 90 mm: width = 1.4966536; height = 3.5366535
39 mm x 48 mm: width = 1.5366535; height = 1.8833464
52 mm x 29 mm: width = 1.1366535; height = 2.0466535
iso-b8: width = 2.440945; height = 3.464567
62 mm x 29 mm: width = 1.1366535; height = 2.44
62 mm x 100 mm: width = 2.44; height = 3.93
12 mm Dia: width = 0.47334644; height = 0.47334644
23 mm x 23 mm: width = 0.9066535; height = 0.9066535
58 mm Dia: width = 2.2933464; height = 2.2933464
12 mm: width = 0.47334644; height = 3.9366536
29 mm: width = 1.14; height = 3.9366536
38 mm: width = 1.4966536; height = 3.9366536
50 mm: width = 1.9666536; height = 3.9366536
54 mm: width = 2.1266534; height = 3.9366536
62 mm x 100 mm: width = 2.44; height = 3.93
12 mm x2: width = 0.82665354; height = 3.9366536
54 mm: width = 2.1266534; height = 3.9366536
38 mm x2: width = 2.8733466; height = 3.9366536
50 mm x2: width = 3.8133464; height = 3.9366536
54 mm x2: width = 3.9366536; height = 4.0933466
62 mm x2: width = 3.9366536; height = 4.76
29 mm: width = 1.14; height = 3.9366536
29 mm x3: width = 3.18; height = 3.9366536
38 mm x3: width = 3.9366536; height = 4.25
50 mm x3: width = 3.9366536; height = 5.66
54 mm x3: width = 3.9366536; height = 6.06
62 mm x3: width = 3.9366536; height = 7.08
38 mm: width = 1.4966536; height = 3.9366536
29 mm x4: width = 3.9366536; height = 4.2
38 mm x4: width = 3.9366536; height = 5.6266537
50 mm x4: width = 3.9366536; height = 7.5066533
54 mm x4: width = 3.9366536; height = 8.026653
62 mm x4: width = 3.9366536; height = 9.4
29 mm x 90 mm: width = 1.14; height = 3.5366535
38 mm x 90 mm: width = 1.4966536; height = 3.5366535
Small Address Label: width = 1.1366535; height = 2.44
17 mm x 54 mm: width = 0.67; height = 2.12
62 mm x 100 mm: width = 2.44; height = 3.93
62 mm x 100 mm: width = 2.44; height = 3.93
17 mm x 87 mm: width = 0.67; height = 3.42
17 mm x 54 mm: width = 0.67; height = 2.12
Binder 3 cm - Spine: width = 1.14; height = 8.226653
Binder 5 cm - Spine: width = 2.44; height = 8.226653
58 mm Dia: width = 2.2933464; height = 2.2933464
12 mm Dia: width = 0.47334644; height = 0.47334644
23 mm x 23 mm: width = 0.9066535; height = 0.9066535
23 mm x 23 mm: width = 0.9066535; height = 0.9066535
62 mm x 184 mm Postage Label: width = 2.44; height = 7.24
Binder 5 cm - Spine: width = 2.44; height = 8.226653

Edit (April 2017)

Just to update the status of this question. In the end I solved it by using python, and an open source utility brother_ql that it send jobs to the usb port directly without even using the firmware provided by brother. It works perfectly fine and solved my issue.

5

5 Answers

1
votes

there's no better way to answer like here

then also don't confuse height and length and width, the paper class in java takes width and height not length

 public void setSize(double width, double height) {
    mWidth = width;
    mHeight = height;

you might also want to consider this

   /**
 * Sets the imageable area of this <code>Paper</code>.  The
 * imageable area is the area on the page in which printing
 * occurs.
 * @param x the X coordinate to which to set the
 * upper-left corner of the imageable area of this <code>Paper</code>
 * @param y the Y coordinate to which to set the
 * upper-left corner of the imageable area of this <code>Paper</code>
 * @param width the value to which to set the width of the
 * imageable area of this <code>Paper</code>
 * @param height the value to which to set the height of the
 * imageable area of this <code>Paper</code>
 */
public void setImageableArea(double x, double y,
                             double width, double height) {
    mImageableArea = new Rectangle2D.Double(x, y, width,height);
}

those are just some of the methods inside the paper class you might want to take a look at when it comes to implementation more so the parameters.. hope it helps :)

0
votes

I have seen many times Paper setSize parameters being passed holding pixel sizes. Can you try to change mm2pt with mm2px like this?

PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
Paper p = pf.getPaper();
int resolution = 72; // dpi
p.setSize(UnitConv.mm2px(62, resolution), UnitConv.mm2px(40, resolution));
p.setImageableArea(0, 0, UnitConv.mm2px(62, resolution), UnitConv.mm2px(40, resolution));
pf.setPaper(p);
pf.setOrientation(PageFormat.LANDSCAPE);

job.setPrintable(this, pf);

if (job.printDialog()) {
    try {
        job.print();
    } catch (Exception PrintException) {
        PrintException.printStackTrace();
    }
}
0
votes

You may need to use the PrintRequestAttribute while submitting the printjob request. If custom print media size does not work, you may like to use the discovered media size using query code and select the most suitable one in request attribute set.

@Test
public void testMyPrinteService() {
    // select default or specific one here
    PrintService printService = PrintServiceLookup.lookupDefaultPrintService();

    PrinterJob job = PrinterJob.getPrinterJob();

    PageFormat pf = job.defaultPage();
    Paper p = pf.getPaper();
    p.setSize(UnitConv.mm2pt(62), UnitConv.mm2pt(40));
    p.setImageableArea(0, 0, UnitConv.mm2pt(62), UnitConv.mm2pt(40));
    pf.setPaper(p);
    pf.setOrientation(PageFormat.LANDSCAPE);

    Printable myPrintable = null ;//some printable new MyPrintable(1); 
    PrintRequestAttributeSet printReqAttrs = new HashPrintRequestAttributeSet();
    PrintRequestAttribute jobPrinArea = new MediaPrintableArea(0, 0, 64, 40, MediaPrintableArea.MM);
    printReqAttrs.add(jobPrinArea);

    if (job.printDialog(printReqAttrs)) {
        try {
            job.setPrintable(myPrintable, pf);
            job.setPrintService(printService);
            //pass specific attributes to printer
            job.print(printReqAttrs);
        } catch (Exception PrintException) {
            PrintException.printStackTrace();
        }
    }
}

Hope this helps.

0
votes

Using a custom java.awt.print.Paper won't work with Brother QL label printers.

I've figured out a solution for QL-720NW, which is almost the same model, just with WiFi and Ethernet. Note that it should work will all Brother label printers.

First you need to add a custom continuous tape format using the drivers. In Windows, its located in:

Printer Preferences > Advanced tab > Continuous Tape Format > Settings

Printer Settings

List of Custom Paper Sizes

Add Custom Paper

Afterwards you should find the media by the name you have chosen (e.g., "Custom paper") and print via the javax.print API:

// Lookup printer by name 
PrintService[] foundPrinters = PrintServiceLookup.lookupPrintServices(null, new HashAttributeSet(new PrinterName("QL-720NW", null)));
PrintService printer = foundPrinters[0];

// Lookup custom paper by name
MediaSizeName paper = null;
for (Media m : (Media[])printer.getSupportedAttributeValues(Media.class, null, null))
{
    if (m instanceof MediaSizeName)
    {
        MediaSizeName media = ((MediaSizeName)m);
        if ("Custom paper".equals(media.toString())) paper = media;
    }
}

// Create a new printable object
Printable p = ...; // Create a printable object
Doc doc = new SimpleDoc(p, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);

// Set custom paper as request attribute
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
attrs.add(paper);

// Create a new print job and print it
DocPrintJob job = printer.createPrintJob();
try
{
    job.print(doc, attrs);
}
catch (PrintException ex)
{
    ex.printStackTrace();
}
0
votes

I found a solution that worked for me. After calling printDialog() you must not setPrintable() on the PrintJob, but setPageable() with the Printable wrapped in a Book object works. The first one validates the passed PageFormat and chooses another.