0
我在尝试打印“.pdf”时遇到问题。我用这个代码打印字符串没有问题,但PDF不会。打印“.pdf”文件 - PrinterJob
我的程序用pdf接收一个byte []并打印出来,我想录制一个tempfile来从InputStream打印,但也失败了。
跟随我用打印的代码:
FileChannel fc = null;
ByteBuffer bb = ByteBuffer.wrap(pdf);
FileOutputStream fos = null;
RandomAccessFile fis = null;
try {
File Tempfile = File.createTempFile("portfolios-temp", ".pdf");
fos = new FileOutputStream(tempfile);
fos.write(pdf);
fos.close();
FileInputStream psStream = new FileInputStream(tempfile);
DocFlavor psInFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
MyDoc doc = new SimpleDoc(psStream, psInFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add (new Copies (1));
aset.add (OrientationRequested.PORTRAIT);
aset.add (Sides.ONE_SIDED);
aset.add (MediaSizeName.ISO_A4);
DocPrintJob job printService.createPrintJob =();
try {
job.print (myDoc, aset);
} Catch (Exception pe) {
pe.printStackTrace();
}
} [...]
我得到的打印服务是这样的:
PrintService printService = null;
for(PrintService printServiceCurrent : PrinterJob.lookupPrintServices()) {
if(printServiceCurrent.getName().equals(PRINTER_NAME)) {
printService = printServiceCurrent;
break;
}
}
他向打印机发送一个命令,但是就这样产生没有内容。我检查了临时文件,它正在完美生成。
有什么想法?
在此先感谢。
我补充说,我得到的打印服务的代码。我还修复了aset的代码。谢谢 – Gannis