Reputation: 2357
I'm struggling to limit the pages to be printed.
I'm using: Java17, Ubuntu 20.04
Using this example, selecting a PDF and limiting the page with PageRanges
attribute will just not work.
IPP specification has the page-ranges
attribute.
public class Main {
public static void main(String[] args) throws FileNotFoundException, PrintException {
JFileChooser fileChooser = new JFileChooser();
int result = fileChooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
FileInputStream inputStream = new FileInputStream(fileChooser.getSelectedFile());
Doc doc = new SimpleDoc(inputStream, flavor, null);
PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob printJob = ps.createPrintJob();
PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
attributeSet.add(new PageRanges(1));
printJob.print(doc, attributeSet);
}
}
}
Update:
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
for (PrintService printService : printServices) {
System.out.println("---> %s".formatted(printService.getName()));
List.of(PageRanges.class, Copies.class, PrintQuality.class, Sides.class)
.forEach(i -> System.out.println("%s -> %s".formatted(
i.getName(),
printService.isAttributeCategorySupported(i))));
}
Outputs:
---> PDF
javax.print.attribute.standard.PageRanges -> true
javax.print.attribute.standard.Copies -> true
javax.print.attribute.standard.PrintQuality -> false
javax.print.attribute.standard.Sides -> true
---> SP-3710SF
javax.print.attribute.standard.PageRanges -> true
javax.print.attribute.standard.Copies -> true
javax.print.attribute.standard.PrintQuality -> false
javax.print.attribute.standard.Sides -> true
Edit 2:
There's a statement on PageRanges about IPP (But I did not really know what it means):
IPP Compatibility: The PageRanges attribute's canonical array form gives the lower and upper bound for each range of pages to be included in and IPP "page-ranges" attribute. See class SetOfIntegerSyntax for an explanation of canonical array form. The category name returned by getName() gives the IPP attribute name.
Upvotes: 0
Views: 62