3
Does anyone have any javascript code that exports a graphic div to a file. PDF?
3
Does anyone have any javascript code that exports a graphic div to a file. PDF?
3
after a while researching and cracking my head on this issue, I was able to create a script using Chart js. to create a simple chart and then export this chart to PDF using jsPDF.js, but to be possible to pass the graphic to pdf, I would have to first transform it into an image in PNG format, to accomplish this task I used the plugin html2canvas. here’s the fiddle with the script I used: https://jsfiddle.net/tj9tsyc3/5/
html:
<canvas id="myChart" width="400" height="400"></canvas>
<button type="button">gerar pdf</button>
js:
$('button').on('click', function(){
html2canvas($('#myChart'), {
onrendered: function(canvas) {
var imgData = canvas.toDataURL('image/png');
var pdf = new jsPDF('p', 'mm');
pdf.addImage(imgData, 'PNG', 10, 10);
pdf.save('test.pdf');
}
});
});
Thanks for the reply @Leandro Ruel, it worked perfectly for me, only in Google Chrome, Firefox, IE 10 e 11, IE 9 is giving error, I will try to find a way to get, thanks for the help brother!
arrange! anything just comment here
Browser other questions tagged javascript html pdf
You are not signed in. Login or sign up in order to post.
as far as I know, and with my previous experiences in this, I can only do this with PHP!
– Leandro RR
if you know how to use it see this: http://pdfkit.org/
– Leandro RR
Vlw by the answer @Leandroruel, just a doubt, this pdfkit can create a pdf from a DIV? why the examples he has on this site he creates everything in hand.
– 20comer
opa @sergioBertolazo not tested just searched something for you to take a look, have to read the documentation better, if not meet your need, search for "javascript pdf Generator"
– Leandro RR
It’s expensive I tested no function msm.. @Leandroruel , vlw by help ai guy will have to continue the search to do
– 20comer
friend, which graphic plugin is using in html page?
– Leandro RR
@Leandroruel I’m using Chart.js
– 20comer
Possible duplicate of How to print/export (pdf, xls, printer) the google Chart graphics?
– Guilherme Nascimento
Have you tried using the fpdf ?
– Ivan Ferrer