-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
[BUG] Header and Footer Templates don't work when generating a PDF #14441
Comments
@DaveNatalieTripArc margins are required to add the header and footer content, something like this should work: var pdfOptions = new PagePdfOptions()
{
Margin = new() { Top = "40px", Bottom = "40px" },
DisplayHeaderFooter = true,
HeaderTemplate = "<span style=\"font-size: 5pt;color:#000000;\">HEADER</span>",
FooterTemplate = "<span style=\"font-size: 5pt;color:#000000;\">FOOTER</span>",
PrintBackground = true,
Path = "file.pdf"
}; |
This now works for most urls (including the wikipedia page I used above), but I was still having issues. Upon further inspection, I noticed this in a style tag of the page.
Removing this code allowed the header and footer to be displayed. |
Is it possible, using Playwright, to avoid showing the header and footer on the first page? I tried using default margins, and overriding them with CSS
But doing so will prevent the header and footer from showing on all pages. If I comment out Oddly enough, I can partially accomplish this with the header only. Removing I also tried adding a class to the footer template |
How I can add it center of footer ? |
If it can help anyone, here are my findings about the header and footer template. Some of it is apparently undocumented. I used the following documentation: https://playwright.dev/python/docs/api/class-page#page-pdf
So, I would say, header and footer do work when generating PDF, but the documentation misses out on a lot of stuff and they are not easy to get to work properly. Here is how I went about the problem. I used the python API. Also, I used the Jinja project to template the header and footer templates. For example, something along the lines of:
and the CSS -- defines footer left, center or right elements:
PDF creation:
|
@leducvin This is great info, thanks for posting. I am just left with one question that is preventing me from using Playwright in my project.
|
@DaveNatalieTripArc Unfortunately, I don't know the answer to that question, but I suspect it's not possible in the current state. It seems like it's either with or without for all pages. |
Why was this issue closed?Thank you for your contribution to our project. This issue has been closed due to its limited upvotes and recent activity, and insufficient feedback for us to effectively act upon. Our priority is to focus on bugs that reflect higher user engagement and have actionable feedback, to ensure our bug database stays manageable. Should you feel this closure was in error, please create a new issue and reference this one. We're open to revisiting it given increased support or additional clarity. Your understanding and cooperation are greatly appreciated. |
Context:
Code Snippet
Describe the bug
The header and footer are not visible in the generated document. I've tried including HTML tags in the template, and all kinds of style teqniques, but I have never been able to get the header and footer to display for any webpage.
The text was updated successfully, but these errors were encountered: