how to add silent printing ireport PDF?

http://community.jaspersoft.com/questions/514537/how-add-silent-printing-ireport-pdf-urgent

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});" +
"\r\n" +
"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();

Here is the code snippet
======================== =

HashMap params = new HashMap();
// adobe javascript code for the silent print
StringBuffer 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);

===================
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

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
Now i am able to use this property PDF_JAVASCRIPT as shown below
exporter.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 advance
Shibin

你可能感兴趣的:(java)