/** * Prints using custom PrintRequestAttribute values. */ private static void printWithAttributes(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new PageRanges(1, 1)); // pages 1 to 1 job.print(attr); }
private void calculateTotalPagesToPrint() { // iterate over page ranges to find out how many pages are to // be printed PageRanges pageRanges = (PageRanges) printRequestAttributeSet.get(PageRanges.class); totalPagesToPrint = 0; // we need to loop over the multiple ranges as commas can be used // to specify more then one range. Make sure the specified pages // fall with in the range allowed by the document. int start, end; for (int[] ranges : pageRanges.getMembers()) { start = ranges[0]; end = ranges[1]; if (start < 1) { start = 1; } if (end > pageTree.getNumberOfPages()) { end = pageTree.getNumberOfPages(); } totalPagesToPrint += end - start + 1; } }
attr.add(new PageRanges(1, 1)); // pages 1 to 1
DocPrintJob printJob = printService.createPrintJob(); HashPrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); attributes.add(new PageRanges(1)); printJob.print(pdfDoc, attributes);
/** * Prints using custom PrintRequestAttribute values. */ private static void printWithAttributes(PDDocument document) throws IOException, PrinterException { PrinterJob job = PrinterJob.getPrinterJob(); job.setPageable(new PDFPageable(document)); PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new PageRanges(1, 1)); // pages 1 to 1 job.print(attr); }
printRequestAttributeSet.add(new PageRanges(startPage + 1, endPage + 1));
printRequestAttributeSet.add(new PageRanges(startPage + 1, endPage + 1));
aset.add(new PageRanges(1, 1)); aset.add(new Copies(1));
attr.add(new PageRanges(1, 1)); // pages 1 to 1
printRequestAttributeSet.add(new PageRanges(startPageIndex + 1, endPageIndex + 1));