title: Cannot specify the correct size for printing
body: <p>We have acquired a <a href="http://www.brother.ca/en-CA/labelprinters/24/ProductDetail/QL700" rel="nofollow noreferrer">brother QL-700</a> printer recently and we are doing some sticker printing through this machine.</p>
  
  <p>The paper that we have been feeding is a <a href="http://g03.a.alicdn.com/kf/HTB10tofHFXXXXaKapXXq6xXFXXXW/10x-x-rollETICHETTE-BROTHER-62mm-X-30-48Mt-Continuo-Termico-QL-560-QL-570-QL-700.jpg" rel="nofollow noreferrer">62mm-wide sticker roll</a> without "length" restriction.</p>
  
  <p>The issue is, no matter how I do (I've tried <code>Book</code>, <code>PrintRequestAttributeSet</code>), 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 &times; 40mm as we needed. It always "snap" to a nearest paper as it like:</p>
  
  <p><a href="https://i.stack.imgur.com/npUMH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/npUMH.png" alt=""></a></p>
  
  <p>Here is the code in question:</p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p><br><br>
  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 <code>36mm</code> was preset by the software itself:</p>
  
  <p><a href="https://i.stack.imgur.com/MnaNc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MnaNc.png" alt=""></a></p>
  
  <p><strong>So Question:</strong></p>
  
  <p>How to force the "<code>length</code>" of the paper to be exact 40mm?</p>
  
  <p>Relevant:
  <a href="https://stackoverflow.com/questions/29899335/custom-paper-size-for-labelprinter-brother-ql-570">custom paper size for labelprinter (Brother QL 570)</a></p>
  
  <p><strong>Edit</strong></p>
  
  <p>I did a media size query (<a href="https://stackoverflow.com/a/16156562/534862">code</a>) and here is the list of media that it can support:</p>
  
  <pre><code>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
  </code></pre>
  
  <p><strong>Edit (April 2017)</strong></p>
  
  <p>Just to update the status of this question. In the end I solved it by using python, and an open source utility <a href="https://github.com/pklaus/brother_ql" rel="nofollow noreferrer">brother_ql</a> 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.</p>