我使用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);