Q: Is it possible to specify staple & duplex options on a per-document basis with jPDFPrint?
A: Yes, it is: Java supports setting print job attributes for each print job, this is done through PrintRequestAttribute objects. jPDFPrint supports passing these attributes through.
The attributes that you want to use are:
javax.print.attribute.Finishings.STAPLE |
and
javax.print.attribute.Sides.DUPLEX |
Here is a sample Java code that will verify that the printer supports the DUPLEX attribute and then print using the DUPLEX attribute:
package print; import java.awt.print.PrinterException; import java.awt.print.PrinterJob; import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.HashPrintServiceAttributeSet; import javax.print.attribute.PrintServiceAttributeSet; import javax.print.attribute.standard.Chromaticity; import javax.print.attribute.standard.PrintQuality; import javax.print.attribute.standard.PrinterName; import javax.print.attribute.standard.Sides; import com.qoppa.pdfPrint.PDFPrint; public class PrintWithAttributes { public static void main (String [] args) { try { // Load the PDF document PDFPrint pdfPrint = new PDFPrint("input.pdf", null); // Create attribute set to print to a file HashPrintRequestAttributeSet attrSet = new HashPrintRequestAttributeSet(); attrSet.add(PrintQuality.HIGH); attrSet.add(Chromaticity.MONOCHROME); // Lookup the print service by name PrintService printService = getPrintService("printer name"); // Check if the printer supports duplex if (printService.isAttributeValueSupported(Sides.DUPLEX, null, null)) { // Print with duplex attrSet.add(Sides.DUPLEX); // Send the PDF to the printer pdfPrint.print ("printer name", null, attrSet); } } catch (Throwable t) { t.printStackTrace(); } } public static PrintService getPrintService(String printerName) throws PrinterException { PrintServiceAttributeSet pSet = new HashPrintServiceAttributeSet(); pSet.add(new PrinterName(printerName, null)); PrintService[] pServices = PrintServiceLookup.lookupPrintServices(null, pSet); if (pServices.length > 0) { return pServices[0]; } else { throw new PrinterException("No Such Printer: " + printerName); } } } |
You can see all attributes supported by java by looking at the Java JDK Javadoc API and look at all classes that implement PrintRequestAttribute.