alafr / SVG-to-PDFKit

Insert SVG into a PDF document created with PDFKit
MIT License
404 stars 115 forks source link

Embedded base64 SVG #136

Open sophistifunk opened 3 years ago

sophistifunk commented 3 years ago

I've got an SVG with an embedded base64 image, which is itself an SVG, which gives me a SVGElemImage: failed to open image "data:image/svg+xml;base64,....." in PDFKit error, I'm guessing because it only supports PNG/JPG. Is there a way to get SVG-to-PDFKit to handle those embedded SVG images instead of trying to get PDFKit to do it?

ajil-paul commented 3 years ago

I am also facing this issue. I have an svg which contain svg elements and also base64 png data. But I am getting only the svg elements in the pdf. That is the png image inside that svg is missing.

msn444 commented 1 year ago

Same here... embedded image/png;base64 works, embedded image/svg+xml;base64 does not.

amjed-ali-k commented 1 year ago

I am also facing this issue. Any fix on this?

matonga commented 3 months ago

I was able to "do it yourself" by replacing all <image/> tags with the content of the refered SVG (or decoding the base64 data in your case) and adding a tag with a transform to the embedded image in the correct position. Actually three tags as I didn't bother calculating a proper transformation matrix (I read embedded image viewBox and <image/>'s x, y, width, height).

SVG-to-PDFKit just handles the <image/> to PDFKit, which doesn't know what to do as it doesn't support SVGs... else we wouldn't be using SVG-to-PDFKit in the first place.