Html2Canvas问题与波斯语

时间:2017-12-23 10:44:41

标签: javascript jquery html2canvas html-to-pdf

我需要使用html2canvas将HTML转换为图片。问题是它无法正确显示波斯语(波斯语)文本。我想知道是否有人可以帮我解决它!



#target {
  width: 160px;
  height: 50px;
  background: blue;
  color: #fff;
  padding: 10px;
}

button {
  display: block;
  height: 20px;
  margin-top: 10px;
  margin-bottom: 10px;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<script>
  window.takeScreenShot = function() {
    html2canvas(document.getElementById("target"), {
      onrendered: function(canvas) {
        document.body.appendChild(canvas);
      },
      width: 320,
      height: 220
    });
  }
</script>

<div id="target">
   این یک متن فارسی است.
</div>
<button onclick="takeScreenShot()">to image</button>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

text-align: left

上使用#target

#target {
  width: 160px;
  height: 50px;
  background: blue;
  color: #fff;
  padding: 10px;
  text-align: left
}

button {
  display: block;
  height: 20px;
  margin-top: 10px;
  margin-bottom: 10px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<script>
  window.takeScreenShot = function() {
    html2canvas(document.getElementById("target"), {
      onrendered: function(canvas) {
        document.body.appendChild(canvas);
      },
      width: 320,
      height: 220
    });
  }
</script>

<div id="target">
   این یک متن فارسی است.
</div>
<button onclick="takeScreenShot()">to image</button>

编辑:找到相关主题:

Html2canvas image capturing issue with UTF-8 characters

Arabic Encoding with html2canvas