In some circumstances, when - printing on windows using the javax.print APIs, - and a security manager is present - and queuePrintJob permission is granted, then a SecurityException may still be thrown. Running the program below demonstrates this java -Djava.security.manager=default -Djava.security.policy=print.policy // print.policy grant { permission java.lang.RuntimePermission "queuePrintJob"; }; // PrintSE.java import javax.print.attribute.*; public class PrintSE implements Printable { public static void main(String[] args) throws Exception { GraphicsEnvironment.getLocalGraphicsEnvironment(); PrintService service = PrintServiceLookup.lookupDefaultPrintService(); if (service == null) { return; } SimpleDoc doc = new SimpleDoc(new PrintSE(), DocFlavor.SERVICE_FORMATTED.PRINTABLE, new HashDocAttributeSet()); DocPrintJob job = service.createPrintJob(); job.print(doc, new HashPrintRequestAttributeSet()); } public int print(Graphics g, PageFormat pf, int pg) { if (pg > 0) return NO_SUCH_PAGE; g.drawString("Test passes.", 100, 100); return PAGE_EXISTS; } }
|