我正在使用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();
}
}
}