I don't know if this is possible or not so bear with me.

I've got an application that serves a PDF after sending some data to the server with a POST. Currently I'm sending the PDF to the browser by setting the Content-disposition, Content-length, and Content-type headers.

Example:

res.setHeader('Content-disposition', 'attatchment; filename="' + filename + '"')
if (stats && stats.size) then res.setHeader('Content-Length', stats.size)
res.setHeader('Content-type', 'application/pdf')

stream.pipe(res)
// stream is a filestream from somewhere

Doing it this way works fine for setting the file name if you want to save the PDF. Because of some PDF encoding issues and Apple products, we now want to open the PDF directly in the browser. Users will then print as PDF to save it so that Apple readers can view the PDF correctly.

Is it possible to set the Print as PDF name? It seems that it uses URL and title to determine what the printed name is. If that's the case, is there a way of setting the title with the headers or otherwise setting the title while still loading the PDF in the browser?

有帮助吗?

解决方案

After asking a more generalized question, it would seem it's impossible.

I'm fairly certain the title behavior for files opened directly in the browser. If you attempt to save the file with the above headers, the filename will be populated correctly.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top