1

可能重复:
如何打印使用 iText 创建的 PDF?

我使用 iText 创建了一个 PDF。现在,我只想打印 PDF 文件的第一页。我该怎么做?

这是我正在尝试的东西,但显然不起作用。

AttributeSet aset = new HashAttributeSet();
aset.add(new PrinterName(PRINTER_NAME, null));

PrintService[] services = PrintServiceLookup.lookupPrintServices(null, aset);
PrintService service = services[0];

System.out.println(service);

PdfReader pdfReader;
pdfReader = new PdfReader(PDF_FILE);
byte[] page1 = pdfReader.getPageContent(1);

Doc doc = new SimpleDoc(page1, DocFlavor.BYTE_ARRAY.AUTOSENSE, null);

DocPrintJob pj = service.createPrintJob();
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();

pj.print(doc, printRequestAttributeSet);
4

1 回答 1

1

没试过,但这我在 2 分钟内在网上找到的...

论坛是德语的,但是 code是英语的...应该可以

于 2012-07-19T18:29:48.263 回答