0

i'm trying to print a div into PDF, but i would include CSS into PDF. I've tried many codes of threads but without solution. JsPDF works but the problem is when i include canvas for css. Can u help me?

<button id="pdf">Click</button>

<div id="elem">
  <span>test</span>
</div>
<div id="editor">
  </span>DON'T PRINT</span>
</div>

<script>
var doc = new jsPDF(); 
var specialElementHandlers = {
    '#editor': function (element, renderer) { 
        return true;
    }
};
$('#pdf').click(function () {
    var source = window.document.getElementById("elem"); 
    doc.fromHTML(source, 15, 15, 
        {
            'elementHandlers': specialElementHandlers 
        });
    doc.output("dataurlnewwindow"); 
});
</script>

this is my code now, but it doesn't include css

BMor
  • 1
  • This link might help you. https://stackoverflow.com/questions/23681325/convert-canvas-to-pdf – Junaid Ali May 27 '19 at 13:47
  • you should use inline-css, check this example: https://github.com/MrRio/jsPDF/blob/master/examples/basic.html – GrafiCode May 27 '19 at 14:20
  • JsPDF permit graphic edit (like doc.textcolor) but in this case i have only one element : doc.fromHTML that contain all the elements, so i can't use this option. – BMor May 27 '19 at 14:54

0 Answers0