In Chrome, when hitting Ctrl + P you can choose 'Save to PDF'. The default file name is equal to the title of the html page the user wants to print. Can this be changed, without changing the actual title of the html page? I'd like to have a date & time in the PDF's name, but I don't want the date & time in the title of my html page.
Chrome save to PDF custom filename
Asked Answered
So if you can put a print button in somewhere and link it to a function similar to the following:
function printWithSpecialFileName(){
var tempTitle = document.title;
document.title = "Special File Name.pdf";
window.print();
document.title = tempTitle;
}
If you use iframe, use window.top.document.title because it is the title of the top window which is used ;) –
Betake
I'm guessing this won't apply to users who just press ctrl/cmd+p –
Hanford
const tempTitle = document.title;
window.addEventListener('beforeprint', () => {
document.title = 'custom';
});
window.addEventListener('afterprint', () => {
document.title = tempTitle;
});
This is a functionality of a print-to-PDF printer driver, and as far as I could verify, you have no control over it. So, unfortunately, the default file name will be the page title...
© 2022 - 2025 — McMap. All rights reserved.
--kiosk-printing
mode. – Ulu