Jump to content
We've recently updated our Privacy Statement, available here ×

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


elangovan.pari

Recommended Posts

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!

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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));

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...