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
Footer is not displayed anymore with recent Chromiums #290
Comments
We encountered the same here! It was introduced in one of projects on 4 October when we deployed a new release of our software with the latest image (Debian). |
@janwillemvd can you pinpoint the chromium version where it broke? We currently only have |
script to reproduce this https://gist.github.com/maltoe/104d192430a059f3672cb7a8c7a3b1bf (assumes local chrome is affected and chrome 115 is run via docker) another example a bit later: they have definitely also made changes to the "zoom" of footer/header and to the default font |
potential culprits:
|
@janwillemvd We have worked around this in our apps now by not using |
Will check this afternoon and let you know! |
Thanks, @maltoe, will try that! |
Maybe a bit bold, but perhaps it may help: @mstensho - you've recently worked on related code in Chromium (e.g. this commit) -> Do you have any idea what has changed and what we can do to mitigate? Context in the issue description. |
Don't know why the footer would disappear, but the font size change is explained here: https://bugs.chromium.org/p/chromium/issues/detail?id=1509917#c3 |
@mstensho thank you for responding! 💜 Unfortunately just dropping the Do you think it makes sense to file a bug at bugs.chromium.org? Is what we've been doing here even "officially" supported? I've found lots of examples about |
There is code in Chromium that checks whether the headers / footers overlap with the page area box [1], and omit any such headers / footers. In the CSS at chromic_pdf/lib/chromic_pdf/template.ex Lines 245 to 275 in ed525c2
Setting the 'width' and 'height' properties for the page context isn't supported (at least not yet), and it probably wouldn't do what you think, anyway. I would expect the 'size' descriptor to be used instead, i.e. something like this:
Unless this is for a separate "print job" for headers / footers. Then you should probably just remove width / height and set margins to 0. But I don't know this framework, so hard for me to tell. In the test, I don't think width and height are specified, are they? We have guards in Chromium against invalid page area sizes, e.g. if the total size of the margins are larger than the page box [1], which would result in a zero or negative page area. In such cases we fall back to the default page size and margins (ignore CSS completely). If you try to squeeze in a footer taller than the default bottom margin, it will be discarded, since it would overlap with the page area. See above. Are the headers and footers really 40mm? Looks smaller to me. |
This seems to be pretty much what is happening. Can you point me to this code?
Good to know, we've been using these properties and additionally setting
Don't know what a "print job" is in this context. The way this library works currently, in short:
I was assuming that all page dimensions (including width and height) would be taken from the CSS with this setup. But just to repeat, I've since changed this ^^ and my test is now using |
I was able to reproduce the behaviour using puppeteer, if that helps. I'm expecting to see 3 "hello" strings, but get only 2, with the footer one missing. Running Google Chrome 120.0.6099.71. const puppeteer = require('puppeteer');
const html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
@page {
size: 210mm 297mm;
margin-top: 40mm;
margin-bottom: 40mm;
}
#header, #footer { font-size: 12pt; }
p { margin: 0; }
</style>
</head>
<body>
<p>hello</p>
</body>
</html>
`;
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setContent(html);
await page.pdf({
path: 'output.pdf',
displayHeaderFooter: true,
preferCSSPageSize: true,
headerTemplate: html,
footerTemplate: html,
});
await browser.close();
})(); run with: npm init -y
npm install puppeteer
node test.js |
Also @mstensho thanks again for your invaluable help! 💜 much appreciated |
I can confirm that it's broken in our app which uses 117.0.5938.132 (running on Debian 12). |
@janwillemvd ❗ you're right, 117 was broken for us, too. I thought it was the version we used before 119, but in fact that was only for a few days (and PDFs from the period are broken too)... So our last known good version is in fact 115. @mstensho Would you like me to open a bug on bugs.chromium.org? |
A bug report sounds fine. Also, I really meant to point to the code that performs the header / footer overlap testing yesterday, but it looks like I forgot. Sorry. |
Thanks, I'll open that bug report in a second then. The code you've linked I had found before and found it suspicious, but it should only apply to elements with a |
Oh right, it needs to be .text, indeed. |
🎉 I think I've figured this out now. The problem is that we've been prepending the entire CSS snippet above to both the content HTML and the @mstensho This is certainly a behaviour change in Chromium since after 115, but probably a good one. Thanks again for your time. For ChromicPDF, I'm going to simply split this CSS apart and not include any |
Fixes [[#290]](#290) Since Chrome 117 custom footers would not be displayed anymore when configured via `ChromicPDF.Template`. Reason for this was that our stylesheet was prepended to both the content markup as well as the header and footer templates. The `@page` rule contains the page margins which used to be ignored in the header and footer sections, but are not applied and lead to the footer being pushes out of its content box. Fixed by splitting `ChromicPDF.Template.styles/1` into `page_styles/1` and `header_footer_styles/1` and removing the `@page` directive from the header and footer styles. Besides, this patch removes the `zoom` directive from the header and footer templates for Chrome >= v120, as they have removed the default 4/3 scale-up.
Fixes [[#290]](#290) Since Chrome 117 custom footers would not be displayed anymore when configured via `ChromicPDF.Template`. Reason for this was that our stylesheet was prepended to both the content markup as well as the header and footer templates. The `@page` rule contains the page margins which used to be ignored in the header and footer sections, but are not applied and lead to the footer being pushes out of its content box. Fixed by splitting `ChromicPDF.Template.styles/1` into `page_styles/1` and `header_footer_styles/1` and removing the `@page` directive from the header and footer styles. Besides, this patch removes the `zoom` directive from the header and footer templates for Chrome >= v120, as they have removed the default 4/3 scale-up.
Wonderful, @maltoe! Will try it out asap! |
Fixes [[#290]](#290) Since Chrome 117 custom footers would not be displayed anymore when configured via `ChromicPDF.Template`. Reason for this was that our stylesheet was prepended to both the content markup as well as the header and footer templates. The `@page` rule contains the page margins which used to be ignored in the header and footer sections, but are not applied and lead to the footer being pushes out of its content box. Fixed by splitting `ChromicPDF.Template.styles/1` into `page_styles/1` and `header_footer_styles/1` and removing the `@page` directive from the header and footer styles. Besides, this patch removes the `zoom` directive from the header and footer templates for Chrome >= v120, as they have removed the default 4/3 scale-up.
Fixes [[#290]](#290) Since Chrome 117 custom footers would not be displayed anymore when configured via `ChromicPDF.Template`. Reason for this was that our stylesheet was prepended to both the content markup as well as the header and footer templates. The `@page` rule contains the page margins which used to be ignored in the header and footer sections, but are not applied and lead to the footer being pushes out of its content box. Fixed by splitting `ChromicPDF.Template.styles/1` into `page_styles/1` and `header_footer_styles/1` and removing the `@page` directive from the header and footer styles. Besides, this patch removes the `zoom` directive from the header and footer templates for Chrome >= v120, as they have removed the default 4/3 scale-up.
Thank you so much @maltoe, really saving the day here <3 |
Glad you figured it out! I'm not quite sure why page margins were ignored previously, but it certainly makes more sense to honor margins on a general basis. |
Fixes [[#290]](#290) Since Chrome 117 custom footers would not be displayed anymore when configured via `ChromicPDF.Template`. Reason for this was that our stylesheet was prepended to both the content markup as well as the header and footer templates. The `@page` rule contains the page margins which used to be ignored in the header and footer sections, but are not applied and lead to the footer being pushes out of its content box. Fixed by splitting `ChromicPDF.Template.styles/1` into `page_styles/1` and `header_footer_styles/1` and removing the `@page` directive from the header and footer styles. Besides, this patch removes the `zoom` directive from the header and footer templates for Chrome >= v120, as they have removed the default 4/3 scale-up.
Fixes [[#290]](#290) Since Chrome 117 custom footers would not be displayed anymore when configured via `ChromicPDF.Template`. Reason for this was that our stylesheet was prepended to both the content markup as well as the header and footer templates. The `@page` rule contains the page margins which used to be ignored in the header and footer sections, but are not applied and lead to the footer being pushes out of its content box. Fixed by splitting `ChromicPDF.Template.styles/1` into `page_styles/1` and `header_footer_styles/1` and removing the `@page` directive from the header and footer styles. Besides, this patch removes the `zoom` directive from the header and footer templates for Chrome >= v120, as they have removed the default 4/3 scale-up.
Footer templates set via
ChromicPDF.Template
are not displayed anymore with recent Chromiums.ChromicPDF.Template
sets page dimensions and header/footer dimensions via rules in@page { ... }
and setspreferCSSPageSize: true
in theprintToPDF
call. Some time after Chromium 117, footers set viafooterTemplate
have disappeared (margin is there but blank).Analysis so far
printToPDF
options (in inches) fixes itmargin-top
is present in@page
, it breaks againpreferCSSPageSize: false
Minified example of what is broken
See stylesheet for actual code.
Things we've tried
size
vs.width/height
in@page
has no effectzoom
rule from#header, #footer
has no effectmargin-inline: ...
is ok, but specifying top/bottom in the CSS immediately breaks itThe text was updated successfully, but these errors were encountered: