elangovan.pari Posted September 29, 2017 Share Posted September 29, 2017 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 More sharing options...
bojan.brajkovic Posted September 29, 2017 Share Posted September 29, 2017 Hi,you can refer to: http://jasperreports.sourceforge.net/sample.reference/printservice/index.html for more info on this topic.Regards Link to comment Share on other sites More sharing options...
elangovan.pari Posted September 29, 2017 Author Share Posted September 29, 2017 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 More sharing options...
szaharia Posted October 2, 2017 Share Posted October 2, 2017 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now