Hi All,
In my HTML code some UNICODE content exists. If I try to convert from HTML to Canvas, it is generating junk characters. I used tamil UNICODE data.
find the screen shot of my HTML content.
Can you please give any solution. I needs this urgent.
Please respond anyone ASAP.
Thanks&Regards,
Ramesh
@ramesh-git It seems to be really a _BUG html2canvas_ even.
I did a test with "fillText" and had no problems, but when using the "html2canvas". There were some characters were replaced by a strange drawing (a circle to be exact).
The only quick fix that you can specify:
you must create canvas of their texts before running html2canvas and puts them overlapping to the original texts (using
position: absolute;
and the original texts should receivevisibility: hidden;
- may have to put the text within span tags and these span tags should be hidden.), when you run the callbackonreaded
you remove (or hide) the canvas (texts).Note: Remember, whenever you make a question that will use code "client-side", add an example online using sites like http://html2canvas.hertzen.com/ (I've added an example to your question, so it will be easier for developers.)
fillText example:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
body{
background:#ccc;
}
canvas{
background:#fff;
}
</style>
<canvas id="e" width="600" height="200"></canvas>
<h1 id="a1">āŽ¤āŽŽāŽŋāŽ´ā¯ āŽāŽāŽāŽā¯āŽāŽŗā¯ āŽā¯āŽā¯āŽŽāŽŋāŽāŽŽā¯-āŽĒā¯āŽžāŽā¯āŽā¯āŽ¤āŽŽāŽŋāŽ´ā¯- World of Tamilconverters</h1>
<script>
var canvas = document.getElementById("e");
var a1 = document.getElementById("a1");
var context = canvas.getContext("2d");
context.fillStyle = "#000";
context.font = "bold 16px Arial";
context.fillText(a1.innerHTML, 10, 20);
</script>
bug html2cavans example:
http://jsfiddle.net/6KvLk/
I discovered the reason for the failure:
In function renderText(el, textNode, stack)
, to be more specific in line: 1186:
we have this: : textNode.nodeValue.split("");
(this split is for normal characters)
For the "unicode text" you need to add the property text-align
(css) with one of the following valuesââ: left
, right
, and justify
.
Note: and do not use the property
letter-spacing
:
Try:
<h1 id="a1"><span style="text-align:justify;">āŽ¤āŽŽāŽŋāŽ´ā¯ āŽāŽāŽāŽā¯āŽāŽŗā¯ āŽā¯āŽā¯āŽŽāŽŋāŽāŽŽā¯-āŽĒā¯āŽžāŽā¯āŽā¯āŽ¤āŽŽāŽŋāŽ´ā¯- World of Tamilconverters</span></h1>
<script>
var a1 = document.getElementById("a1");
html2canvas(a1,{
"onrendered":function(canvas){
document.body.appendChild(canvas);
}
});
</script>
very much thanks to brcontainer.
When I saw his/shes post, i thought of trying some code manipulation & It unblivably worked. The answer is to replace :
textList = (!options.letterRendering && /^(left|right|justify|auto)$/.test(textAlign) && noLetterSpacing(getCSS(el, "letterSpacing")))
with:
textList = (!options.letterRendering || /^(left|right|justify|auto)$/.test(textAlign) || noLetterSpacing(getCSS(el, "letterSpacing")))
notice at (&&) sign which is replaced by (||).
@BENYAZ For your issue (#289), wouldn't a cleaner fix be to just change left|right|justify|auto
to left|right|center|justify|auto
? I suspect your workaround might break or significantly slow rendering for some use cases.
@BENYAZ it works for me (Pashto & Urdu) languages. Thank you
@BENYAZ it also works for me in persian language
@BENYAZ yea, I also confirm it working in Arabic and Persian.
It working in Dari
var textList = (!this.options.letterRendering || noLetterSpacing(container)) || !hasUnicode(container.node.data) ? getWords(characters) : characters.map(function(character)
I changed && to ||
@BENYAZ It's working in Bangla language. Thanks
@rafiul āĻāĻžāĻ āĻāĻĒāĻ¨āĻŋ āĻā§āĻŽāĻ¨ā§ āĻāĻ āĻ¸āĻŽāĻ¸ā§āĻ¯āĻž āĻ¸āĻ˛āĻ āĻāĻ°āĻ˛ā§āĻ¨ āĻāĻāĻā§ āĻā§āĻ˛ā§ āĻŦāĻ˛ā§āĻŦā§āĻ¨? āĻ āĻ°ā§āĻĨāĻžā§ āĻā§āĻ¨ āĻĢāĻžāĻāĻ˛ā§ āĻāĻŋā§ā§ āĻ˛āĻžāĻāĻ¨āĻā§āĻ˛ā§ āĻŦāĻĻāĻ˛āĻžāĻ¤ā§ āĻšāĻŦā§? html2canvas.js āĻāĻ° āĻŦā§āĻļ āĻā§ā§āĻāĻāĻž āĻāĻžāĻ°ā§āĻļāĻ¨ā§ āĻā§āĻ°āĻžāĻ āĻāĻ°ā§āĻāĻŋ, āĻā§āĻ¨ā§ āĻāĻžā§āĻāĻžāĻ¤ā§āĻ āĻ°āĻŋāĻĒā§āĻ˛ā§āĻ¸ āĻšāĻā§āĻž (āĻ¯ā§āĻā§āĻ˛ā§ āĻ°āĻŋāĻĒā§āĻ˛ā§āĻ¸ āĻāĻ°ā§ āĻ¨āĻ¤ā§āĻ¨ āĻ˛āĻžāĻāĻ¨ āĻŦāĻ¸āĻžāĻŦā§) āĻ˛āĻžāĻāĻ¨āĻā§āĻ˛ā§ āĻĒā§āĻ˛āĻžāĻŽ āĻ¨āĻžāĨ¤
@IbnAhmed html2canvas.js āĻĢāĻžāĻāĻ˛ā§ āĻ¨āĻŋāĻā§āĻ° āĻ˛āĻžāĻāĻ¨āĻāĻž āĻā§āĻā§ āĻŦā§āĻ° āĻāĻ°ā§āĻ¨
textList = (!options.letterRendering && /^(left|right|justify|auto)$/.test(textAlign) && noLetterSpacing(getCSS(el, "letterSpacing")))
Replace with:
textList = (!options.letterRendering || /^(left|right|justify|auto)$/.test(textAlign) || noLetterSpacing(getCSS(el, "letterSpacing")))
** && āĻāĻ° āĻāĻžā§āĻāĻžā§ āĨ¤āĨ¤ āĻšāĻŦā§āĨ¤
@rafiul, āĻāĻžāĻ āĻāĻĒāĻ¨āĻŋ āĻāĻŽāĻžāĻ° āĻāĻĨāĻž āĻā§āĻ˛ā§ āĻŦā§āĻāĻ¤ā§ āĻĒāĻžāĻ°ā§āĻ¨āĻ¨āĻŋāĨ¤ āĻāĻŽāĻžāĻ° āĻāĻžāĻā§ html2canvas.js āĻ¨āĻžāĻŽā§ āĻ¯ā§ āĻĢāĻžāĻāĻ˛āĻāĻž āĻāĻā§ āĻ¸ā§āĻāĻžāĻ¤ā§ āĻāĻ āĻ˛āĻžāĻāĻ¨āĻāĻžāĻ āĻ¨ā§āĻ " textList = (!options.letterRendering && /^(left|right|justify|auto)$/.test(textAlign) && noLetterSpacing(getCSS(el, "letterSpacing")))"
āĻāĻĒāĻ¨āĻžāĻ° html2canvas.js āĻĢāĻžāĻāĻ˛āĻāĻž āĻāĻˇā§āĻ āĻāĻ°ā§ āĻāĻĒāĻ˛ā§āĻĄ āĻāĻ°āĻŦā§āĻ¨?
@IbnAhmed Download from here: http://3rwebtech.com/html2canvas.js
@rafiul, āĻ āĻ¸āĻāĻā§āĻ¯ āĻ§āĻ¨ā§āĻ¯āĻŦāĻžāĻĻ āĻāĻžāĻ :)
@rafiul Would you pls share html2canvas.js file. Thanks
@rafiul Would you pls share html2canvas.js file. Previous link not working. Thanks
@hiroksarker download it from here, https://www.dropbox.com/s/20hk1qcbm0d7far/html2canvas.js?dl=0
same problem with me .... any help please ?
setting css : letter-spacing: 0;
options = {letterRendering: true}
in new version should change this line:
var wordRendering = (!this.options.letterRendering || noLetterSpacing(container)) && !hasUnicode(container.node.data);
with this:
var wordRendering = (!this.options.letterRendering || noLetterSpacing(container)) || !hasUnicode(container.node.data);
I fixed this problem use css 'word-wrap:
normal;'
like ,<div
style="word-wrap: normal;">Your text here</div>
Most helpful comment
I fixed this problem use css
'word-wrap:
normal;'like
,<div
style="word-wrap: normal;">Your texthere</div>