yWorks / svg2pdf.js

A javascript-only SVG to PDF conversion utility that runs in the browser. Brought to you by yWorks - the diagramming experts
MIT License
655 stars 101 forks source link

foreignObject support #15

Open psamim opened 7 years ago

psamim commented 7 years ago

Hi,

I see that foreignObject SVG tag is not supported, for embedding HTML. Am I right?

Thanks

yGuy commented 7 years ago

This indeed is not supported and "html2pdf" is definitely out of scope for "svg2pdf".

With the help of something like this: http://www.techumber.com/html-to-pdf-conversion-using-javascript/ you can probably get something like this to work. We would welcome a pull-request here.

MrRio has plans to rewrite the JsPDF API to use a canvas API, so combining the "html2canvas" project with this new API should enable a straightforward implementation of this task, too.

nbelyh commented 2 years ago

Are there some news regarding the issue (a few years later)? I would like to be able to export to PDF an SVG containing (both) "foreignObjects" and embedded images, without losing the export quality (i.e. without canvas PNG or JPG conversion) in a browser. Would appreciate any advice.

yGuy commented 2 years ago

No. There aren't any news. Believe me, when we reimplement a browser engine, we will definitely add this in a note somewhere ;-) Right now, we don't have plans to implement our own user agent. This is still definitely out of scope of this project. There was a plugin for Chrome that takes SVG snapshots of a website. That source code might help to implement a rudimentary version of what you need. It definitely does not cover the whole HTML spec but it might work for simple use-cases:

https://chrome.google.com/webstore/detail/svg-screenshot/nfakpcpmhhilkdpphcjgnokknpbpdllg?hl=en