RFR: 8223717: javafx printing: Support Specifying Print to File in the API [v3]

Prasanta Sadhukhan psadhukhan at openjdk.java.net
Fri Jun 25 07:23:03 UTC 2021


On Thu, 24 Jun 2021 23:00:42 GMT, Phil Race <prr at openjdk.org> wrote:

>> This enhancement adds the String property outputFileProperty() to the JobSettings class.
>> The value should be a string that references a local file encoded as a URL.
>> If this is non-null and set to a location that the user has permission to write to,
>> then the printer output will be spooled there instead of the printer, so long as the platform printing system supports this.
>> The user can of course also set a print-to-file destination in the platform printer dialogs which may over-ride what the application set. But now the application can also see what it was set to, and cancel or alter it if necessary.
>> 
>> A simple manual test is provided, manual mainly because the few real printing functional tests are all manual as they are only useful if run with a printer configured.
>
> Phil Race has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8223717: javafx printing: Support Specifying Print to File in the API

modules/javafx.graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinterJob.java line 352:

> 350:             try {
> 351:                 settings.setOutputFile(dest.getURI().toURL().toString());
> 352:             } catch (MalformedURLException e) {

I guess in 2D RasterPrinterJob, if there is any exception, we try to form a default file "out.prn"  [https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java#L1137]
and try to print there. Can't we do it here too?

modules/javafx.graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinterJob.java line 356:

> 354:         } else {
> 355:             settings.setOutputFile("");
> 356:         }

Actually in 2D , it seems if dest is null, we redirect printing to actual printer instead of file. Not sure if that is what we need to do here too!!
[https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java#L1148]

modules/javafx.graphics/src/main/java/com/sun/prism/j2d/print/J2DPrinterJob.java line 839:

> 837:             security.checkPrintJobAccess();
> 838:             String file = settings.getOutputFile();
> 839:             if (!file.isEmpty()) {

Don't we need to check for file!= null?

modules/javafx.graphics/src/main/java/javafx/print/JobSettings.java line 485:

> 483:      * <p>
> 484:      * If the application does not have permission to write to the specified
> 485:      * file, a {@code SecurityException} may be thrown when printing.

As I see in 2D atleast in Win32PrintService, if there is a SecurityException for creating a Destination object from a URI, it retries again by creating a new URL with default file "file:out.prn"
Is it not needed here?
[https://github.com/openjdk/jdk/blob/master/src/java.desktop/windows/classes/sun/print/Win32PrintService.java#L1181]

-------------

PR: https://git.openjdk.java.net/jfx/pull/543


More information about the openjfx-dev mailing list