Pandoc is not rendering SVG images when converting from html to docx format
Asked Answered
S

2

7

I amd using pandoc to convert a standalone html (with not external dependency), with all required css and js merged in html itself. HTML has few svg graphs generated via javascript library

The said html file, when opened in browser renders fine, but when converted to docx, svg images are missing from docx file.

command used to convert, looks like

pandoc ./something.html -s -o test1.docx

What I suspect is that it is converting file before javascript could even render those images.

Appreciate help

Singletary answered 17/9, 2018 at 14:16 Comment(3)
AFAIK, word just doesn't support embedded SVGs, so you'd have to convert them to png or something first.Glasswort
Word has supported SVG since ~ Word 2016. The Pandoc conversion, however, doesn't (AFAICT) support this. E.g., I can insert an SVG manually from within Word, but converting from Markdown to DOCX I get a broken image tag. Which is a pain. The pandoc-svg filter (gist.github.com/jeromerobert/3996eca3acd12e4c3d40) may work, but it converts it to a PNG, which doesn't help me much since I need high fidelity images for my usecase.Semela
Just out of curiosity, have you figured this one out? I don't know enough Haskell to be able to update how this works (yet), and I have a ton of SVG images I need to insert into Word docs, and can't really convert to PNG because of the loss of clarity.Semela
B
3

The docx needs a png fallback image, that it uses to show the image.

Pandoc doesn't create those fallback images, but they are aware of the issue. You can track the progress here:

https://github.com/jgm/pandoc/issues/4058

It should be included in the next release.

Bradley answered 12/3, 2020 at 13:45 Comment(0)
M
2

It is now implemented in 2.15

https://github.com/jgm/pandoc/releases/tag/2.15

Molybdenum answered 25/10, 2021 at 12:43 Comment(1)
Note that (in 2023) the Word online viewer does not render the svg. It uses the blurry png fallback. Desktop Word does render the svg.Leighton

© 2022 - 2024 — McMap. All rights reserved.