Display PDF in browser - java

I am developing a Java Web Application (jsp/servlet) using tomcat. I need to display pdf file from local machine. can you suggest what is best way to display it?

I used iframe to display pdf file.
<iframe src="resume.pdf" width="100%" style="height:60em">
[Your browser does <em>not</em> support <code>iframe</code>,
or has been configured not to display inline frames.
You can access the document
via a link though.]
</iframe>

I think you can try a Library called XPDF , I think you can convert from PDF to HTML page , or the second option is just let the user open a link to the page (www.yourwebsite.com/pdffolder/somepdf.pdf)

If you need display a pdf file using tomcat, you can access directly to the file using the specific url where the file is located in your navigator, depending on the path where you put the file, so you can access using 127.0.0.1/files/test.pdf for example. If you need generate a pdf, the best tool I think is iText, this is an easy example how to use id: Introducing PDF and iText

Related

Mounting a PDF via wicket

I am new to wicket and need to load a PDF, using Java and Wicket, when a user enters a URL. For example, typing in the URL:
www.domain.com/pdf/myDocument
will force the document www.domain.com/pdf/myDocument.pdf to be loaded
The reason for doing this is that I have a bunch of PDF documents in the webapp folder of my Java project. A printed letter that is being mailed to customers has a link to one of these documents but is missing the PDF file extension. I therefore need to put something in place that intercepts this URL and load the appropriate PDF resource.
Many thanks for any help.
Check http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/. You can load with webApplication.getServletContext().getResource(parameters.get(0).toString() + ".pdf")

Java agent to display dynamically generated graphic?

In Lotus Notes, I have a document that contains a PPT file attachment. Using Apache POI, I was planning to generate an image from a specific slide from that PPT and display it on the web browser by accessing the agent from the web probably with the use of Ajax. Is there a way to temporarily store the generated image and display it? If yes, how would you be able to do it?
You could achieve this even without saving the attachment by encoding it Base64 and embedding it in the source-code like this:
<img src="data:image/gif;base64,
R0lGODlhmwDFAPcAAAAAAAEBAQICAgMDAwQEBAUFBQYGBgcHBwgICAkJCQoKCgsLCwwMDA0N
DQ4ODg8PDxAQEBERERISEhMTExQUFBUVFRYWFhcXFxgYGBkZGRoaGhsbGxwcHB0dHR4eHh8f
HyAgICEhISIiIiMjIyQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDEx
MTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OTo6Ojs7Ozw8PD09PT4+Pj8/P0BAQEFBQUJCQkND
.... Lot of ascii characters ....
gww18FBEikHcgNkMRW5lmkJI/teaa0wNiOhshFFuiRSVpL34nqQRphZmcV5miORZQwnRpndI
nUmiiTStuaKbLl4Z45wuuADDDDfsgNKeMmy160w1hdaVSZfupyiXSgLoWpOQFjgpWUsKCGem
CEXFlIRlBefllxqKKlyblb45olWqosgmi29iGiudM+6Knp5F6LhrDYYCccQRQuzQp1cBAQA7">
If you need to store it, you could store it to a temp- folder and then attach it to a document. Then you could easily show it using an img- tag with src- url http://server/db.nsf/_/documentuniqueidOfSavedDocument/$File/nameOfImage.jpg

Show PDF file inside web browser with iText

I developed a report (without and independent of any db datasource) only with iText. I know that with JasperReports this is easy. But in my case I just storage the report in pdf file or I used acrobat for java beans to show the report to user. Now I need to change my implementation code to show this report in web browser instead to save in the file.
How I can do this?
You need 2 thinks, first the browser plugin installed on the browser and second to set the content disposition header as inline in the respose, otherwise the browser will try to download it.
response.setHeader("Content-Disposition","inline; filename=\"file.pdf\"");
I assume that you've already set the Content Type to application/pdf and know how to convert an iText document to a bytearray and transmit it to the user.
A word of caution: if people outside your organization will use this app, the might not have the pdf plugin installed, in which case, the browse will download the pdf instead of displaying the pdf.
if the browser has the appropriate add-on installed, you can just drag and drop a pdf-file into the browser and it will show it.
Or if you have a site on which you want to present the pdf, you just put a link to it:
link to your pdf
Or did you mean you want to generate html-output for your report instead of pdf?

What is the best way of opening PDFs from a JSP?

I would like some guidance on the best way of launching PDFs from a browser.
I have a JSP that takes some parameters and based on this downloads a PDF from my Documentum server. The files are stored on my local file system. I then provide the user with a bunch of links to the PDFs so they can click on them to launch the PDF.
Is there a best practice method of doing this?
Thanks.
There is nothing special to do: a link is sufficient. But you can add target="_new" if you want the browser to open the pdf in a new window.
Just make sure that the content-type returned for the pdf is application/pdf.

Generating and Displaying PDF file in Flex/Java

We have Flex on the front end and Java on the back end. When a user will request for a PDF file, request will go to the Java backend, where a PDF file will be generated using Jasper Reports. What we dont know is how to display this PDF file in browser; since we dont want to use JSP/Servlets etc - It has to be flex only. Any suggestions?
Flash Player cannot natively render PDF files. This is possible using Adobe AIR but not in a Flex application. Your best bet is to call navigateToURL() and open a Servlet in a new browser tab/window. The Servlet can simply write contents of the PDF file to the OutputStream and set the appropriate HTTP headers.
i think this question is old, but it may help others, there's a new library developed by Jasper Forge them selves, which deals with JasperReports directly, i mean it's not a PDF viewer, but a JasperReport exporting tool, you can download it from here
i tried it through using JasperServer, when viewing reports you can choose from different options to export it, one of them is flash, and it's working nice
Well for starters, PDFs don't always display in the browser. It depends on the user's settings. You essentially header them the pdf file and either they download it or a program like Acrobat Reader opens in the browser to display it.
Not sure how this is done in flex, I would imagine if you're using Java one simple servlet could do it.

Categories

Resources