使用 jsPDF rtl 支持将 Html 转换为 pdf [英] Html to pdf using jsPDF rtl support
问题描述
我正在尝试使用 angular 5 使用 jsPDF 将 html 转换为 pdf
这是我的代码:
import * as jsPDF from "jspdf";...htmlToPdf(){var doc=new jsPDF();var specialElementHandlers = {'#content' : function(element,render) {return true;}};doc.fromHTML(document.getElementById('content'), 20,20,{'宽度':500,'elementHandlers':specialElementHandlers,});doc.save('Reports.pdf');}
我正在尝试从右到左的方向导出 pdf 没有成功
当我尝试这个命令时:
doc.viewerPreferences({Direction: 'R2L'});
我收到一个错误:'属性在类型jsPdf"上不存在'
顺便说一下,在我的 html 或 css 中,我尝试放置方向属性,但没有帮助.还是从左到右
在我的组件中我使用了这个函数:
htmlToPdf(){const elementToPrint = document.getElementById('content');const pdf = 新的 jsPDF();pdf.addHTML(elementToPrint, () => {pdf.save('report.pdf');});
在我的 html 中:我把 div 标签全部扭曲......并且带有 id="content"我使用属性 dir="rtl"
...
不要忘记添加这个脚本:
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
I am trying to convert html to pdf with jsPDF using angular 5
Here is my code:
import * as jsPDF from "jspdf";
.
.
.
htmlToPdf(){
var doc=new jsPDF();
var specialElementHandlers = {
'#content' : function(element,render) {return true;}
};
doc.fromHTML(document.getElementById('content'), 20,20,{
'width':500,
'elementHandlers': specialElementHandlers,
});
doc.save('Reports.pdf');
}
I am trying to export the pdf with direction right to left without sucsses
When I try this command:
doc.viewerPreferences({Direction: 'R2L'});
I got an error: 'property does not exist on type "jsPdf" '
By the way in my html or css I tried to put direction attribute but it does not help. It still left to right
In my component I used this function:
htmlToPdf(){
const elementToPrint = document.getElementById('content');
const pdf = new jsPDF();
pdf.addHTML(elementToPrint, () => {
pdf.save('report.pdf');
});
In my html: I put div tag that warp all... and with id="content" i use the attribute dir="rtl"
<div id="content" dir="rtl">
.
.
.
</div>
Don't forget to add this script:
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
这篇关于使用 jsPDF rtl 支持将 Html 转换为 pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!