3

I am using dompdf in Symfony project to render PDF

$pdfOptions = new Options();
$pdfOptions->set('defaultFont', 'Arial');
$pdfOptions->setIsPhpEnabled(true);
$pdfOptions->setIsRemoteEnabled(true);

$dompdf = new Dompdf();
$dompdf->setOptions($pdfOptions);
$dompdf->loadHtml($html);
$dompdf->render();
$dompdf->stream("mypdf.pdf");

Same image is showing on webpage but not in pdf. What am I missing?

1
  • 1
    This kind of error often happen when the route to your image is fine in your webpage but not in your pdf, try modifying the route to an absolute url in your pdf and see what happen Commented Mar 29, 2021 at 9:20

1 Answer 1

2

This worked for me

    $options = new Options();
    $options->setIsRemoteEnabled(true);
    $pdfInvoice = new Dompdf($options);
    $body = $this->renderView('App/Payments/invoice.html.twig');

    $pdfInvoice->loadHtml($body);
    $pdfInvoice->setPaper('A4');
    $pdfInvoice->render();
    $pdfInvoice->stream();

    return new Response($pdfInvoice->output());

also set absolute path in your template e.g

<img src="{{ asset('assets/img/logo.png', absolute=true) }}">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.