Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

foreignObject and xhtml #37

Closed
eKoopmans opened this issue Jun 8, 2017 · 6 comments
Closed

foreignObject and xhtml #37

eKoopmans opened this issue Jun 8, 2017 · 6 comments
Labels

Comments

@eKoopmans
Copy link

Hi there, nice-looking project! I'm new to SVG. I've been investigating this approach of rendering HTML inside an SVG element, using:

<foreignObject>
  <div xmlns="http://www.w3.org/1999/xhtml">
  </div>
</foreignObject>

From what I can tell, you don't support <foreignObject>, is that right? It seems like it would be impossible to support. In any case, it might be worth adding to your "Unsupported" list on the readme!

@alafr
Copy link
Owner

alafr commented Jun 8, 2017

Yes it's not supported and out of the scope of this repository (it's not SVG). However if you know any good html -> PDF converter I could add a way to use it with a callback every time a foreignObject/xhtml is encountered. In the meantime I add it to the unsupported list.

It is possible to save an image from the canvas and insert the image in PDFKit (but it will pixelise the text and increase the size of the PDF file).

@eKoopmans
Copy link
Author

Great, thanks. I've been working on an html2pdf tool, but it wouldn't be able to plug-and-play with SVG-to-PDFKit without modifications. It uses html2canvas to render the HTML to an image - you could use that, but it has its problems (one of the reasons I'm looking for alternatives).

@alafr alafr added the wontfix label Jun 8, 2017
@rebeccaswebsite
Copy link

rebeccaswebsite commented Oct 30, 2019

Hi there, do you know of a way that I can convert foreignObject elements inside an svg into a format which is compatible with this library, like a text tag? I'm currently using this library to export some charts into a pdf and I'm losing the labels in the process, as they're in a foreignObject.

@rebeccaswebsite
Copy link

update for anyone finding this: I've managed to change the foreignObject elements into text elements using JavaScript so the labels are displaying properly now

@alafr
Copy link
Owner

alafr commented Oct 30, 2019

Hi, i don't know any solution other than converting them to images with canvas (as said above it could be done with a callback function called when a foreignObject is detected).
If the foreignObjects are very simple and have always the same syntax it might be possible to use a 'replace' with some regex to convert them before using svg-to-pdfkit.

@idrisadetunmbi
Copy link

update for anyone finding this: I've managed to change the foreignObject elements into text elements using JavaScript so the labels are displaying properly now

Hi @rebeccaswebsite, please what approach did you take in solving this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants