您的位置:首页 > 编程语言 > Java开发

用java判断打印机打印服务的能力

2009-10-21 18:41 253 查看
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.print.DocFlavor;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.Attribute;

public class Main {
public static void main(String[] argv) throws Exception {
OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());

StreamPrintService service = factories[0].getPrintService(fos);
Attribute[] attrs = service.getAttributes().toArray();
for (int j = 0; j < attrs.length; j++) {
String attrName = attrs[j].getName();
String attrValue = attrs[j].toString();
System.out.println(attrName);
System.out.println(attrValue);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: