如何使用java读取.xps文件格式?

xqnpmsa8  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(259)

我正在尝试使用java读取.xps文件格式。我找不到合适的解决办法。我可以使用以下代码编写.xps文件。

public static PrintService getPrinterService(String name) {

    try {
            PrintService[] printServices = PrintServiceLookup
                    .lookupPrintServices(null, null);
            PrintService printService = PrintServiceLookup
                    .lookupDefaultPrintService();
            String printerName = "sss";// PrintConfig.getOsReceiptPrinterName();

            for (int i = 0; i < printServices.length; i++) {
                PrintService service = printServices[i];
                System.out.println("service.getName() " + service.getName());
                if ("Microsoft XPS Document Writer".equals(service.getName())) {
                    return service;
                }
            }
            // job.setPrintService(printService);
            // printToKitchen=false;
        } catch (Exception e) {
        }
        return null;
    }

           public static void main(String[] args) {

        Date data = new Date(); // Data
        DateFormat dataform = new SimpleDateFormat("dd-MM-yyyy"); // Data

        PrintService service = getPrinterService("Microsoft XPS Document Writer");
        PrinterJob.lookupPrintServices();//
        // System.out.println("negin");
        if (service != null) {
            try {

                File outputFile = new File("C://Users//test//example1.xps");

                Doc doc;
                doc = new SimpleDoc(new myReceipt(),DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);

                PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
                attributes.add(new Destination(outputFile.toURI()));

                DocPrintJob job = service.createPrintJob();
                job.print(doc, attributes);
            } catch (Exception e) {
                System.out.println("kaboom" + e);
            }
        } else {
            System.out.println("XPS Printer not found");
        }
    }

对于write.xps文件,我使用了以下链接
如何使用java和javaaxp xps jar读取xps文件?:
现在我想用java读取这个.xps文件。请任何人才建议我,我如何能阅读.xps文件格式使用java。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题