Jump to content
JasperReports Library 7.0 is now available ×

Client print directly ? Add Javascript ?


Recommended Posts

By: Eric Tan - neltan

Client print directly ? Add Javascript ?

2003-06-24 01:21

My webapp will generate the PDF to client.

However, we want to hide PDF from browser. And print it directly to client's printer.

 

How can I add javascript into the PDF ?

 

http://forum.java.sun.com/thread.jsp?forum=4&thread=351838

The forum said I can add some javascript in PDF.

To print to the default printer:

document.addJavaScript("this.print({bUI: false, bSilent: false});r");

 

Here are some code of my JSP:

 

byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, new RPT_001_Bean(ms_query) );

 

response.setContentType("application/pdf");

response.setContentLength(bytes.length);

ServletOutputStream ouputStream = response.getOutputStream();

ouputStream.write(bytes, 0, bytes.length);

ouputStream.flush();

ouputStream.close();

 

I do not see any "document". Is it embed in jasper already? How can I add javascript ?

 

 

 

 

 

By: Eric Tan - neltan

RE: Client print directly ? Add Javascript ?

2003-06-24 21:17

Hi jvergara,

 

Would you please explain more?

1. My JRPdfExporter do not have exportReportToStream(OutputStream).

 

This is my code:

JRPdfExporter j = new JRPdfExporter();

j.exportReport();

 

2. Should I use JRPdfExporter replace my code:

byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, new RPT_001_Bean(ms_query) );

 

Actually, I'm not understand how to use JRPdfExporter. Any example?

Thank you.

 

 

 

 

By: juan david vergara perez - jvergara

RE: Client print directly ? Add Javascript ?

2003-06-25 06:06

what version of jasperreports have you actually??

 

 

 

 

By: Eric Tan - neltan

RE: Client print directly ? Add Javascript ?

2003-06-25 18:20

jasperreports-0.4.6.jar

 

 

 

 

By: Eric Tan - neltan

RE: Client print directly ? Add Javascript ?

2003-06-25 19:04

Hi jvergara,

 

After looking at the src of jasperreport. I find the PdfWriter.

 

my genPDF.jsp -

 

JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, new RPT_001_Bean(ms_query) )

 

 

 

JasperRunManager.java - runReportToPdf()

 

--> JasperExportManager.exportReportToPdf(jasperPrint)

 

 

 

JasperExportManager.java - exportReportToPdf()

 

--> exporter.exportReport();

 

 

 

JRPdfExporter.java - exportReport()

 

--> this.exportReportToStream(os);

 

--> find "pdfWriter"

 

**************************************

1. Do you mean that I can modify the source of JRPdfExporter.java - exportReport() ?

2. If so how can I re-complier JRPdfExporter.java and add it into jar ? Actually, I'm not familiar with "ant".

3. This action will force all pdf to print directly, right? Can I force only one pdf to print and other not?

4. Is there any solution other than changing the source? (may be Q1 is wrong...)

 

Will this action

 

 

 

 

By: juan david vergara perez - jvergara

RE: Client print directly ? Add Javascript ?

2003-06-26 06:11

ok.. look, we overwrite some Jasper classes to add support for events to the document. One of them events is print property.

Send me an email to jvergara21@hotmail.com and i'll send you the new JR.jar and a class called JasperDocumentPros, it is the class that support events.

 

 

 

 

By: Eric Tan - neltan

RE: Client print directly ? Add Javascript ?

2003-06-29 18:38

Hi jvergara,

Here is my email: neltan2002@yahoo.com.hk.

Please send me a sample. Thank you very much !!

 

Best Regards,

neltan

 

 

 

 

By: Eric Tan - neltan

RE: Client print directly ? Add Javascript ?

2003-07-02 21:53

Hi jvergara,

Here is my email: neltan2002@yahoo.com.hk.

I did send you mail. But I didn't receive your reply.

Please send me a sample. Thank you very much !!

 

Best Regards,

neltan

 

 

 

 

By: juan david vergara perez - jvergara

RE: Client print directly ? Add Javascript ?

2003-07-03 06:20

in fact, i sent you an email on last week.

 

what ever, i forward this email at this moment.!

 

 

 

 

By: Eric Tan - neltan

RE: Client print directly ? Add Javascript ?

2003-07-06 18:35

Sorry jvergara,

I did not receive. How large is the file size?

Would you please send to another email ?

1. neltan@netvigator.com

2. neltan@mail.hongkong.com

 

Sorry for that...

 

 

 

 

By: Eric Tan - neltan

RE: Client print directly ? Add Javascript ?

2003-07-07 01:28

Thank you jvergara !!

Finally, I can insert the modified class into the original jar file. And do as what you said.

 

However, if I don't show pdf in browser, but pdf print to printer automatically. Is this possible?

 

 

 

 

By: juan david vergara perez - jvergara

RE: Client print directly ? Add Javascript ?

2003-07-08 06:36

hi neltan, is very strange that you can't receive my email.. it's not very large, like 600 KB.

what ever, i'll forward it one more time..

 

about your question, if you mean that you want to create a report, and print it directly to the default printer (on the client) , of course, it's possible, just to create a frameset, where the second frame has 0 % of rows, and in this frame you call the servlet (or jsp) that generates the byte array (pdf file).

 

here a sample.

 

out.println("<html>");

out.println(" <head>");

out.println(" <title>IPS@ - IMPRESION</title>");

out.println(" </head>");

out.println(" <frameset border="0" frameborder="0" rows="100%,*">");

out.println(" <frame name="printMain" src="co.com.winet.ipsa.impresion.CargarBuscador">");

out.println(" <frame name="printHide" src="co.com.winet.ipsa.Comodin" noresize scrolling="no">");

out.println(" </frameset>");

out.println("</html>");

 

 

the frame called "printHide", invoke a servlet that generates a pdf file!!

 

see u!

 

 

David

 

 

 

 

By: juan david vergara perez - jvergara

RE: Client print directly ? Add Javascript ?

2003-06-24 09:37

The way to add javaScript code to the pdf document is modify the JRPdfExporter class directly.

This class invoke an instance of PdfWriter class.

In the method JRPdfExporter.exportReportToStream(OutputStream) you can add the following code and... that's all folks!!!

 

String jScript = "this.print(true, 0, this.numPages-1, true);r";

PdfAction jAction = PdfAction.javaScript(jScript, pdfWriter);

pdfWriter.addJavaScript(jAction);

 

Note!!

 

"this.print(true, 0, this....."

if true... you can select the printer.

if false... print directly in the default printer.

 

Hope this helps!

 

 

 

 

By: Eric Tan - neltan

RE: Client print directly ? Add Javascript ?

2003-09-21 20:59

Hi jvergara,

I would like to ask A little bit more.

 

Can I set the PDF not cache in browser?

We don't want user load & print the previous PDF.

 

Thank a lots !!

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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