我的打印机作业出现问题。。我已经设置好了脚本和纸张大小,但打印机总是在打印完成后滚动。。我使用epson 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);
}
}
我用以下方法解决问题:将lx-300+II的驱动程序打印机更改为lx-800我不知道为什么。但它运行得很好