Hi
I am opening a PDF file using servlet (output stream).
It opens a separate application in the acrobat reader7.0.
But the file name is randomly gnerated. i don't know why it gives random names (like AcrCD.tmp.pdf).
My code
res.setHeader("Content-length",fileLength);
res.setHeader("Content-type","application/pdf");
res.setHeader("Content-disposition","inline; filename=" + fileName );
res.setContentType("application/pdf");
res.setContentLength((int)file.length());
OutputStream outstream = res.getOutputStream();
while((len=inputstream.read(buffer))>0)
{
outstream.write(buffer,0,len);
}
inputstream.close();
outstream.flush();
outstream.close();
It is not opening with the filename.pdf, it opens with acr01.tmp.pdf
Can any one help regarding this one.
-
opening pdf file in servlet (3 messages)
- Posted by: Madhusudhanan Anna Natanagopalan
- Posted on: January 04 2006 11:36 EST
Threaded Messages (3)
- opening pdf file in servlet by abhi v on January 05 2006 22:33 EST
- opening pdf file in servlet by Pawel Zdziechowicz on January 05 2006 23:19 EST
- Checkout this example by Mac Vira on April 16 2011 12:07 EDT
-
opening pdf file in servlet[ Go to top ]
- Posted by: abhi v
- Posted on: January 05 2006 22:33 EST
- in response to Madhusudhanan Anna Natanagopalan
Check the file name. The file name must conform to the target machine's local file system conventions. After all this is only a suggestion, it does not guarantee that the file name you give will be used. If the target system decides that the filename represents some security problems (for whatever reasons) it may decide to rename the file. You will have better luck by using "attachment" instead of "inline" (it may not fit your requirements, though).
This is what the RFC (rfc 2183) that describes this header says:
"The sender may want to suggest a filename to be used if the entity is detached and stored in a separate file. If the receiving MUA writes the entity to a file, the suggested filename should be used as a basis for the actual filename, where possible.
It is important that the receiving MUA not blindly use the suggested filename. The suggested filename SHOULD be checked (and possibly changed) to see that it conforms to local filesystem conventions, does not overwrite an existing file, and does not present a security problem." -
opening pdf file in servlet[ Go to top ]
- Posted by: Pawel Zdziechowicz
- Posted on: January 05 2006 23:19 EST
- in response to Madhusudhanan Anna Natanagopalan
I don't know what browser you're using and wonder why it opens separate application (not embedded in browser) when Content-disposition is inline, butt ...
i. use rather: res.setHeader("Content-disposition","inline; filename=\"" +fileName+"\"");
without eg. in Firefox names containing whitespaces are cut to first word + extension
ii. try change inline to attachment
thus browser will ask what to do with the file (what imho is correct behaviour - eg. pdf is 18 megs)
For embedded Acrobat I've noticed that it gives file the name of service + extension when saved.
eg. http://localhost:8080/StreamData.xml?sp=l23&sp=Satt to StreamData.pdf
Service roughly is equivalent for servlet in Tapestry.
I know it is not THE answer :)
--pawel -
Checkout this example[ Go to top ]
- Posted by: Mac Vira
- Posted on: April 16 2011 12:07 EDT
- in response to Madhusudhanan Anna Natanagopalan
Checkout following blog post that contains a good example on streaming pdf using servlet.