请问如果不支持DocFlavor参数是TEXT_HTML_UTF_8类型的打印,用java有没有什么比较好的方法来实现打印??
下面是我写的测试代码!各位大虾帮忙看看阿!多谢了!
public Print() {
//
        File file = new File("c:\\pptestH.html");//
        //
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        //         DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8;
        
        PrintService service = PrintServiceLookup.lookupDefaultPrintService();
        if (!service.isDocFlavorSupported(flavor))
        {
                    System.err.println("The printer does not support the appropriate DocFlavor");
        }
}
通过测试发现打印机不支持TEXT_HTML_UTF_8类型的打印命令。
下面是我的写的例子。
public Print() {
//
        File file = new File("c:\\pptestH.html");//
        //
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        //
        DocFlavor flavor = DocFlavor.INPUT_STREAM.TEXT_HTML_UTF_8;                
        
        PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
        
        PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
        
PrintService service = ServiceUI.printDialog(null, 200, 200, printService
                                           , defaultService, flavor, pras);
        if (service != null)
        {
            try
            {
                DocPrintJob job = service.createPrintJob();//
                FileInputStream fis = new FileInputStream(file);//
                DocAttributeSet das = new HashDocAttributeSet();
                Doc doc = new SimpleDoc(fis, flavor, das);//
                job.print(doc, pras);//
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        } }
 大家帮忙看看有没有不对的地方呢?