Print.js: Option documentTitle is not working

Created on 15 Aug 2019  路  13Comments  路  Source: crabbly/Print.js

Hello,

seems that documentTitle option isn't working.

This is my jsfiddle: https://jsfiddle.net/xnp5aht2/

Thank you

Most helpful comment

Facing the same issue. Any update to this please?

All 13 comments

Hi, what's your browser?
Your example works for me on Chrome browser.
image

This is my browser version.

Screen Shot 2019-08-23 at 10 30 12

As the documentation said that documentTitle is:

When printing html, image or json, this will be shown as the document title. It will also be the name of the document, if the user tries to save the print job to a pdf file.

And what happen to me is the documentTitle is not working as the name of the document when I tried to save to print.

Ok, now I understand, thanks.

Facing the same issue. Any update to this please?

I traced it down. I think the issue is appending the the iframe to body (in the raw-html case at least). The properties are correctly set and I even override them explicitly again. The only change that worked was setting document.title .... which overrides the title of the calling page though.

I assume a workaround would be capturing the current document, setting it, clearing it.

Hey guys, sorry for the delay on this. I just tried the fiddle using Chrome 78 on a mac and it works. Are you still having issues?

@JandersonConstantino @eljefedelrodeodeljefe @singgihmardianto
Whenever you have a chance, could you please confirm that this issue is still happening with Chrome 78? It's working for me right now.
Thank you.

@JandersonConstantino @eljefedelrodeodeljefe @singgihmardianto
Whenever you have a chance, could you please confirm that this issue is still happening with Chrome 78? It's working for me right now.
Thank you.

The issue is still happening. The jsfiddle shared in the question - when opened in chrome 78 shows the original window title.
image

Thank you @amrita-syn, same here with me still not working. But if you guys need quick solution, you can use @eljefedelrodeodeljefe solution, it works for me.

It seems the issue still there. documentTitle isn't working.

If it helps, I ended up with the following - using the onPrintDialogClose. Partial satisfaction; when you focus back on the browser window/tab, you have your title back.

function printToPdf(content, filename) {
document.getElementsByTagName('body')[0].append(content);
const div = document.getElementById('pdf-content');
document.title = filename.trim().replaceAll(' ', '-');
print({ printable: 'pdf-content',
type: 'html',
documentTitle: filename,
onPrintDialogClose: () => document.title = 'Original Title'
});
div.remove();
}

image

After try different things, i cannot change the DocumentTitle for a download.
What am I doing wrong?
image
image

Hey guys, the purpose of the documentTitle is to customize the browser injected title or header into the print result. So far, this seems to be working as expected.

Here is the fiddle updated with a custom title:
https://jsfiddle.net/crabbly/zvo7fsc4/

And below is the screen shot of the print preview:
printjs-documentTitle

If the user user's browser offers an option to save the print job as a PDF, that's a different feature. We will have to tweak the library to support that. Even though is a bit outside of the library scope, which focus on printing, not PDF generation or downloads. I hope we can get this done. PRs are welcomed! :)

I'll close this issue since we already have another thread focusing on this: #487

Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

raymond8080 picture raymond8080  路  4Comments

PabloSzx picture PabloSzx  路  5Comments

r3wt picture r3wt  路  8Comments

DouglasOGarrido picture DouglasOGarrido  路  3Comments

JahsonKim picture JahsonKim  路  5Comments