我正在使用java print service API来打印文档(pdf,jpg,excel和html)。我能够打印pdf和图像,但我无法打印html和excel。
public class Demo {
public static void main(String[] args) throws IOException, PrinterException {
FileInputStream psStream = null;
String filename = null;
filename = "I:/abc.html";
psStream = new FileInputStream(filename);
DocFlavor psInFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc myDoc = new SimpleDoc(psStream, psInFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService myPrinter = PrintServiceLookup.lookupDefaultPrintService();
if (myPrinter != null) {
DocPrintJob job = myPrinter.createPrintJob();
try {
job.print(myDoc, aset);
} catch (Exception pe) {pe.printStackTrace();}
} else {
System.out.println("no printer services found");
}
}
}
我在互联网上搜索并尝试将Doc Flavor设置为:
DocFlavor.INPUT_STREAM.AUTOSENSE
但我的输出空白。
我可以举一些关于如何使用java print API打印excel和html的例子吗?