New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scripts are not evalutated in header and footer HTML templates for PDFs. #2167
Comments
I also need this feature, because I do not see a normal way to make different headers for different pages. For example on first page (intro page) is one header and on the internal pages is different. <div class="header" id="page1">Intro header</div>
<div class="header">Internal header</div> #page1 {
display: none;
}
#page1:target {
display: block;
}
#page1:target + .header {
display: none;
}
|
Maybe it helps, or is an drive for your own thoughts: #1853 (comment) |
I also met this problem,but I dont know how to slove this problem.my code doesn't seem to be a bit of a problem; |
I am stuck on this too.. I am trying to replace wkhtmltopdf, which allows scripts in the header/footer. They also have If, when the header/footer was rendered, there was some information available via javascript that allowed locating elements relative to the boundaries of the page, to serve this same purpose, that would allow the same type of behavior, eg printing the name of a section that started on a previous page in the header or footer of the current page. Thanks to all for your great work. |
I would also appreciate some development concerning these issues. Javascripts in headers and footers or a header footer function was absolutely useful. Also have external css loaded in headers work would be a great reduction of pain ;-) |
I know this question,I found a way to solve the problem.The reason is that I have been packaged by others.
…________________________________
From: raffaelmeier <notifications@github.com>
Sent: Tuesday, September 25, 2018 7:38:14 AM
To: GoogleChrome/puppeteer
Cc: zhoupeng; Comment
Subject: Re: [GoogleChrome/puppeteer] Scripts are not evalutated in header and footer HTML templates for PDFs. (#2167)
I would also appreciate some development concerning these issues. Javascripts in headers and footers or a header footer function was absolutely useful. Also have external css loaded in headers work would be a great reduction of pain ;-)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#2167 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/Af9UjMZcd1YK512RK3yEOssT07ngCr8sks5uej_WgaJpZM4SjMI_>.
|
Hi skymon4. please descibe your solution. What do you mean by "The reason is that I have been packaged by others." - i do not understand this sentence. |
@raffaelmeier I also execute JavaScript in the header and footer. Maybe my code will help you. |
this is chromium source code print_header_footer_template_page.html
headerTemplate and footerTemplate content was used innerHTML method to render , so it can't execute JavaScript, but we can use other method to execute javascript, we can use under code:
the result is js modify test color to green. |
@yale8848 I've run your snipplet, but I've got a black 'header test' text and I cannot reproduce your result. I've tested on a Chrome 69.0 in headless mode, in Win10 environment, with Node.js v8.11.3. I've also tested without the My goal is to modify the counter in the Any ideas are welcome. Thank you for your answer. |
@user9179380 I test in url-to-pdf-api project docker container, https://github.com/yale8848/url-to-pdf-api-docker os: Debian GNU/Linux 8 (jessie) I try to modify 'header test' color in js code is ok , but try to get 'pageNumber' value in js code , it get empty. |
@yale8848 Thank you for you answer. I will check the linked docker container. Do you use any specific Chrome flag? The list of flags are available here: How did you try to get access to
If it doesn't work, please also try an external image source. Theoretically, the code modify I've posted a question about the issue on StackOverflow: Thank you for your contribution. |
I hate so many trick hacks!I need the headerrTemplate/ footerTemplate can support function setting. |
yeah,as some reason,this way is some diffcult.but if we do use truth way, we can solve this question |
Something that might be quick to deliver is to allow this resource file to be replaced at run time: Then I would be able to write my own custom setupHeaderFooterTemplate function. I could then do a bit more than replace the pageNumber text, such as adding a conditional class based on the page number. |
I have similar needs but simpler. I want to have a "Back to top" link in footer which can navigate to page 1 when clicked. Tried PS: i place a |
@luckydrq did you find how to manage that ? I have the exact same needs and even if links for table of contents works well, as soon as the link is in the footer, it's ignored. |
Not yet, seems that links not supported in footer. |
I have been trying to do the same (run code in header/footer) but haven't been successful. Ultimately I would like to have number page 1 from the second page. And remove headers from 1st page. |
I've been playing with running an onload script like you had in your comment and thought it might work as your example was producing numbered pages. However it seems this is achieved via the class name rather than the script execution. Simply using the class="pageNumber" prints the page numbers for me.
I would very much like to be able to only show our footer on the last page of the pdf and haven't figured out a good way to make that happen yet unfortunately. |
@buzzie-bee |
@yale8848
Waiting for your reply, thank you. |
try to change |
@yale8848 I tested onerror/onload, but it still doesn't work properly. |
We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days. |
🤷 |
We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days. |
Steps to reproduce
What steps will reproduce the problem?
First, I setup a basic test page like this:
The
headerTemplate
looks like this:What is the expected result?
The docs don't mention whether or not script tags are supported in the header and footer templates. I would expect then that the code above would render a header with a red background and remove the page number node. (The code above was just for testing purposes).
What happens instead?
The script appears not to evaluate. Instead the resulting PDF has no background, and a page number div.
If evaluating scripts in these templates is not supported, might I suggest updating the PDF section of the docs to state as much. Thanks for all the hard work the Puppeteer team has put into this project!
The text was updated successfully, but these errors were encountered: