Html to pdf using jsPDF rtl support

强颜欢笑 提交于 2019-12-24 02:09:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!