One of my main objectives is to convert a <div>
element that contains multiple inline svg images into a png file. The entire process must be carried out within the client's browser using JavaScript. I have experimented with various techniques:
Utilizing the canvg library and following the guidelines outlined in this post: https://github.com/niklasvh/html2canvas/issues/95#issuecomment-34439223
original svg:
result:
Compacting the css styles into the
<svg>
tag and then invoking canvg, based on the instructions from this post: Convert embedded SVG to PNG in-placeresult: an empty image.
Condensing the css styles into the
<svg>
tag and manually sketching the svg on a canvas, following the steps provided in this post: how to save/ export inline SVG styled with css from browser to image fileresult: an empty image.
Streamlining the css styles into an inline style sheet using this code:
result: an empty image.
employing svg crowbar to manually save the
<div>
element as an .svg file.result:
afterwards, when comparing the computed css of the original svg with the downloaded svg, it was discovered that the downloaded svg contained the correct svg xml but the wrong inline stylesheet (
<style type="text/css">
) For example, the numbers 200, 300 on the extreme right of the graph were rendered as
whereas in my external css, I had:<text x="214" dy=".32em" y="0" style="text-anchor: start;">200</text>
.scatterChart .axisGraphicsContext text { font-size: 8px; fill: #777; }
Nevertheless, the font-size and fill properties were absent from the inline stylesheet of the downloaded svg.