javascript - Download PHP, HTML coded page in pdf format. -


i've 'download in pdf' button on page. page contains php , html code.i want download page pdf(not open in browser window). tried 1 code using jspdf coverts div contents pdf format not applying css , same formatting per original page.

js code:

<script type="text/javascript" src="https://parall.ax/parallax/js/jspdf.js"></script> var doc = new jspdf(); var specialelementhandlers = {     '#editor': function (element, renderer) {         return true;  } };  $('#cmd').click(function () {     doc.fromhtml($('#div-bill').html(), 15, 15, {              'width': 170,              'elementhandlers': specialelementhandlers }); doc.save('sample-file.pdf'); }); 

button: <button id="cmd">generate pdf</button>

page div:
<div class="container" id="div-bill"> //page elements here </div>

take @ phantomjs, great job @ rendering web pages pdf documents. webkit based browser , supports css, canvas , svg.

the executable run on windows, linux or osx servers , can script actions in javascript.

so can have "download in pdf" button go php file lauches phantomjs executable, requests file want turn pdf document saves on server's disk. then, read pdf file again using php , send user download prompt, example:

header('content-disposition: attachment; filename=somename.pdf'); header('content-type: application/pdf'); readfile($file); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -