javascript - HTML to PDF with CSS included -
i'm searching way convert page pdf document using jspdf, cannot convert css styling. it's text , no graphics.
this code i'm using @ moment
var specialelementhandlers = { '#ignorepdf': function (element,renderer) { return true; } }; var doc = new jspdf(); doc.fromhtml($('#page-with-images').get(0), 20, 20, {'width': 500, 'elementhandlers': specialelementhandlers,}); doc.save("test.pdf");
but result not want, because there no styling included. how fix problem?
try this.
var pdf = new jspdf('p', 'pt', 'a4'); pdf.addhtml($("#content"), function() { var output = pdf.output("datauristring"); alert(output); //pdf.output("datauri"); //this output pdf in new window });
div { width: 100%; background-color: lightblue; padding: 15px; border: 2px solid black; } p { background-color: limegreen; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script> <body> <div id="content"> <div> <div> <div> <div> <p id="to-pdf">html content...</p> </div> </div> </div> </div> </div> </body>
Comments
Post a Comment