Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving already opened pdf file in broswer

 
Veeren Jote
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Veeren Jote
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not believe that that is something you will be able to control.
 
Veeren Jote
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic