Possible Duplicate:
How to print a PDF created with iText?
I have created a PDF using iText. Now, I want to print just the first page of the PDF file. How do I do it?
Here is something that I am trying, but obviously not working.
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);
Didn’t try it but that’s what I found on the net in 2 minutes…
The forum is in German but the
codeis English… should work