9

I want to capture my webpage, In order to this I find html2canvas, when I use as shown below ,my UTF-8 (persian) characters get in trouble and this direction destroyed as you see.

HTML:

   <div id="wrapper">
        <span>این کاراکتر ها بهم میریزند</span>
    </div>

JavaScript:

$(document).ready(function() {
    html2canvas($("#wrapper"), {
        onrendered: function (canvas) {
            theCanvas = canvas;

            document.body.appendChild(canvas);

            canvas.toBlob(function (blob) {
                saveAs(blob, "Dashboard.png");
            });
        }
    });     
});

WebPage:

enter image description here

Captured WebPage via html2canvas:

enter image description here

you can see full example here

What is wrong with my implementation?

vahid kargar
  • 800
  • 1
  • 9
  • 23

6 Answers6

6

This is a bug with html2canvas (Arabic Encoding with html2canvas) and can be fixed by setting text-align: left on your wrapper element.

Here's an updated fiddle http://jsfiddle.net/ydeL72m8/1/

Community
  • 1
  • 1
mpallansch
  • 1,174
  • 6
  • 16
2

Set the box css that have trouble to :

text-align: left; //or right or justify

that work for me.

Zahra Badri
  • 1,656
  • 1
  • 17
  • 28
2

Just replace this line to new edited line

return styles.letterSpacing !== 0 ? toCodePoints(value).map(function (i) { return fromCodePoint(i); }) : breakWords(value, styles);

new line instead

return [value];
1

Instead of the sentence in the html2canvas.js file

textList = (!options.letterRendering && /^(left|right|justify|auto)$/.test(textAlign) && noLetterSpacing(getCSS(el, "letterSpacing"))) ? textNode.nodeValue.split(/(\b| )/) : textNode.nodeValue.split("");

use:

textList = (!options.letterRendering && /^(left|right|justify|auto|center)$/.test(textAlign) && noLetterSpacing(getCSS(el, "letterSpacing"))) ? textNode.nodeValue.split(/(\b| )/) : textNode.nodeValue.split("");
Zoe
  • 27,060
  • 21
  • 118
  • 148
1

you must to use last version library html2canvas this reslove your problem;

e sadeghi
  • 43
  • 4
0

Add this styling to the wrapper object:

letter-spacing: normal !important;

source : Arabic font rendering

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 15 '22 at 03:26