The root of this problem is sitting somewhere inside Dompdf library. However it is triggered by entity_print's default CSS styles and therefore a potential problem for every user of this module.

The CSS code added in #2744511: Fix max-width on img for entity-print.css is causing the problem described here: https://github.com/dompdf/dompdf/issues/1448#issuecomment-327211626

As soon as you work with max-width on images inside tables, you will get render problems. In that case you should:

  1. disable "Enable Default CSS" config setting
  2. if needed, control your max size with image styles only. If you still want/need the max-width selector, you should add it with a more fine grained selector, that never includes tables

I'd suggest keeping this issue open until there's a generic solution within Dompdf and/or point this problem out on the project page and readme.

Update

In the Github thread, I just realized that I was using the wrong default value, when I tried to override the max-width for images inside tables. I haven't tried it yet, but adding this should/could fix the problem:

.page td img {
  max-width: none;
}

Comments

agoradesign created an issue. See original summary.

agoradesign’s picture

Issue summary: View changes
benjy’s picture

Do you want to submit a patch with that CSS, I think we could commit it here and close the issue?

agoradesign’s picture

Yes, that's what I was planning anyway :) It was already too late yesterday and I was out of office today until now. I'll have to test the line within Drupal, if it really works as expected first

agoradesign’s picture

Status: Active » Needs review
StatusFileSize
new247 bytes

This works for me :)

Maybe we should document this somewhere anyway? + the tiny drawback of these new CSS lines is that images do not have a max-width any more within tables. At least for DomPdf users they never really worked anyway, but it could theoretically affect someone using images in tables on one of the other supported render engines (chances are small however)

  • benjy committed 5488a6b on 8.x-2.x
    Issue #2906839 by agoradesign: Images in tables are rendered way too...
benjy’s picture

Status: Needs review » Fixed

We can document this in the handbook if you want but I think this issue is enough. Committed and pushed. Thanks!

agoradesign’s picture

Agree... this should be solid default now + one can find this issue. should be enough documentation :)

benjy’s picture

I think maybe we should remove the .page looking at this again, not all themes will have that class?

agoradesign’s picture

It wouldn't harm of course.

On the one side, having .page would be still ok because the CSS is just a default that doesn't have to be used, as same as the Twig template. As soon as you start customizing the Twig template, I'm pretty sure you begin to do the same with CSS and have a closer look what's in the defaults.

On the other side, it would make sense for any img and any td img scenario -> so let's remove the .page :)

benjy’s picture

StatusFileSize
new237 bytes

Committed the attached patch.

  • benjy committed d8e6824 on 8.x-2.x
    Issue #2906839 by agoradesign, benjy: Images in tables are rendered way...
agoradesign’s picture

This one was bad... you have to either drop ".page" off both selectors (".page img" and ".page td img") or none. This way the table override will never be used

agoradesign’s picture

Status: Fixed » Needs work

I'll put it back to "needs work" then

agoradesign’s picture

a little bit off-topic, but it may interest you: I've added a comment to #2806113-28: No option to print header and footer in pdf describing what you have to take care of when adding header and/or footer to DomPdf via CSS positioning

  • benjy committed 9da4f49 on 8.x-2.x
    Revert "Issue #2906839 by agoradesign, benjy: Images in tables are...
benjy’s picture

Status: Needs work » Fixed

ahhh, right you are. .page is in the entity-print template, I didn't realise that the first time. I've reverted the last commit and kept your original. Thanks!

Yeah I saw your other comments, thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.