使用html2canvas进行阿拉伯语编码
我使用html2canvas
拍摄一个div的图像,内容来自同一页面,相同的域名,但它显示阿拉伯字母断开连接,似乎html2canvas不支持阿拉伯语。
当我在其网页上阅读有关它的可用详细信息时,我没有找到任何有用的信息。
这是我使用的简单代码:
$("#import").click(function(){ // send the contents of the email :) html2canvas(document.body, { onrendered: function(canvas) { document.body.appendChild(canvas); }, letterRendering:true }); });
任何线索?
我想过尝试一些代码操作,它无法工作。 答案是替换:
textList = (!options.letterRendering && /^(left|right|justify|auto)$/.test(textAlign) && noLetterSpacing(getCSS(el, "letterSpacing")))
有:
textList = (!options.letterRendering || /^(left|right|justify|auto)$/.test(textAlign) || noLetterSpacing(getCSS(el, "letterSpacing")))
注意(&&)符号被(||)替换。
您使用的是UTF-8编码吗? 如果你的头脑中没有它绝对不会工作:)希望这会有所帮助。
这是html2canvas
错误。 通过设置内容CSS可以解决此问题:
text-align: left; //or right or justify
在这里阅读更多内容: https : //github.com/niklasvh/html2canvas/issues/226#issuecomment-20232693
我最终找到了答案,需要三个步骤:
-
你需要确保你的html2convas js文件支持从左到右的语言,如波斯语,阿拉伯语或希伯来语,是的,你不能相信有两个不同的文件,可能一个是旧的,另一个已经更新,所以例如如果您使用https://files.codepedia.info/files/uploads/iScripts/html2canvas.js,它对于从右到左的语言将无法正常工作,而https://github.com/niklasvh/html2canvas/releases/download/ 0.4.1 / html2canvas.js运行完美。
-
既然你已经选择了
html2canvas.js
真实版本,你需要使用text-align: right;
对于你的元素。(注意:并非所有元素都需要它,你可能只需要为元素的父元素设置它)。 -
您可能需要在html文件的头部添加
。
现在一切都会像魅力一样! 如果你喜欢它就投票给我。 感谢答案,让我得到最完整的答案。