Sicos1977 / ChromiumHtmlToPdf

Convert HTML to PDF with a Chromium based browser
431 stars 85 forks source link

Document title #164

Open nicolasr75 opened 4 weeks ago

nicolasr75 commented 4 weeks ago

I noticed today that the input filename is used as the document title for the PDF. Ex. my output filename is Report_2024.pdf, my input filename is input.html.

When I open the PDF in Adobe Viewer and Adobe already has files opened, it displays tabs for the PDFs which contain the document title. In my case the title is input.html which is confusing to the user.

Is there any way to explicitly set the document title?

Thanks for your great work!

Sicos1977 commented 4 weeks ago

I don't think there is an option to set the title --> https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF

Sicos1977 commented 4 weeks ago

Try this (from stackoverflow) --> https://stackoverflow.com/questions/26905908/chrome-save-to-pdf-custom-filename

Sicos1977 commented 4 weeks ago

I try to have a look in the code to see if I can add it as an option and then inject some JavaScript in the dom object before converting it to PDF. But if you need a quick solution than try the stack overflow suggestion.

nicolasr75 commented 4 weeks ago

Thanks for looking into this. After reading the Stack Overflow suggestions I found out that it's much easier, at least for my application: simply set the title tag in the html head to the desired name and Chrome will respect that. In my application I create the html file from scratch, so I have full control over the content. For others, however, this may not be possible.