Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html2Canvas problems with thai language

Run this code and then 'save' you will difference of image. Any solution to solved this problem?

Example of code

$(document).on("click", "#save", function() {
  html2canvas(
    $("body"), {
      onrendered: function(canvas) {
        $("#result_here").append(canvas);
        var data = new FormData();
        data.append("data", "the_text_you_want_to_save");

        var xhr = (window.XMLHttpRequest) ? new XMLHttpRequest() : new activeXObject("Microsoft.XMLHTTP");
        xhr.open('post', 'save_file.php', true);
        xhr.send(data);
      }
    }
  );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>

<div id="canvas" style="border:1px solid red; width: 300px; heght:300px; ">
  <p>hello
    <p>
      <p>สวัสดี</p>
</div>

<div id="result_here" stlye="border:1px solid blue;"></div>

<button id="save">SAVE</button>

this is my result

enter image description here

( first block is html and second block is result of image you will see a diffrence on )

like image 621
lovepong Avatar asked Nov 18 '25 14:11

lovepong


1 Answers

For those having issues with html2canvas, I recommend switching to the modern-screenshot package. It's more lightweight and offers better output quality. Example in this case: https://jsfiddle.net/x1apujzd

$(document).on("click", "#save", function() {
  modernScreenshot.domToCanvas($("body")[0]).then(function(canvas) {
    $("#result_here").append(canvas);
  })
});
like image 166
khangnd Avatar answered Nov 20 '25 03:11

khangnd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!