我正在研究打印系统,需要在每个打印文档中添加任意文本(如作者,文档哈希,一些sysvars等) . 我们使用Java Printing Service(javax.print)作为打印客户端,使用Cups作为服务器 .
Cups有一些称为“过滤器”的文档后处理程序 .
过滤器 - 是一个由Cups推出的程序 . 杯子通过过滤一些参数 - 其中包括"job attributes" .
因此,我决定将自定义属性从java传递到cups并在过滤器中将属性作为文本添加到文档中 . 一切正常,文档被打印,但我没有在过滤器中获取我的属性 . 他们甚至没有被传递到Cups(在包嗅探器中看到它) .
我已经使用getSupportedAttributeCategories()来查看支持的列表(通过打印机?)属性 . 也许我应该以某种方式将我添加到该列表中,但我不明白如何 .
我不仅限于"attributes", I just need to pass arbitary data from java to Cups filter . 我该怎么做?
我的java代码如下:
MyAttrSet attrs = new MyAttrSet();
attrs.add(new MyAttr(42));
attrs.add(new Copies(18));
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(is, flavor, null);
DocPrintJob job = service.createPrintJob();
job.print(doc, attrs);
Filter是一个简单的bash脚本,它打印传递给它的所有内容:
#!/bin/bash
echo "All args:" > /tmp/f1.log
for var in "$@"
do
echo "$var, " >> /tmp/f1.log
done
/tmp/f1.log看起来像:
All args:
87,
oroboros,
Java Printing,
18,
some useless crap like job uuid and else...
MyAttr:
class MyAttr extends IntegerSyntax implements PrintRequestAttribute {
protected MyAttr(int value) {
super(value);
}
public Class extends Attribute> getCategory() {
// TODO Auto-generated method stub
return MyAttr.class;
}
public String getName() {
// TODO Auto-generated method stub
return "somemycustop5";
}
}