【问题标题】:how to stop printing after finished in printer job java如何在打印机作业java完成后停止打印
【发布时间】:2016-08-10 16:38:50
【问题描述】:

我的打印机作业有问题.. 我设置了我的脚本并设置了纸张尺寸,但打印机在完成打印后总是滚动.. 我用爱普生LX-300+II 在我的 epson LX-300、LX-310 和 LX-800 中,打印运行正常,打印完成后打印机自动停止,但在我的 epson LX-300+II 中,打印机在完成打印后总是滚动。 我不知道为什么,我使用相同的脚本进行打印.. 这是我设置自定义纸张大小的脚本:

public void setPrinter(String textParam, String spesialWords, int gotoX2) {

    try {
        String destination = "";
        boolean printToDoc = true;
        PrinterJob pj = PrinterJob.getPrinterJob();
        //boolean printDialog = pj.printDialog();
        System.out.println("--------------------");

        //PageFormat pf = pj.getPageFormat(null);
        PageFormat pf = pj.defaultPage();
        Paper paper = pf.getPaper();

        double cm = 72.0 / 2.54;
        if (!destination.equalsIgnoreCase("document.pdf")) {
            if (destination.equalsIgnoreCase("printer")) {
                paper.setSize(26 * cm, 7 * cm);
            }
        }
                paper.setSize(23 * cm, 7 * cm);
        double getHeight = 7 * cm;
        double getWidth = 23 * cm;
        double margin = 0.0; // half inch

        paper.setImageableArea(margin, margin, paper.getWidth(), paper.getHeight());
        pf.setPaper(paper);
        System.out.println("==========================================");
        System.out.println("paper height : "+getHeight);
        System.out.println("paper width : "+getWidth);

        PrintRequestAttributeSet attr_set = new HashPrintRequestAttributeSet();
        if (destination.equalsIgnoreCase("document.pdf")) {
            PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
            DocPrintJob printerJob = defaultPrintService.createPrintJob();
            File pdfFile = new File(destination);
            SimpleDoc simpleDoc = new SimpleDoc(pdfFile.toURL(), DocFlavor.URL.AUTOSENSE, null);
            try {
                printerJob.print(simpleDoc, null);
            } catch (PrintException ex) {
                Logger.getLogger(Printing2.class.getName()).log(Level.SEVERE, null, ex);
            }

        } else if (destination.equalsIgnoreCase("document.ps")) {
            try {
                if (textParam.toLowerCase().contains("post")) {
                    destination = "post_"+destination;
                } else if (textParam.toLowerCase().contains("non")) {
                    destination = "non_"+destination;
                } else if (textParam.toLowerCase().contains("token")) {
                    destination = "pre_"+destination;
                }

                attr_set.add(new Destination(new java.net.URI("file:" + destination)));
            } catch (URISyntaxException ex) {
                Logger.getLogger(Printing2.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        PrinterResolution pr = new PrinterResolution(120, 144, PrinterResolution.DPI);
        attr_set.add(pr);

        pj.setPrintable(new MyPrintable(textParam, spesialWords, gotoX2), pf);
        if (!destination.equalsIgnoreCase("document.pdf")) {

            try {
                //System.out.println("ini print");
                if (destination.equalsIgnoreCase("xps")) {
                    pj.print();
                } else {
                    pj.print(attr_set);
                }
            } catch (PrinterException e) {
                System.out.println(e);
                javax.swing.JOptionPane.showMessageDialog(rootPane, "Gagal mencetak struk, Silahkan lihat pengaturan printer anda");
            }
        }

    } catch (IOException ex) {
        //System.out.println("testing cuuy");
        Logger.getLogger(Printing2.class.getName()).log(Level.SEVERE, null, ex);
    }

}

【问题讨论】:

    标签: java printing


    【解决方案1】:

    我解决了我的问题: 将我的 lx-300+II 驱动打印机更改为 lx-800 我不知道为什么。 但它工作得很好

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-14
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-05
      • 2013-07-23
      相关资源
      最近更新 更多