2

I'm trying to convert my div to pdf using jsPDF , this is my div :

<div id="pdffile" style="display:none" class="containerPDF">
     <headerp><h1 id="pdfTitle" style="text-align: center; color:red;"></h1></headerp>
     <navp>
         <div id="pdfImage"></div>
</navp>
     <articlep>
     <h1>Description</h1><p id="pdfDescription"></p>
    </articlep>
     <footerp style="text-align: center;">Copyright © Emoovio</footerp>
 </div>
 <div id="editor"></div>

and this is my jquery code :

$('#cmd').click(function () {
var x =  $(".entry-title").text();

        doc.fromHTML($('#pdffile').html(), 15, 15, {
            'width': 170,
            'elementHandlers': specialElementHandlers
        });
        //doc.autoPrint();
        doc.save('emoovio-'+x+'.pdf');

});

and when I excute this code , i have my pdf , but no center , no color , nothing styling !!!

  • 2
    Duplicate: http://stackoverflow.com/questions/20460035/jspdf-cant-get-any-styling-to-work – R. Chappell Sep 07 '16 at 14:57
  • 1
    i don't wanna set color for every text or center !!! i just wanna convert my html part to pdf , and saving my style !!! understand!! – Oumaya Abdelkhalek Sep 07 '16 at 15:06
  • 1
    A PDF doesn't support style information. If you read the answer on the issue linked it clearly says it does not support CSS. It won't support style tags either. You'll have to add these to your script manually or find another solution. – R. Chappell Sep 07 '16 at 15:46
  • 1
    yes i find another (html2pdf) but i feel like it's very basic :/ :( – Oumaya Abdelkhalek Sep 07 '16 at 16:13

1 Answers1

0

To Retain all the styles, try html2pdf.js. It will first convert your HTML page into Image and then as a pdf. You can refer to their documentation for further details.

Abdul Samad
  • 323
  • 1
  • 2
  • 10