ZAJDAN
ZAJDAN

Reputation: 131

SVG in mPDF (PHP library )

In php code I use mPDF library for generating PDF. I am facing a problem with insert svg into PDF The svg file I catch via POST:

   $svg = $_POST['structureSVG'];
   $svg_pdf = str_replace('"', '\'', $svg); //change " to '

proof what is inside:

   var_dump($svg_pdf);
    //shows string which contains: 
<svg>...</svg>

here I can be sure, that the SVG was captured correctly. So I put the SVG:

$html = " <div> $svg_pdf </div> ";
$mpdf -> WriteHTML($html);
$mpdf -> Output('pdf/test_svg.pdf', 'I');

but unfortunately the SVG picture is not rendered in PDF

thank You for any help

Upvotes: 5

Views: 14313

Answers (1)

Petr Hub&#237;k
Petr Hub&#237;k

Reputation: 191

You need to handle the SVG as regular <img> tag. From my point of view, it'd be easiest to save the file to the temp directory and then let it load with mPDF:

<img src="path/to/the/temp/file.svg">

Unfortunately, you can not use data uri for SVG images (at least in version 5.7.4).

Upvotes: 4

Related Questions