I am using TCPDF to convert html into PDF.
$pdf = new TCPDF();
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$html = '<div>Some random html </div>';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('/pdf/output.pdf','F');
It works like a charm.
But I have a case when (Dynamic) html has SVG inline code also. So I need to convert this html which has SVG into PDF. But it does not work. Below is my code.
$pdf = new TCPDF();
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage();
$html = '<div>Some random html <div style="width: 100px;"><svg viewBox="10 0 80 80">
<ellipse cx="240" cy="100" rx="220" ry="30" style="fill:purple" />
<ellipse cx="220" cy="70" rx="190" ry="20" style="fill:lime" />
<ellipse cx="210" cy="45" rx="170" ry="15" style="fill:yellow" />
Sorry, your browser does not support inline SVG.
</svg></div> </div>';
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('/pdf/output.pdf','F');
So in this case the generated PDF has all the html printed in pdf but in place of SVG it says "Sorry, your browser does not support inline SVG".
Is there any possible way to generate PDF from html containing SVG?
Update I found http://www.pdfy.net/ this website can convert html based svg into PDF. Any idea how they are doing it?
EDIT 1:
Okay Now I found that mPDF have supports for inline SVG. And it has really great support for it. But mPDF have it's own problem of very less support for basic css. For Eg. Position absolute, float are not supported very well.
So again I am back with the same problem with additional requirement. A library which supports conversion of html with inline svg to PDF and it also supports all basic CSS.