1

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?

Omid Nazifi
  • 5,235
  • 8
  • 30
  • 56
Taras Melnyk
  • 3,057
  • 3
  • 38
  • 34

1 Answers1

1

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

Taras Melnyk
  • 3,057
  • 3
  • 38
  • 34
  • I am using version 1.0.4 of openhtmltopdf , and am facing the same problem. svg image is not displaying in the pdf. Any clue ?? – Bhabadyuti Aug 05 '20 at 10:56