Is there a way to use patterns/textures using addSVG for jsPDF?
I have SVG images generated using the D3 library and they look great. Problem is, addSVG can't use them. I verified that 'regular' SVGs work, I can do basic shapes, strokes, color fills. Is there a way to get the patterns in there?
Ideally, could I extend addSVG to handle dataURIs or perhaps build a CSS with the pattern fills?
If that doesn't work, then maybe a way to parse the SVG XML string to work?
If not either of those, is there a way to create some patterns in 'regular' SVG that I could use instead? Maybe there's an existing library that's simpler than D3? I actually don't need a lot.
edit: It's worth mentioning that Node.js is not an option, and external server resources aren't really an option either. I'm saving an internal server-based SVG to PNG converter to an absolute last fallback. Also typical client-side SVG to PNG conversions are a no-go as well, I have to support IE11 and I can't get around the security error canvas.toDataURL throws (I don't think it's possible).
edit: addSVG is pretty basic and does not support patterns and other fancy bits. I was able to use canvg and addImage as a workaround. Linked article in answer does NOT work for IE11.
Looking at the code for addSVG()
I see it only has extremely basic support for SVGs. It only supports <path>
elements and they have to be at the top level of the SVG. In additon, it doesn't support changing path colours, and it only allows 'c' and 'l' path commands.
So the simple answer to your question is "No". :/
Assuming you don't want to write your own SVG converter (and there are no alternative plugins out there), then you may have to resign yourself to converting the SVG to a bitmap and inserting that.
How to converted SVG Files into PDF in JSPDF using javascript
链接地址: http://www.djcxy.com/p/77336.html上一篇: 贝宝自适应付款费用计算