sanoj_mathew Posted November 30, 2006 Share Posted November 30, 2006 hello all i need to add silent printing for ireport generated PDF that is to be shown in a browser . By using the itext generated PDF i can do the code as shown below and it is working fine.. But how can i implement this in ireports please help me !!!!!!!! ServletOutputStream out = response.getOutputStream();Document document = new Document();ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {PdfWriter writer = PdfWriter.getInstance(document, baos);writer.setViewerPreferences( PdfWriter.HideMenubar | PdfWriter.HideToolbar | PdfWriter.HideWindowUI );document.open(); writer.addJavaScript("this.print({bUI: false,bSilent: false,bShrinkToFit: true});" +"rn" +"this.closeDoc();"); document.add(new Chunk("Silent Auto Print")); document.close();}catch (DocumentException e){e.printStackTrace();} response.setContentType("application/pdf"); response.setContentLength(baos.size()); baos.writeTo(out); out.flush(); Post edited by: sanoj_mathew, at: 2006/11/30 11:16 Post edited by: sanoj_mathew, at: 2006/11/30 11:17Post edited by: sanoj_mathew, at: 2006/11/30 11:19 Link to comment Share on other sites More sharing options...
Teodor Danciu Posted December 12, 2006 Share Posted December 12, 2006 Hi, We have added support for JavaScript in the PDF exporter.This will be part of the next release. You could test it in the meatime by getting the latest source code from our SVN repository, if you want.It is simply about a new PDF exporter parameter that allows you to supply a JavaScript snippet to be executer when the PDF opens in the viewer. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
kgopalrao Posted January 17, 2007 Share Posted January 17, 2007 Thankyou in advance, Here is my situation, I downloaded the latest jsper report bundle on Jan-12-2007.I am using the latest ireport to generate the jrxml file and using that generate a PDf report.I am able to generate the report properly I am having problems with silent printing. I want the generated PDF to be such that when the pDf is opened in the browser it will automatically send to the default printer on the client side. For testing, I made the security setting on ie, to the lowest possible. Here is the code snippet ======================== = HashMap params = new HashMap(); // adobe javascript code for the silent printStringBuffer javascript = new StringBuffer();javascript.append("var params= his.getPrintParams();");javascript.append("params.interactive=params.constants.interactionLevel.silent;");javascript.append("params.pageHandling =params.constants.handling.shrink;");javascript.append("this.print(params);");params.put(JRPdfExporterParameter.PDF_JAVASCRIPT, javascript.toString()); MapBasedJRDataSource mapBasedJRDataSource = new MapBasedJRDataSource(values);jasperPrint = JasperFillManager.fillReport(jasperReport, param,mapBasedJRDataSource); byte[] report=JasperExportManager.exportReportToPdf(jasperPrint); =================== Even after I do the above step I find that the pdf is generated properly, but nothing is send to the printer. Thank you,Gopal Link to comment Share on other sites More sharing options...
Teodor Danciu Posted January 17, 2007 Share Posted January 17, 2007 Hi, I'm not an expert on JavaScript.You should note that the PDF_JAVASCRIPT parameter accepts Acrobat JavaScript. I guess you should read Acrobat JavaScript documentation to see why it does not work. A start could be the iText documentation. I hope this helps.Teodor Link to comment Share on other sites More sharing options...
kgopalrao Posted January 18, 2007 Share Posted January 18, 2007 Thank you very much for your help. Couple of things, I tried using Itext directly. Here is the code snippet,=========== =PdfWriter writer = PdfWriter.getInstance(document, baos);writer.addJavaScript("this.print(false);", false);document.add(new Chunk("Silent Auto Print")); ============ =And it works, Then I used the same script "this.print(false);" with jasperreport/ireport combination and I had the same old issue. Couple of questions that will help me1. As per you what I am doing (as far as jasper-report cois concerned is correct. And it should have worked. 2. I am wondering if I have to something at the Ireports side, like add a parameter with some specific name and instructions, so that it will work. I am also attaching my JRXL file (one that i generated using ireports/ latest version (As of Jan-12-2007) Once again thank you for you help. Gopal [file name=test_report.jrxml size=2211]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/test_report.jrxml[/file] Link to comment Share on other sites More sharing options...
pmaslov Posted January 23, 2007 Share Posted January 23, 2007 Hi Gopal,I was able to start printing on load in my PDF report. I doubt you can insert Acrobat Javascript right from iReport. Although I was able to do this by insering code exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.print({bUI: true, bSilent: false, bShrinkToFit: true});"); into PdfServlet that already has everything else for PDF exporting.I also got latest (trunk) JasperReports version 1.3.0 from svn. Pavel Link to comment Share on other sites More sharing options...
shibinthomas Posted September 29, 2009 Share Posted September 29, 2009 Hi teodord (all), i am trying to call the printer using the demo provided in (jasperreports-3.5.2\demo\samples\printservice). my problem is while genarate report and display print dialog the page scale attribue should be "Fit to Printable Area" . if i am use this "this.print({bUI: true,bSilent: true,bShrinkToFit: true});" in JRPdfExporterParameter.PDF_JAVASCRIPT my problem may be solved. but in 3.5.2 that attribute not avilable. Is any alternate solutions avilable [ using javax.print.attribute. pakage ] ? I need to select the paper size A4 (MediaSizeName.ISO_A4)&page scale attribue in print dialog to "Fit to Printable Area", while user generate report . Thanks in advance Shibin Link to comment Share on other sites More sharing options...
Teodor Danciu Posted September 29, 2009 Share Posted September 29, 2009 Hi, I don't see what you mean when you say that in 3.5.2, the PDF_JAVASCRIPT parameter is not available.You mean you tried it in 3.5.2 and it did not work or what? Thank you,Teodor Link to comment Share on other sites More sharing options...
shibinthomas Posted September 30, 2009 Share Posted September 30, 2009 I am extremely sorry.That is my mistake .. i compile the application with version 1.2.4 . so i mistaken .Now i am able to use this property PDF_JAVASCRIPT as shown belowexporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT,"this.print({bUI: true,bSilent: false,bShrinkToFit: true});"); using this i am able to populate print dialog and get select property page sacling to Fit to Printable Area.Also i need in Preview Composite (now 8.5 * 11 ) with A4 size(that is 8.27 * 11.69). How i set this values in PDF_JAVASCRIPT. Thanks in advanceShibin Link to comment Share on other sites More sharing options...
shivamkhandelwal Posted March 13, 2013 Share Posted March 13, 2013 This javascript option does not work anymore due to some kind of update in adobe reader update ...Please look into this issue as many funcitonalities stopped working instantaneously..... Shivam 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