Chrome save to PDF custom filename
Asked Answered
S

3

18

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.

Scorekeeper answered 13/11, 2014 at 9:54 Comment(0)
B
37

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;
}
Brothel answered 10/2, 2016 at 8:52 Comment(3)
That's a great workaround! Especially combined with --kiosk-printing mode.Ulu
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+pHanford
M
1
    const tempTitle = document.title;
    window.addEventListener('beforeprint', () => {
        document.title = 'custom';
    });
    window.addEventListener('afterprint', () => {
        document.title = tempTitle;
    });
Metrology answered 29/6, 2023 at 6:20 Comment(0)
T
-1

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...

Triune answered 13/11, 2014 at 10:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.