phpwkhtmltopdf
phpwkhtmltopdf copied to clipboard
PDF document filename with inline downloads
Hello there
I have found that if I run the following code:
$pdf->send("This-is_a_lovely__filename.pdf", true);
Then the PDF is automatically downloaded, with the correct filename. this is great
However, if I want the user to be able to view the PDF first, by using this:
$pdf->send("This-is_a_lovely__filename.pdf");
Then when the user saves the PDF, the filename becomes "document.pdf"
Is this a limitation of the browser? I'm using Firefox in this instance.
Thanks, Chris
Honest answer: I don't know. The download logic was refined many times over the years and is based on the official PHP manual for readfile(). It should work - but browsers sometimes change their behavior so I just can't tell.
You can find our implementation here: https://github.com/mikehaertl/php-tmpfile/blob/master/src/File.php#L95
What you could do:
- Create a simple test PHP script (without our library)
- Build a download logic with
readfile()to send some test PDF you have on your server - Try to mimic the same headers we have in our
File.phpand then play around with different header settings to find out if you can achieve what you want. Main thing to check is probably theContent-Dispositionheader.
If you find a combination that works you can report it here and we can see if we can improve the situation.
@christatedavies Any news here? Did you have a chance to reproduce the issue with a custom PHP script?
Hi Mike. Not really, it looks like its an issue with the browser and how you can tell the browser to download or prompt. I don't fully understand it personally.
Ok. I'll leave this open for now. If you or someone else finds a way feel free to post an update here so we can add it to the lib.