发布网友 发布时间:2022-04-23 22:46
共2个回答
热心网友 时间:2022-04-27 06:16
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_16;
InputStream in= new FileInputStream(file);//这里的file是已经生成的PDF
//PrintService[] ps=PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);//用户可选用的 PrintService实例数组。
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); //默认的PrintService
PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);
if(!ps.isDocFlavorSupported(flavor)){
System.out.println("文件格式不支持!");
return null;
}
if(service!=null){
DocPrintJob pj=service.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
Doc doc1=new SimpleDoc(in,flavor,das);
pj.print(doc1, pras);
}
in.close();
热心网友 时间:2022-04-27 07:34
嵌入字体试试 吧