Convert Html (SVG) to PDF using Dompdf

Asked

Viewed 216 times

0

With the code below I am able to generate the PDF normally. Only the "figure" I am generating using the SVG is not being shown.

What I have to change for the figure to be included in the PDF?

*** Remembering that I can’t change anything in HTML.

<?php
    ini_set("display_errors", 1);
    error_reporting(E_ALL|E_STRICT);
    require "vendor/autoload.php";

    use Dompdf\Dompdf;
    use Dompdf\Options;

    $options = new Options();
    $options->set('isRemoteEnabled', TRUE);
    $options->set('debugKeepTemp', TRUE);
    $options->set('isHtml5ParserEnabled', true);

    $dompdf = new DOMPDF($options);

    $doc = new DOMDocument();
    libxml_use_internal_errors(true);
    $doc->loadHTMLFile("exemplo.html");
    libxml_clear_errors();

    $html = $doc->saveHTML();
    $dompdf->loadHtml($html);
    $dompdf->render();
    $dompdf->stream("exemplo.pdf", array("Attachment"=>0));

?>

example.php

<!DOCTYPE html>
<html>
    <body>
        <svg width="400" height="110">
            <rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)" />
        </svg>
    </body>
</html>
  • 1

    It is not a related response, but it can be a solution to generate an html image using ocanvas2html.js and then convert it to image in the serivodor with Base64 and save to pdf

  • 1

    I’ll run some tests.... Thank you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.