Html2canvas image capturing issue with UTF-8 characters
Asked Answered
B

8

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?

Babette answered 31/5, 2015 at 8:27 Comment(0)
G
2

Set the box css that have trouble to :

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

that work for me.

Giralda answered 11/4, 2020 at 9:5 Comment(0)
C
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/

Cienfuegos answered 31/5, 2015 at 12:35 Comment(1)
Thanks a lot. i was about to ask the same question on malayalam language. You saved my projectEwing
G
2

Set the box css that have trouble to :

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

that work for me.

Giralda answered 11/4, 2020 at 9:5 Comment(0)
V
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];
Vshaped answered 2/1, 2021 at 15:35 Comment(0)
C
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("");
Carious answered 12/3, 2019 at 20:29 Comment(0)
B
1

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

Bionics answered 12/7, 2020 at 7:28 Comment(0)
F
1

Add this styling to the wrapper object:

letter-spacing: normal !important;

source : Arabic font rendering

Footwall answered 11/8, 2022 at 4:4 Comment(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.Kim
I
0

I faced the same messy Arabic letters with only <h1.. h6> elements, I solved it by using styled p [Paragraph] elements instead. Arabic headers problem

Interlock answered 30/11, 2023 at 10:14 Comment(0)
T
0

I faced the same issue in version 1.4.1 and fixed it by adding

letter-spacing: normal;

to the wrapping element

Thissa answered 24/4, 2024 at 14:48 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.