Skip to content

printToPdf not working when certain characters are present #52

@TWithers

Description

@TWithers

What were you trying to do?

Pass in a view file to export as a pdf.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Email Export</title>

</head>
<body>
<div class="email-container">
    <div>Displays</div>
    <div style="color:#220022">Doesn't display</div>
</div>
</body>
</html>

What happened?

It will render "Displays". It will not render "Doesn't display" due to the # I am pretty sure.

How to reproduce the bug

System::printToPdf('<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Email Export</title>

</head>
<body>
<div class="email-container">
    <div>Displays</div>
    <div style="color:#220022">Doesn't display</div>
</div>
</body>
</html>');

Debug Output

No errors or logs.

Which operating systems have you seen this occur on?

macOS

Notes

This seems to be fixed by base64 encoding the html snippet before transmitting to the electron api, and then adding base64; inside the loadUrl method:

   public function printToPDF(string $html, ?array $settings = []): string
    {
        return $this->client->post('system/print-to-pdf', [
            'html' => base64_encode($html),
            'settings' => $settings,
        ])->json('result');
    }
yield printWindow.loadURL(`data:text/html;base64;charset=UTF-8,${html}`);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions