exupero / saveSvgAsPng

Save SVGs as PNGs from the browser.
MIT License
1.09k stars 362 forks source link

saveSvgAsPng on specific svg not working #8

Closed PjotrC closed 9 years ago

PjotrC commented 9 years ago

As I first tried your script, it worked pretty well. But now, after I edited my svg file a lot, it did stop working. Unfortunately there are no error messages. Can I post here a link to the problematic svg or my website?

exupero commented 9 years ago

Please do.

On Jul 11, 2014, at 7:15 PM, PjotrC notifications@github.com wrote:

As I first tried your script, it worked pretty well. But now, after I edited my svg file a lot, it did stop working. Unfortunately there are no error messages. Can I post here a link to the problematic svg or my website?

— Reply to this email directly or view it on GitHub.

PjotrC commented 9 years ago

Ok, here is the problematic svg: https://dl.dropboxusercontent.com/u/17823304/Climograph/Climograph%20Davos.svg

And on that site I've got your script: https://dl.dropboxusercontent.com/u/17823304/Climograph/Climograph_test.html

PjotrC commented 9 years ago

Hi exupero, do you see the problem and can you fix it? Or is there something I can do? I removed the patterns and clipPaths from my script, that creates the svg, but still it das not work. These were the things, which I added to, before it stopped working. Another thing, which differs to my previous SVGs is, that I now use paths with cubic Bézier curves. I removed them too. And also the indenting, but still its not working. The only other thing, which I've added are tags - can this be the reason?

exupero commented 9 years ago

The problem is caused by the <br/> tags within the <title> tags. Use the HTML entity &#013; instead.

PjotrC commented 9 years ago

Ok, I am using that entity now - but still it is not working.

exupero commented 9 years ago

Are you using the latest version of the script?

Using the Sandbox on the test page, I was able to render the following PNG from your updated SVG code:

test

PjotrC commented 9 years ago

Have you changed something in the last 24h? Anyway, I just downloaded your script again.

Its odd, I tried my new svg (tags replaced with entity) with your index.html demo page and it worked. - But it does not on my page. But it works with my old svg. Please try yourself: https://dl.dropboxusercontent.com/u/17823304/Climograph/Climograph_old.html (creates the old svg) https://dl.dropboxusercontent.com/u/17823304/Climograph/Climograph_test.html (creates the new svg)

The code used to call saveSvgAsPng is the same in both versions, the only difference is the svg itself.

Also: After clicking the "save as png file" link, the page seems to be reloaded. You can see this, by changing a value in the table before clicking the link. Afterwards the value is changed back to its initial value (under Chrom - Firefox does remember the user inputs).

exupero commented 9 years ago

Your code is saving the contents of the first child of the #svgContainer element, which in your new code is an HTML comment. The old SVG lacks the comment and therefore saves fine.

The page reload is due to the link and isn't related to this library. You can change the href value to # to prevent reloading.

PjotrC commented 9 years ago

Arg... I never thought that comments are added to the DOM structure. Thanks a lot for pointing all this out!

exupero commented 9 years ago

I wouldn't have guessed it either. Glad it's working for you.