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

Cannot draw SVG on the html canvas #1543

Open
kikifang opened this issue May 26, 2018 · 11 comments
Open

Cannot draw SVG on the html canvas #1543

kikifang opened this issue May 26, 2018 · 11 comments

Comments

@kikifang
Copy link

kikifang commented May 26, 2018

Description

I'm trying to draw a SVG image (please see code.html.txt) on the html canvas, using html2canvas v1.0.0-alpha.12. But, not successful.

The html2canvas might not support all kinds of SVG elements in Chrome browser, I guess. I'm not sure that this is a Chrome security restriction, or a html2canvas fault. This has blocked my work.

Oops... :(

Specifications:

  1. html2canvas version tested with: 1.0.0-alpha.12
  2. Mac
  • Browser & version: Chrome Version 66.0.3359.181
  • Operating system: Mac OS Version 10.13.4.
  1. Windows
  • Browser & version: Chrome Version 62.0.3202.94
  • Operating system: Windows latest version
@fuggfuggfugg
Copy link

Pretty sure SVG is not supported, I had to use https://github.com/canvg/canvg to first convert all SVG to canvas and then print it out.

You can also take a look at this example. http://rahulgaba.com/front-end/2016/07/14/generating-pdf-using-jspdf-and-html2canvas.html

@LanderBeeuwsaert
Copy link

Hmmm, I'm using html2canvas together with svg's. I don't have any problems with it.

@kikifang
Copy link
Author

@LanderBeeuwsaert

Could you copy me your SVG file? As my issue described, it works in Safari browser, but doesn't work in Chrome. Thank you.

@mockey-jockey
Copy link

@LanderBeeuwsaert
Could you please put it on jsfiddle woking example with the combination of html2canvas and svg

@LanderBeeuwsaert
Copy link

@mockey-jockey ,

Hey, not too familiar with jsfiddle, so if you prepare the dependencies for me in jsfiddle and then send me the link so I can complete (only have to replace the svg with my svg) I'd be happy to.

@motodimago
Copy link

I can not capture this.

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">...</svg>

But I can capture this svg.

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="48" height="48">...</svg>

I just add width and height.

@elramus
Copy link

elramus commented Jul 20, 2018

Experiencing similar issues here. Inline SVGs not rendered into canvas.

In Safari it seems to work fine, but only if all properties are included inline within the SVG. So if you're adding your dimensions, fill, stroke, etc. through CSS stylesheet, they won't show up and it won't work.

In Chrome and in Firefox, I cannot get it to render inline SVGs at all. Strange.

Update: when enabling ForeignObjectRendering as an option, Chrome now renders the SVG but they're in the wrong place, and for some reason this also had the affect of forcing text into a different font. In Firefox, enabling this throws this error:

screen shot 2018-07-20 at 3 21 43 pm

@richardhovdsveen
Copy link

My svg is rendering, but get a bit offset (about 150 px)

@okpalan
Copy link

okpalan commented Feb 16, 2022

Looking through this issue ,I encountered a solution online.it is at https://jsfiddle.net/oz3tjnk7. Note ,it does not contain the use of this library ,but a vanillas implementation https://jsfiddle.net/oz3tjnk7/

@george-wb
Copy link

@richardhovdsveen any chance you solved the SVG offset issue? my SVGs are also rendered by about that many pixels as well.

@richardhovdsveen
Copy link

@george-wb Ended up with calculating the difference when it appeared. At least thats what I remember :)

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

No branches or pull requests

9 participants