问题描述
我正在尝试使用Angular 5用jsPDF将html转换为pdf
这是我的代码:
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');
}
我正在尝试将pdf的导出方向从右到左
当我尝试此命令时:
I am trying to export the pdf with direction right to left without sucsses
When I try this command:
doc.viewerPreferences({Direction: 'R2L'});
我收到一个错误:类型"jsPdf"上不存在该属性"
顺便说一下,在我的html或CSS中,我尝试放置direction属性,但没有帮助.它仍然从左到右
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');
});
在我的html中:我放置了所有扭曲的div标签...,并带有id ="content"我使用属性dir ="rtl"
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>
别忘了添加此脚本:
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
这篇关于使用jsPDF rtl支持将HTML转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!