问题
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
回答1:
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>
来源:https://stackoverflow.com/questions/49154335/html-to-pdf-using-jspdf-rtl-support