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
Capture SVG #95
Comments
No, it does not. It isn't a fault in the library, but a bug in most browsers (latest stable Firefox, version 12, has this issue fixed and is the only one where it works as expected afaik). The problem is that any SVG image taints the canvas, making it unreadable. By default, html2canvas ignores content which taints the image, as we want to keep the canvas readable (i.e. for example if you want to use If however, you don't care that SVG images taint the canvas, then you can set the option I'd also like to point out, if SVG rendering would work correctly cross browser, this library would become almost obsolete, as SVG's can be used to render HTML. I've committed already some code which accelerates the canvas rendering significantly on browsers where SVG rendering works (i.e. FF12), as well as allowing support for all CSS properties the browser supports. For information have a look at https://github.com/niklasvh/html2canvas/blob/master/src/Parse.js#L1227 |
Hello, setTimeout(function() {
It's render SVG successfully in example images.html. But in case the SVG is more complicated it doesn't render correctly in cross browser. For example: I would like to capture the chart (http://www.highcharts.com/demo/), in Chrome: it just capture the x axis and y axis of chart when chart is rendered as inline SVG, in case chart render as img with source from extenal svg file, it doesn't capture anything. Do you have any idea to solve this issue? |
Using as image should work for FF/Chrome. What you could try is whether a simple canvas render using drawImage works with the SVG. |
+1 for this. I have the same use case as babyhero, I need to grab a screenshot of highcharts SVG graphs for a reporting tool. It might be possible to grab all the highcharts SVGs individually, but it's rendered within a view with other information that we would like to have "Save to Screenshot" capability for. |
@babyhero184 I got around this limitation in html2canvas by using canvg (http://code.google.com/p/canvg/) to convert highcharts SVG's to PNG's on the fly, hiding the SVG elements and showing the PNG. Then I took a screenshot on the fly with html2canvas and then hid the PNG and showed the highcharts SVG again. It's a roundabout process (SVG -> canvas -> PNG -> canvas -> PNG) but it works for my needs. |
@joeyrobert I am also facing the same issue with highcharts and html2canvas. It will be a great help if you can share gist of your code. |
@joeyrobert @Jagdeep1 another option is using Fabric.js to render SVG on canvas, then retrieve its image. |
+1 |
2 similar comments
+1 |
+1 |
any solution for this issue ? |
@majuansari SVG to Canvas and Canvas to image works in firefox, but in Chrome there is a security lock. |
I was using jQuery to capture chart elements, and discovered the Highcharts SVG wasn't properly parsed when did so. If anyone's passing a jQuery selector of a chart, it may not contain the SVG. |
@mbritton try http://code.google.com/p/canvg/ (foreignObject not work) |
Yes, that was my solution. |
I solved this issue by replacing svg elements with canvg-generated canvas elements while capturing.
|
Just a quick note:
|
@steren: While this works great in Chrome, is there a workaround for Firefox, which produces a NS_ERROR_NOT_AVAILABLE on the line context.drawImage(image, 0, 0) - apparently a know bug - or IE 11 where a SecurityError appears on canvas.toDataURL() despite the image being on the same domain? Haven't been able to get it running in other browsers besides Chrome... |
@gifarangw your code works fine with highcharts. Thanks for your wonderful code. 👍 Only thing I removed was the canvas.toBlob part. |
@steren thanks for your solution, it works well (tested on latest chrome and firefox), and it doesn't need an additional library which is good. I made a few changes and combined with the code from @gifarangw and I obtained:
|
Hi all just to say that the @remiremi solution worked great for me! I have a page with lots of graphs created with HighStocks in svg and this solution worked great! Well done guys! |
@guypaskar your svg could need to be curated further. You can add I gave a quick try to an amcharts svg and I had to add the properties |
I have found a simple fix. Make sure your svg image has a width and height. There are not enough arguments otherwise because an svg cant be measured like a image can. |
Can someone on this issue recap? Is the original issue resolved? It seems that certain browser issues that may have caused the majority of problems mentioned here have been fixed since 2012. According to some comments here, the use of other libraries such as canvg is also no longer needed? For remaining issues, would they be covered by #197 and/or #267? Can this one be closed? |
It's still an issue with at least some browsers |
I tried this using angular but end up with a tainted canvas. I guess I need the raw SVG?
|
@remiremi i used your code but result is same, svg is missing.. |
@remiremi ... what is the plugin name which i have attache when um using this script |
Basically, setting an explicit width/height on the SVG just before calling html2canvas fixes most cases for me.. |
Still having issues rendering multi-line span's and div's though |
Hi guys, then enjoy it. |
Does anyone have an idea of how I would call An example would be great! |
+1 still an issue for capturing SVG element screenshot in firefox. |
|
Hey, I was able to resolve this issue using this solution (without jQuery): |
let targetElem = document.getElementById('body');
I am doing this, but I a, getting only blank image in IE11. But, I can see the canvas on webpage. Can anyone please help me what I am doing wrong here? |
Hello. I have a problem render svg when this have Sample svg
Sample in jsfiddle http://jsfiddle.net/maestro888/fmjywksq/ |
This is true but not for IE11, unfortunately... |
Glad you got it sorted out.
Just checked your JS Fiddle and it's displaying the image.
Regards,
Bernard T. A. Baker
…On Wed, Mar 27, 2019 at 4:34 PM Alessandro Candini ***@***.***> wrote:
I have found a simple fix.
Make sure your svg image has a width and height.
There are not enough arguments otherwise because an svg cant be measured
like a image can.
This is true but not for IE11, unfortunately...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#95 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AM7ZzLPsl0WJS7gGI9npSsRxR33FCnN9ks5va52bgaJpZM4AD-Sb>
.
|
I've found a solution with canvg, reported here on stack overflow: it works perfectly on IE11 ! My re-elaborated snippet, removing jQuery dependency:
|
Great
…On Thu, 28 Mar 2019, 08:49 Alessandro Candini, ***@***.***> wrote:
I've found a solution with canvg <https://github.com/canvg/canvg>,
reported here on stack overflow
<https://stackoverflow.com/questions/34042440/using-html2canvas-to-render-a-highcharts-chart-to-pdf-doesnt-work-on-ie-and-fir>:
it works perfectly on IE11 !
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#95 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AM7ZzKNy1GOgQU9TVv7PGCi4fJvYSxDVks5vbIIOgaJpZM4AD-Sb>
.
|
Hi @niklasvh Nice to see your html2canvas javascript library ,Its a awesome library ,But Still Am facing the same issue for rendering the svg into canvas creation using npm version "1.0.0-alpha.12 |
testpdf (1).pdf |
the same problem,Error finding the svg in the cloned document |
Before using html2canvas i am temporarily setting height and width to the SVGs. This way i am able to capture the svg. var selectedItem = document.querySelector(".chartWrapper"); |
|
The simplest way is to put an SVG tag in the div tag. Don't apply or write any CSS in the SVG tag. Instead, apply all the CSS properties to that div tag. |
Hello,
Does html2canvas support capture SVG, if yes, how to do that? Could you give an example?
The example in tests\images didn't capture SVG.
Please help. Thanks a lot.
The text was updated successfully, but these errors were encountered: