Html2canvas: Unicode font problem

Created on 10 Jun 2013  ·  21Comments  ·  Source: niklasvh/html2canvas

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.


Bug Unicode

Most helpful comment

I fixed this problem use css 'word-wrap: normal;'

like ,<div style="word-wrap: normal;">Your text here</div>

All 21 comments

@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 receive visibility: hidden; - may have to put the text within span tags and these span tags should be hidden.), when you run the callback onreaded 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 (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">
<canvas id="e" width="600" height="200"></canvas>
<h1 id="a1">தமிழ் ஊடகங்கள் கூடுமிடம்-பொங்குதமிழ்-  World of Tamilconverters</h1>
    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);

bug html2cavans example:

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:


<h1 id="a1"><span style="text-align:justify;">தமிழ் ஊடகங்கள் கூடுமிடம்-பொங்குதமிழ்-  World of Tamilconverters</span></h1>
    var a1 = document.getElementById("a1");

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")))


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( ? getWords(characters) :
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:

@rafiul, অসংখ্য ধন্যবাদ ভাই :)

@rafiul Would you pls share html2canvas.js file. Thanks

@rafiul Would you pls share html2canvas.js file. Previous link not working. Thanks

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(;

with this:
var wordRendering = (!this.options.letterRendering || noLetterSpacing(container)) || !hasUnicode(;

I fixed this problem use css 'word-wrap: normal;'

like ,<div style="word-wrap: normal;">Your text here</div>

Was this page helpful?
0 / 5 - 0 ratings

Related issues

I3rendan picture I3rendan  ·  9Comments

akhil-uddemarri picture akhil-uddemarri  ·  20Comments

jorgecasar picture jorgecasar  ·  6Comments

christopherkade picture christopherkade  ·  25Comments

geekduck picture geekduck  ·  6Comments