mpdf icon indicating copy to clipboard operation
mpdf copied to clipboard

firefox do not show unchecked checkboxs if useActiveForms set to true

Open Raidri opened this issue 3 years ago • 1 comments

Guidelines

Description of the bug

If I use an active form with checkboxes the checkboxes will not shown in firefox. The file will downloaded to the device and from there I open it in firefox.

Firefox generates the following warnings which come from the html checkbox:

Warning: _collectFieldObjects: "TypeError: this.appearance.dict is undefined".
Warning: _parsedAnnotations: "TypeError: this.appearance.dict is undefined".

If I set the checkbox "checked" it shows up.

It seems to be something with mPDF other PDF files are working.

I attached an example PDF just with checkboxes test-checkbox-pdf.pdf

mPDF version

8.1.4

PHP Version and environment (server type, cli provider etc., enclosing libraries and their respective versions)

PHP 8.1, PDF.js 3.1.22, Firefox (108.0.2 64 bit), Windows 11

Reproducible PHP+CSS+HTML snippet suffering by the error

 $defaultConfig = (new ConfigVariables()
)->getDefaults();
        $fontDirs = $defaultConfig['fontDir'];

        $defaultFontConfig = 
(new FontVariables())->getDefaults();
        $fontData = $defaultFontConfig['fontdata'];

        $mpdf = new Mpdf([
            'mode' => 'UTF-8',
            'fontDir' => array_merge($fontDirs, [
                $distributionPath . 'Resources/Private/App/Assets/Fonts/Roboto',
            ]),
            'fontdata' => $fontData,
            'margin_left' => 10,
            'margin_right' => 10,
            'margin_top' => 35,
            'margin_bottom' => 0,
            'margin_header' => 10,
            'margin_footer' => 0,
            'useActiveForms' => true
        ]);

        $mpdf->SetTitle($seminar->getNumber() . ' ' . $seminar->getTitle());
        $mpdf->SetAuthor('xxx');
        $mpdf->SetDisplayMode('fullpage');

        $cssContent = file_get_contents($distributionPath . 'path/to/styles.css');

        if($cssContent !== false) {
            $mpdf->WriteHTML(
                $cssContent,
                HTMLParserMode::HEADER_CSS
            );
        }
        $mpdf->WriteHTML($html, HTMLParserMode::HTML_BODY);

        $mpdf->Output('Seminar_' . str_replace(' ', '_', $seminar->getTitle()) . '.pdf', 'D');
*, p, h1, h2, h3, h4, h5, h6, a, span, table, tr, td {
    font-family: "Ubuntu", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
}


<form action="#">        
<input type="checkbox" id="agb" name="agb" value="agb" style="width: 100%; font-size: 16px; border-color: rgb(212,19,22);"/>        
<label for="agb">Checkbox 1 - not checked</label><br>        
<input type="checkbox" id="privacy" name="privacy" checked="checked" value="privacy" style="width: 100%; font-size: 16px; border-color: rgb(212,19,22);"/>        
<label for="privacy">Checkbox 2 - checked</label><br>    
</form>

Raidri avatar Jan 16 '23 10:01 Raidri

I'm running into issues with the checkbox in MPDF as well.

In my circumstance, the PDF generated will always check the box if the property "checked" is on the input - regardless of its value.

So,

<input type="checkbox" value="some-input" name="some-input" checked="checked" />

And

<input type="checkbox" value="some-input" name="some-input" checked="" />

Will both render a checkbox with a "checked" state.

If the state needs to be determined by a variable, I found that assigning the entire property to the variable makes it work.

For example, this will not work:

@php 
    $checkedState = "checked";
@endphp

<input type="checkbox" value="some-input" name="some-input" checked="{{ $checkedState }}" />

But this will work:

@php 
    $checkedState = "checked=''";
@endphp

<input type="checkbox" value="some-input" name="some-input" {{ $checkedState }} />

phillipkregg avatar Sep 27 '23 17:09 phillipkregg