use of org.apache.pdfbox.pdmodel.interactive.viewerpreferences.PDViewerPreferences in project pdfbox by apache.
the class Printing method printWithDialogAndAttributes.
/**
* Prints with a print preview dialog and custom PrintRequestAttribute values.
*/
private static void printWithDialogAndAttributes(PDDocument document) throws IOException, PrinterException {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(new PDFPageable(document));
PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet();
// pages 1 to 1
attr.add(new PageRanges(1, 1));
PDViewerPreferences vp = document.getDocumentCatalog().getViewerPreferences();
if (vp != null && vp.getDuplex() != null) {
String dp = vp.getDuplex();
if (PDViewerPreferences.DUPLEX.DuplexFlipLongEdge.toString().equals(dp)) {
attr.add(Sides.TWO_SIDED_LONG_EDGE);
} else if (PDViewerPreferences.DUPLEX.DuplexFlipShortEdge.toString().equals(dp)) {
attr.add(Sides.TWO_SIDED_SHORT_EDGE);
} else if (PDViewerPreferences.DUPLEX.Simplex.toString().equals(dp)) {
attr.add(Sides.ONE_SIDED);
}
}
if (job.printDialog(attr)) {
job.print(attr);
}
}
use of org.apache.pdfbox.pdmodel.interactive.viewerpreferences.PDViewerPreferences in project pdfbox by apache.
the class PDFDebugger method printMenuItemActionPerformed.
private void printMenuItemActionPerformed(ActionEvent evt) {
if (document == null) {
return;
}
try {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPageable(new PDFPageable(document));
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
PDViewerPreferences vp = document.getDocumentCatalog().getViewerPreferences();
if (vp != null && vp.getDuplex() != null) {
String dp = vp.getDuplex();
if (PDViewerPreferences.DUPLEX.DuplexFlipLongEdge.toString().equals(dp)) {
pras.add(Sides.TWO_SIDED_LONG_EDGE);
} else if (PDViewerPreferences.DUPLEX.DuplexFlipShortEdge.toString().equals(dp)) {
pras.add(Sides.TWO_SIDED_SHORT_EDGE);
} else if (PDViewerPreferences.DUPLEX.Simplex.toString().equals(dp)) {
pras.add(Sides.ONE_SIDED);
}
}
if (job.printDialog(pras)) {
job.print(pras);
}
} catch (PrinterException e) {
throw new RuntimeException(e);
}
}
Aggregations