2016-11-10 131 views
10

我們最近購買了brother QL-700打印機,我們正在通過本機進行一些不乾膠打印。無法指定正確的打印尺寸

我們一直在餵養的紙是沒有「長度」限制的62mm-wide sticker roll

問題是,不管我怎麼做(我試過BookPrintRequestAttributeSet),我都無法使用Java來告訴打印機對話框窗口使用正確的打印機紙張尺寸。我無法做到,例如,準確的62mm × 40毫米,因爲我們需要。它總是「捕捉」到最近的文件,因爲它想:

這裏是有問題的代碼:

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(); 
    } 
} 



我可以證實,打印機可以在任意長度打印如下圖所示(使用Brother的P-touch編輯器)。公告雖然它的調整,但36mm由軟件本身預設:

於是問:

如何強制紙張「length」確切40毫米?

相關: custom paper size for labelprinter (Brother QL 570)

編輯

我做了一個媒體尺寸查詢(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 

編輯( 2017年4月)

只是爲了更新此問題的狀態。最後,我通過使用python和開源工具brother_ql解決了這個問題,它直接將作業發送到USB端口,而無需使用兄弟提供的固件。它工作得很好,解決了我的問題。

回答

1

有沒有更好的方式來回答這樣here

那麼也不要混淆高度和長度和寬度,在Java中的紙張類需要的寬度和高度不長

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

,你可能還需要考慮這個

/** 
* 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); 
} 

這些都只是一些紙張類中的方法,你可能想看看,當談到在IMPL ementation更多的是這樣的參數.. 希望它有幫助:)

+1

謝謝。打印機的問題在於,無論您設置什麼尺寸,打印機服務似乎都會「貼」到他們喜歡的最接近的尺寸,這與打印機不兼容,因爲打印機可以打印62毫米x *毫米的紙張尺寸。他們提供的軟件證明它可以完成,但不能用於Java。不知何故,我沒有得到正確的組合,或者Java服務不支持它。 –

0

我已經看過很多次了PapersetSize參數傳遞保持像素尺寸。你可以嘗試改變mm2ptmm2px這樣?

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

沒有運氣。它仍然選擇最接近的變體「58毫米直徑」。 –

0

您可能需要使用PrintRequestAttribute同時提交​​。如果自定義打印介質尺寸不起作用,您可能希望使用發現的介質尺寸,使用query code並在請求屬性集中選擇最合適的一種尺寸。

@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(); 
     } 
    } 
} 

希望這會有所幫助。

+0

如果我這樣做,會顯示Java的默認提示,但打印機拒絕接受該作業並在運行中取消它。我無法使用這種方法打印它:(http://imgur.com/Hj77T7H –