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 Saving already opened pdf file in broswer Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Saving already opened pdf file in broswer" Watch "Saving already opened pdf file in broswer" New topic
Author

Saving already opened pdf file in broswer

Veeren Jote
Greenhorn

Joined: Dec 01, 2009
Posts: 6
I have servlet which creates and send a pdf based file and i ask it to open inline inside of a browser window.
This works as intended, but when i try to "save" the file from the Adobe's menu, it just takes the servletname for the file name instead of actual filename i supplied.

Did anyone overcome this issue?
Veeren Jote
Greenhorn

Joined: Dec 01, 2009
Posts: 6
Code is something similar to below:

response.setContentType("application/pdf"); // MIME type for pdf doc
response.setContentLength(fileContent.length);
String downloadreportname = "CustomeFileNameGenerated.pdf";
//set response headers
response.addHeader("Content-Disposition", "inline; filename=" + downloadreportname);

response.getOutputStream().write(getFileContents());

This works like a charm, but when the actual file is downloaded by the broswer and opened up inside a broswer window by adobe plugin, I dont get the right file name when we hit "save"
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56528
    
  14

It's doing exactly what you told it to. If you don't want it to be inline, don't specify inline. What you want is "attachment".


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Veeren Jote
Greenhorn

Joined: Dec 01, 2009
Posts: 6
Thanks for your reply, appreciate your help.
Well i know about inline & attachment clauses, and thats what my intention is... to display the pdf inline inside browser.

But after the PDF is loaded inside the browser and we want to hit save on the Adobe's plugin's menu inside the broswer, then it provides a dialog box which should prompt me to save the file.
So far so good, but the prompted name that is displayed is NOT the name i intended it to be, its with the servlet's name.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56528
    
  14

I do not believe that that is something you will be able to control.
Veeren Jote
Greenhorn

Joined: Dec 01, 2009
Posts: 6
Thanks for your reply.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Saving already opened pdf file in broswer
 
Similar Threads
Passed IBM WebSphere Portal V5.0, Application Development Test 348
web.xml couldn't detect taglib tag anymore?
running another application from java
Creating a file from Various chunks of different files in java
chinatag SCEA5 exam simulator