Should mpdf render using \Mpdf\HTMLParserMode::HTML_BODY

Created on 10 November 2023, 8 months ago

Problem/Motivation

We face an issue where body styles are not rendered as expected in pdf output.

Here's the render of a Drupal body field using writeHTML with $mode 0.

And the same PDF using $mode \Mpdf\HTMLParserMode::HTML_BODY

While it may not be immediately clear from the images, in the second image, our custom CSS is being applied as expected.

See https://mpdf.github.io/reference/mpdf-functions/writehtml.html

Its not clear to me which is best. Perhaps we should make this configurable?

Steps to reproduce

Create a node with body text using a WYSIWYG editor. Render using mpdf.

Apply patch (forthcoming), comapre render of same node as pdf.

Proposed resolution

Allow changing the $mode call on writeHTML?

Remaining tasks

Research best option

User interface changes

Possible new config

API changes

Possible new config

Data model changes

Possible new config

πŸ’¬ Support request
Status

Closed: works as designed

Version

2.4

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @agentrickard
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)
  • Status changed to Needs review 8 months ago
  • Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 8
    last update 8 months ago
    Waiting for branch to pass
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    And a patch to show the output change.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    I think a settings form to allow site builders to control mPDF's settings.
    Like ✨ DomPDF settings Needs review

  • Status changed to Needs work 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    OK, I'll queue it up and use the patch in the meantime.

  • Status changed to Closed: works as designed 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States agentrickard Georgia (US)

    For the record -- it turns out that image 1 is more correct.

    The problem we were having was with REM units not being defined. https://mpdf.github.io/css-stylesheets/supported-css.html

    Specifically:

    Note: Support for rem was added in mPDF 5.7. Unlike the CSS3 specification, the basic size used for rem in the document is based on the font-size set on the element (rather than the element).

    Our default css specifies font-size in REM on the body, assuming inheritance from HTML.

    So we don't need the patch, and I am going to set this back to a closed support request. We can open another ticket for settings if needed.

Production build 0.69.0 2024