I'm trying to set up a service that runs at night to automatically print a bunch of invoices and other documents to a bunch of printers. At the moment, I can print the documents in order, but I need to specify the tray (one with our letterhead and one with white paper). Everything that I tried so far does not work at all, I specify the MediaTray attribute in the PrintRequestAttribute set, but it does nothing. Has anyone had experience with something like this?
My current code that I use for testing is as follows.
// Create a PDFFile from a File reference File f = new File("C:\\File.pdf"); FileInputStream fis = new FileInputStream(f); FileChannel fc = fis.getChannel(); ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page PDFPrintPage pages = new PDFPrintPage(pdfFile); // Create Print Job PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat pf = PrinterJob.getPrinterJob().defaultPage(); pjob.setJobName(f.getName()); Book book = new Book(); book.append(pages, pf, pdfFile.getNumPages()); pjob.setPageable(book); // Send print job to default printer PrintRequestAttributeSet aset=new HashPrintRequestAttributeSet(); aset.add(MediaTray.MIDDLE); //Used several of the tray options here pjob.print(aset);
Galbrezu
source share