Jasper Report - Direct(Silent) Printing or Open PDF without Save and with Print

Hi,

We have requirement to Print the Jasper Report directly to the printer or open the report on client screen with Print option only(No save/Save as/right click save/ctrl+s).

1. We gave the below Silent Print solution by using Acrobat reader's Javascript enable option. but client is not accepting this solution since enabling Javascript may cause security issues(like malicious code injection).

JRPdfExporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print({bUI: true, bSilent: true, bShrinkToFit: true});");

2. We tried Jasperviewer and we are getting java.awt.headless exception evethoughwe set  java.awt.headless=true/false.

public class JasperViewer2 extends JasperViewer {

        public JasperViewer2(JasperPrint jasperPrint) {

                super(jasperPrint);

                // remove "save" button

                try {

                        //find button

                        Field f = this.viewer.getClass().getDeclaredField("btnSave");

                        f.setAccessible(true);

                        JButton saveButton = (JButton) f.get(this.viewer);

                        saveButton.setVisible(false); // or setEnabled(false);

                } catch (Exception e) {

                        //silent

                }

        }

}

3. We tried PrintService API, It is working fine in our local workspace whereas When we deploy our code in the Websphere Portal server(Linux) we dont get Printer details which are configured on client machine.

 PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet(); 

PrintService[] services = PrintServiceLookup.lookupPrintServices(null, printServiceAttributeSet);
                         PrintService[] printservices = PrintServiceLookup.lookupPrintServices(null, null);
                          PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();

and we are trying many options but we dont get proper solution, Can you please anyone provide the solution, appreciate your help!

elangovan.pari's picture
Joined: Nov 30 2016 - 1:48am
Last seen: 5 years 11 months ago

3 Answers:

Hi,

you can refer to: http://jasperreports.sourceforge.net/sample.reference/printservice/index.html for more info on this topic.

Regards

bojan.brajkovic's picture
Joined: Sep 11 2017 - 5:41am
Last seen: 4 years 10 months ago

Thank you for the detais, They have hard coded(though its commented) this Printer names, we dont know the client's printer names, how to handle these ?

 PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
    //printServiceAttributeSet.add(new PrinterName("Epson Stylus 820 ESC/P 2", null));
    //printServiceAttributeSet.add(new PrinterName("hp LaserJet 1320 PCL 6", null));
    //printServiceAttributeSet.add(new PrinterName("PDFCreator", null));
elangovan.pari's picture
Joined: Nov 30 2016 - 1:48am
Last seen: 5 years 11 months ago

If no printer name is provided, the print service lookup mechanism will be triggered, in order to find the available printers.

The exporter uses the first print service in the list returned by this mechanism.

shertage's picture
22162
Joined: Sep 26 2006 - 8:06pm
Last seen: 2 months 2 weeks ago
Feedback
randomness