Jump to content

how to add silent printing ireport PDF? urgent!!!!


sanoj_mathew

Recommended Posts

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:17

Post edited by: sanoj_mathew, at: 2006/11/30 11:19

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

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

  • 1 month later...

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

 

===================

 

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

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 me

1. 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

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

  • 2 years later...

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

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

 

 

 

Link to comment
Share on other sites

  • 3 years later...

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