set Destination attribute in printReqAttrSet

Neacsu Cristian neacsu.cristianstefan at gmail.com
Fri May 10 08:39:21 UTC 2019


For windows print through "Microsoft Print to PDF", there is no way right
now to pre-define a path programmatically. There is no way to set inside
the printReqAttrSet (J2DPrinterJob), an attribute of type Destination, to
solve this issue.

Before jdk 9, I was bypassing it through reflection like this:

java.lang.reflect.Field field = job.getClass().getDeclaredField("jobImpl");
field.setAccessible(true);
PrinterJobImpl jobImpl = (PrinterJobImpl) field.get(job);
field.setAccessible(false);
field = jobImpl.getClass().getDeclaredField("printReqAttrSet");
field.setAccessible(true);
PrintRequestAttributeSet printReqAttrSet = (PrintRequestAttributeSet)
field.get(jobImpl);
field.setAccessible(false);
printReqAttrSet.add(new Destination(new File(filePath).toURI()));

Now, the module is closed, so I cannot access it through reflection. Is
there a way to obtain this behavior again?


More information about the openjfx-dev mailing list