Html2Canvas问题与波斯语

问题描述 投票:2回答:1

我需要使用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>
javascript jquery html2canvas html-to-pdf
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.