Read PDF to Browser

Hi

I have some files in my server that I need to read to the client browser.

This pdf files are located outside of my application directory (ex: c:\myfiles).

I have one script that read the file content (line by line) and print to the jsp page, and I have response.setContentType("application/pdf");, but when I load the page I just have strange characters.

I would like to open the file with the acrobat reader.

Anyone know what can be the problem?

Thanks in advance.

Lu韘 Matos

[527 byte] By [lghm@aeiou.pta] at [2007-10-3 0:25:36]
# 1

...you can use a iframe in your html code....

<iframe id="ReportFrame" marginheight="200" width="850" height="600"

style="left:10px;top:110px;" src="YOUR/DIRECTORY">

</iframe>

...also you can change de src (source)...with java script...

i forget...in your browser have to be installe de acrobat reader plugin...

pachiloa at 2007-7-14 17:18:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Reading the file line by line?

Sounds like you are opening it with a file writer.

Two suggestions to get it to work

1 - Use a servlet rather than a JSP to send the file. JSP adds in extra characters (all those line breaks) which would corrupt the PDF

2 - use response.getOutputStream() from the servlet and write bytes, rather than using a writer.

evnafetsa at 2007-7-14 17:18:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hi

pachilo and evnafets thanks for the replies.

I already try to use the response.getOutputStream(); but sometimes I get the error that the response.getOutputStream(); is already called.

I change my way o read the file to FileInputStream instead of FileReader and now is working.

I just don't understand why with the FileReader don't work.

Thanks

Lu韘 Matos

lghm@aeiou.pta at 2007-7-14 17:18:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hi

Now I have another problem. If the computer that access to the webpage don't have the acrobat reader installed the content of the page is, one more time, strange characters.

In this case, it should be prompted to download the file.

If I have the acrobat installed than it open the acrobat reader, but not inside the webpage, it opens in the acrobat program.

Anyone know any solution for this?

Thanks

Lu韘 Matos

lghm@aeiou.pta at 2007-7-14 17:18:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

>I just don't understand why with the FileReader don't work.

Because FileReader is for reading plain Text files. It only expects characters.

A PDF (like an image) is stored in binary format.

>If the computer that access to the webpage don't have the acrobat

>reader installed the content of the page is, one more time, strange characters.

This is a client configuration thing. If the browser thinks it knows what the file is, it will try to open it. You can't tell from the server end if the client has acrobat reader installed or not.

Solution: install acrobat reader.

Workaround: right click the links and "save as"

>If I have the acrobat installed than it open the acrobat reader, but not

>inside the webpage, it opens in the acrobat program.

This is a preference inside the Acrobat reader.

Look on Edit:Preferences, under the category "Internet"

Each individual user configures this how they like it. You can't affect it from the server.

evnafetsa at 2007-7-14 17:18:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...