javasvghtml-to-pdfopenhtmltopdf

Svg image is not displayed on PDF file


I'm using 0.0.1-RC14 openhtmltopdf version for generating PDF files from html. I have svg image on my html template. This is a snippet of my code:

PdfRendererBuilder builder = new PdfRendererBuilder();
builder.defaultTextDirection(BaseRendererBuilder.TextDirection.LTR); 
builder.useSVGDrawer(new BatikSVGDrawer()); builder.useMathMLDrawer(new 
MathMLDrawer()); builder.addDOMMutator(LaTeXDOMMutator.INSTANCE); 
builder.useDefaultPageSize(210, 297, BaseRendererBuilder.PageSizeUnits.MM); 
builder.withHtmlContent(html, "");
builder.toStream(os); 
builder.run();

What I'm doing wrong or what I'm missing?


Solution

  • I've fixed the issue after upgrading openhtmltopdf library to the latest version: 0.0.1-RC15 and adding namespace attribute to the svg element: xmlns="http://www.w3.org/2000/svg" :

    <svg xmlns="http://www.w3.org/2000/svg" ...> ... </svg>"

    For detailed information refer to https://github.com/danfickle/openhtmltopdf/wiki/Plugins:-SVG-Images or https://github.com/danfickle/openhtmltopdf/issues/258#issuecomment-410269938