1

我正在使用 DocPrintJob 打印一个 .txt 文件。这工作正常。该文件将从点阵打印机打印。现在,我面临的问题是-:

  • 根据我的要求,打印一条记录后,纸张需要自动回到打孔位置。
  • 但是,当直接从应用程序打印时,纸张不会自动设置回打孔位置。
  • 但是,通过在记事本中打开手动打印文件时,打印会通过自动纸张调整正常进行,即纸张设置回穿孔位置以进行下一次打印

我尝试在每页末尾使用换行符和回车符。但它没有成功。有没有办法通过代码设置打印机的调整?这是我的示例代码-:

private static void print(String fileName) throws FileNotFoundException, PrintException {
     FileInputStream textStream;
     textStream = new FileInputStream(fileName);
     DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
     Doc mydoc = new SimpleDoc(textStream, flavor, null);   
      // Set the printer Name
     PrintService service = PrintServiceLookup.lookupDefaultPrintService();
     PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
     printServiceAttributeSet.add(new PrinterName(service.getName(), null));
     // Set the paper size and orientation
     PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
     printRequestAttributeSet.add(new MediaPrintableArea(0, 0, 4, 9, MediaPrintableArea.INCH));
     printRequestAttributeSet.add(OrientationRequested.LANDSCAPE);
     InputStream is = null;
     try {
          PrintRequestAttributeSet  pras = new HashPrintRequestAttributeSet();
            pras.add(new Copies(1));
         DocPrintJob job = service.createPrintJob();
         PrintJobWatcher pjw = new PrintJobWatcher(job);
         job.print(mydoc, printRequestAttributeSet);
         pjw.waitForDone();
     }catch(Exception e){
         e.printStackTrace();
     }
     finally{
        try {
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
     }

 }
4

0 回答 0