java无法指定正确的打印大小
我们最近购买了一台brother QL-700打印机,我们正在通过这台机器进行一些贴纸打印
我们提供的论文是没有“长度”限制的62mm-wide sticker roll
问题是,无论我怎么做(我已经尝试了Book
,PrintRequestAttributeSet
),我都无法使用Java告诉打印机对话框窗口使用正确的打印机纸张大小。举例来说,我无法按照我们的需要精确制作62mm×40mm。它总是按如下方式“捕捉”到最近的纸张:
以下是相关代码:
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
”精确到40mm
相关: 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端口,甚至不使用brother提供的固件。它工作得很好,解决了我的问题
# 1 楼答案
我找到了一个适合我的解决方案。调用printDialog()后,不能在PrintJob上设置Printable(),但将Printable包装在Book对象中的setPageable()可以工作。第一个验证传递的页面格式并选择另一个
# 2 楼答案
您可能需要在提交printjob request时使用PrintRequestAttribute。如果自定义打印介质大小不起作用,您可能希望使用query code使用查找到的介质大小,并在请求属性集中选择最合适的介质大小
希望这有帮助
# 3 楼答案
没有比这更好的回答方式了
然后也不要混淆高度、长度和宽度,java中的paper类采用宽度和高度而不是长度
你也可以考虑这个
这些只是paper类中的一些方法,当涉及到实现时,您可能想看看这些方法,更多的是参数。。 希望有帮助:)
# 4 楼答案
我多次看到
Paper
setSize
参数被传递以保持像素大小。你能试着用这样的mm2px
来改变mm2pt
吗# 5 楼答案
使用自定义java。awt。打印纸张不能与Brother QL标签打印机一起使用强>
我已经为QL-720NW找到了一个解决方案,它几乎是同一个型号,只有WiFi和以太网请注意,所有兄弟标签打印机都可以使用
首先,需要使用驱动程序添加自定义的连续磁带格式。在Windows中,其位于:
Printer Settings
List of Custom Paper Sizes
Add Custom Paper
之后,您应该根据您选择的名称(例如,“自定义纸张”)查找媒体,并通过javax打印。打印API: