I am using nodejs server to serve static files. When the pdf file is served, the browser displays the title as URL of the pdf path.
127.0.0.1:8080/docs/sample
How can I set this to a custom title say "Sample"
I have tried following things but no luck :
Any help will be much appreciated.
Reason: The browser is simply reading the metadata that is saved in the actual PDF file as the document title, which may be different from the document file name. You may confirm this by opening the PDF file in Adobe Acrobat Reader > navigate to File > Properties.
In Chrome, click the three dots in the upper right corner of your browser window. Navigate to Settings › Advanced › Privacy and Security. Click Site Settings › PDF Documents.
If you're using a static file server, then yes you are serving it as a download. Modern browsers often contain a built-in PDF viewing plugin, so instead of asking the user where to save the file, the browser will instead just display the PDF right in a browser tab. It still downloaded it, it just saved it to some temporary cache on your machine in that case.
What I'm getting at is that you cannot control the browser title in that case because it's just the browser trying to be nice and make things convenient for the user. The PDF file itself would have no idea if it was being displayed in the browser's built-in viewer or in Adobe Reader on the desktop. There are no HTTP headers you could send down to set the title either because browsers expect page titles to be set from HTML or JavaScript running on an actual web page.
Now, if you were to embed the PDF file in an HTML page with some kind of PDF viewer then you could control the page title with a simple <title>some title</title>
tag or calling document.title = 'some title';
from JavaScript. That works because the browser is rendering an actual web page that you control, and that page just happens to have an embedded PDF viewer on it.
Here's an example of an embeddable PDF viewer. http://pdfobject.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With