wood burning stoves 2.0*
The moose likes Servlets and the fly likes JSP & PDF's Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP & PDF Watch "JSP & PDF New topic
Author

JSP & PDF's

Jan Muller
Greenhorn

Joined: Mar 19, 2001
Posts: 6
I am working on a project that accept an aplication. Depending on if the application was accepted or not by the processing servlet, I want to display a new page that includes an link to a PDF. I do not want to save the PDF on the server but push it through to the client's machine. Does anybody know how I can do this from within a JSP.


Jan H Muller<BR>[mail]janmuller@home.com[/mail]
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

I'm not sure I understand what you are trying to do.
What is the PDF you want displayed?
If it isn't on the server, where is it?
You can link to a PDF file just like you would from a static HTML page.
Rephrase your question and people will probably be able to help you solve your problem.


!_I_Know_Kung_Fu_!
Jan Muller
Greenhorn

Joined: Mar 19, 2001
Posts: 6
I am quite new to JSP development. What I am trying to do, is generate the PDF in a servlet with the result of the application into a String and this string can go into the Session for the JSP to retrieve . I want to display an HTML page with an informative message and an PDF icon that the user can click on to display/save the PDF page. I hope this is a better description of what I want to do.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Jan,
Is this what you wanted ? For the pdf content part I used a physical .pdf file which reside in server. In your case you can use a session bean's .getPDFBytes() method to get the bytes of PDF content. I used the jsptags pdf file which downloaded from sun's site at http://java.sun.com/products/jsp/syntax.pdf for this example and able to view as PDF file through Netscape. But no luck with IE.

In your case , your main .html page can be like this.




[This message has been edited by maha anna (edited March 19, 2001).]
Jan Muller
Greenhorn

Joined: Mar 19, 2001
Posts: 6
I have tried this solution but I get an error 500 added to the back of the pdf after the %%EOF pdf tag and this corrupts the pdf.

[ July 24, 2002: Message edited by: Mike Curwen ]
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
I am able to view the pdf without 500. 500 error means some error related to server side processing. may be in jsp code. Check it once again.
To go one step at a time write a simple jsp and read a .pdf file from server's disk and push to client and see if you could succeed.
Also please post your jsp code here.
regds
maha anna
Jan Muller
Greenhorn

Joined: Mar 19, 2001
Posts: 6
I found an open source package at the following site that generates PDF files : http://www.dot.state.oh.us/javapdf/
I wrote a Servlet that displays a jsp the first time it is activated and a PDF if a button is pressed on this jsp using
the PdfPage class in the above package. The Servlet Code follows.

My Jsp looks like this :

This works!!!
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Thanks for sharing this link Jan!
regds
maha anna
Vin Man
Greenhorn

Joined: Jun 13, 2001
Posts: 26
Hi Jan,
Thanks for the posting of the link to the Ohio Dot open source project.
I tried running their hello2 and hello3 example - pretty much like what you did in your "myClass" servlet. My hello2.java code follows:
public class hello2 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/pdf");
PdfPage page = new PdfPage(response.getOutputStream());
page.setFont(page.BOLD, 50);
page.println("Tutorial - Hello 2");
page.setFont(page.NORMAL, 25);
page.println(new Date().toString());
page.close();
}// doGet()
}// end of class
after deploying the servlet to my jrun servlet engine and restarting it, I type in the address to my servlet on my IE address bar (eg. http://localHost/test/servlet/sutut1.hello2). What I am getting is a blank page!!! Did you run into this problem? and what did you do to get your content displayed?
Shubhrajit Chatterjee
Ranch Hand

Joined: Aug 23, 2001
Posts: 356
When you are generating a file "on the fly" which has white space constraints ( i mean white spaces will make it unrenderable) then it is unwise to use JSP ... as JSP engine will always add white spaces to the output stream ... use a servlet instead.
I have used a great open source tool for generating PDF on the fly ... it is called by iText. In fact using by iText we are now producing very crisp reports from back end data bases and have won lotas of kudo's form our client. You might like to check it out
The link is ...
http://www.lowagie.com/iText/


Shubhrajit
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Hi Jan,
You can try FOP from apache http://xml.apache.org/fop
U can use it with Servlet or Jsp.
Even though its main target is for XML,u can give a try. The best u will get is clear seperation from presentation design and control.
U can design all ur PDF layout in a file can fo (formatting objects),later supply this .fo to ur servlet,then it will create PDF dynamically
somehting like http://localhost:8080/servlet/FopServlet?fo=mypdf.fo&out=mypdf.pdf
This won't create any local files in hardisk.If the client wants he can store it by click save
Works in all browsers.
If time permits u can give a try.
Reagards
Balaji
[ July 26, 2002: Message edited by: Balaji Loganathan ]

Spritle Software Blogs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP & PDF's