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!
3 Answers:
Hi,
you can refer to: http://jasperreports.sourceforge.net/sample.reference/printservice/index.html for more info on this topic.
Regards
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));