Hide Print to File in the Java Print Dialog Box

I support this Swing app with the print option. Users need not to interact with the base file system in any way, but the print dialog offers "print to file" as a single printer and, of course, allows you to select a directory and file from the file system.

Is there a painless way to override / change the print dialog to hide the printer "in file" from this dialog? I understand that the API will allow me to do this in parts, but I would prefer not to create most of the interactive GUI and functions for this.

+4
source share
2 answers

From the Sun forums (http://72.5.124.102/thread.jspa?messageID=10931926#10931926 ), while you cannot hide the button, it looks like you can capture the selection event and it throws an exception:

DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); PrintService[] printerArray = dialogPrinters.toArray(new PrintService[dialogPrinters.size()]); // call print dialog and get print attributes PrintService selectedPrinter = javax.print.ServiceUI.printDialog(null, 200, 200, printerArray, defaultPrintService, flavor, pras); // check if "print-to-file" option used if (pras.get(Destination.class) != null) { // here we deny to perform the save into a file JOptionPane.showMessageDialog(CMSJRViewer.this, getBundleString("error.printing")); throw new PrintException("Print to file option not allowed. Action aborted!"); } else { ... } 
+4
source

From what I see in the implementation classes of abstract PrinterJob , no, this is not possible.

0
source

Source: https://habr.com/ru/post/1310384/


All Articles