Reputation: 4246
My Java servlet includes the following line:
response.addHeader("Content-Disposition", "filename=myFile.pdf");
I need to include a named destination defined in the PDF file as part of the file name. Ideally, I could use the following:
response.addHeader("Content-Disposition", "filename=myFile.pdf#Chapter3");
but when I run it, the url in the browser shows /path/to/myFile.pdf%23Chapter3
instead of the desired /path/to/myFile.pdf#Chapter3
.
How to escape the # in "filename=myFile#Chapter3"? Escaping with \ gives a compile-time error. Escaping with &035; doesn't work either.
Upvotes: 0
Views: 412
Reputation: 24812
RFC 2616 defines that "the Content-Disposition response-header field has been proposed as a means for the origin server to suggest a default filename if the user requests that the content is saved to a file" so I don't think you can do what you intend to through your servlet. Maybe you will have better luck with some script in the pdf : you could imagine parsing its own name to dynamically set it at the right anchor at opening.
Upvotes: 3