File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Compressed PDF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Compressed PDF" Watch "Compressed PDF" New topic
Author

Compressed PDF

Philip Hung
Greenhorn

Joined: Dec 11, 2001
Posts: 10
Hello. I'm trying to send a PDF from a servlet and was able to successfully do it, and PDF loads within the IE window. As an experiment I try to GZIP compress the PDF before I send it. The code is as follows:

The difference here is that now IE is opening a "File Download" dialog box, to save the pdf and select a viewer for the file. I was expecting that given IE is able to decompress gzip, it would first decompress the result and since I've set the content type as "application/pdf", it would open the decompressed stream in the same IE window, like the original uncompressed version of the program.
Is my assumption incorrect? or is there something that I missed in order to expect the original load behavior?
Thanks in advance.
[ July 22, 2003: Message edited by: Philip Hung ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

You can force the browser to open the save as dialog box by setting a header to attachment. However, you can't force the browser to open the file directly. You can only suggest it.
If you suggest the browser open the file, either directly or by default (as you are doing), the browser sees if it recognizes the file type. If it recognizes the file type, it looks to see whether the default in the browser settings is open or save. If it doesn't recognize the file type, it can only save.
This is a good thing. I wouldn't want the browser automatically opening zip files potentially ontaining malicious attachments.
Also, your content type should match what you are sending over the network. In your case that would be the zip file.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Philip Hung
Greenhorn

Joined: Dec 11, 2001
Posts: 10
That make sense. Thanks for clarifying Jeanne.
However, I'm basically using the example code in the "Core Servlet" book. There was a section regarding sending compressed pages from a servlet.
So basically what I did was replace the setContentType from ("text/html") to ("application/pdf") and push a PDF info to the output stream instead of HTML. IE was able to open the "decompressed" HTML without any dialog box coming out. But I guess it was because IE naturally understands HTML, rather than PDF which required a plug-in.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compressed PDF
 
Similar Threads
send contents as attachment
Using gzip in jsp files
data loss during file transfer from applet2servlet
Cannot Download PDF (streamed) in IE with HTTPS
generate pdf and display on browser when clicked on link