我们最近购买了一台brother QL-700打印机,我们正在通过这台机器进行贴纸打印。
我们喂食的论文是62mm-wide sticker roll,没有“长度”限制。
问题是,无论我怎么做(我已经尝试var magicNumber = [UInt](count: 4, repeatedValue: 0)
data.getBytes(&magicNumber, length: 4 * sizeof(UInt))
,Book
),我无法使用Java告诉打印机对话窗口使用正确的纸张尺寸打印机。我无法做到,例如,我们需要的确切的62毫米×40毫米。它总是“按下”到最近的纸张:
以下是相关代码:
PrintRequestAttributeSet
我可以确认打印机可以随意打印,如下面的屏幕截图所示(使用Brother的P-touch编辑器)。请注意,虽然它是可调整的,但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();
}
}
是由软件本身预设的:
所以问题:
如何强制纸张的“36mm
”精确到40毫米?
相关: custom paper size for labelprinter (Brother QL 570)
修改
我做了一个媒体大小查询(code),这是它可以支持的媒体列表:
length
编辑(2017年4月)
只是为了更新这个问题的状态。最后,我通过使用python和一个开源实用程序brother_ql解决了它,它直接将作业发送到usb端口,甚至没有使用兄弟提供的固件。它完美无缺,解决了我的问题。
答案 0 :(得分: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);
}
这些只是论文类中的一些方法,你可能想要了解一下实现更多的参数.. 希望它有所帮助:)
答案 1 :(得分:0)
我看到很多次Paper
setSize
参数传递了像素大小。您可以尝试使用mm2pt
这样更改mm2px
吗?
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();
}
}
答案 2 :(得分:0)
您可能需要在提交PrintRequestAttribute时使用printjob request。如果自定义打印介质尺寸不起作用,您可能希望使用query code使用发现的介质尺寸,并在请求属性集中选择最合适的介质尺寸。
if(f.getAbsolutePath().contains(".ovpn")){
files.add(f);
}
希望这有帮助。
答案 3 :(得分:0)
使用自定义java.awt.print.Paper无法与Brother QL标签打印机一起使用。
我已经找到了QL-720NW的解决方案,该解决方案几乎是相同的模型,只是带有WiFi和以太网。 请注意,它应该适用于所有Brother标签打印机。
首先,您需要使用驱动程序添加自定义连续磁带格式。在Windows中,其位于:
打印机首选项>高级选项卡>连续带格式>设置
此后,您应该通过选择的名称查找媒体(例如“自定义纸张”)并通过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();
}
答案 4 :(得分:0)
我找到了对我有用的解决方案。调用printDialog()之后,您不得在PrintJob上设置setPrintable(),但可以将Book包裹在Printable中的setPageable()起作用。第一个验证传递的PageFormat并选择另一个。