Html2canvas: CSS styles broken after export image

Created on 28 Apr 2017  路  17Comments  路  Source: niklasvh/html2canvas

Hi,
I have issue in exporting image. After image is exported using html2canvas, css of the page are missing. As a result, UI distortion is happening after we export to jpg.

I saw workaround in https://github.com/niklasvh/html2canvas/issues/504 which helped to fix the issue. Can someone please suggest if this can be moved as a fix to html2canvas into Git

Needs More Information

Most helpful comment

Why is this closed? I'm still facing this issue in the latest version. Can someone please suggest any fix or workaround they're using?

All 17 comments

I meet the same situation.

1123 is the same like question.

I also faced the same problem. Still searching the solution. Is there any library extensions to avoid css issues?

Well, after researching, I found it is nomal problem dealing with svg text elements font style when using svg as html elements.
A thinkful sulotion is to convert svg text as html text outside of svg tag and position absolute to make text style work.
Another sulotion is to render svg as image in backend side as a image, when rendering load font files.

@tangshuang hey, do you have an example about that to solve the problem?

@Xilver266 it is a large code solution, and impossible to paste my code here.
You can just follow the idea to try by yourself.

The solution is to remove the Unicode condition for CSS in canavas2html.js

@mahadevshindhe Could you please detail your solution?

@tangshuang

I am using html2canvas version 0.5.0-alpha1.
download link https://github.com/niklasvh/html2canvas/releases/download/0.5.0-alpha1/html2canvas.js

Line no 2321 , remove the condition !hasUnicode(container.node.data). I am able to get Unicode text properly.

var textList = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character) {
return window.html2canvas.punycode.ucs2.encode([character]);
});

Is this still an issue with v1.0.0? If so, could you please share an example on jsfiddle.

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

i'm experiencing this issue

Edit: Also confirmed this is an issue on 1.0.0-alpha.9
fiddle: http://jsfiddle.net/patgoins/2d90yop3/

I am also experiencing this issue on 1.0.0-alpha.4

Also, the styles seem to be applied in the image export only when they are applied to the element inline.
When the styles are applied via a class, they are ignored

i'm experiencing this issue too

me too

alpha 12 shows this issue too...

Why is this closed? I'm still facing this issue in the latest version. Can someone please suggest any fix or workaround they're using?

it has been 3 years, and still I didn't find solution from this issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rrutkows picture rrutkows  路  4Comments

anthonymejia picture anthonymejia  路  4Comments

tjchambers32 picture tjchambers32  路  3Comments

kunal886496 picture kunal886496  路  3Comments

Loki180 picture Loki180  路  4Comments