javascript - Poor Image Quality Inserting Google Charts into a PDF using JSPDF -
i'm trying render pdf view of reporting page contains google charts display data. going converting chart url encoded jpeg. image quality @ stage still once add pdf document using jspdf image quality severely reduced.
here's jsfiddle of current method: http://jsfiddle.net/5c5yx/3/
function getimgdata(chartcontainer) { var chartarea = chartcontainer.getelementsbytagname('svg')[0].parentnode; var svg = chartarea.innerhtml; var chartdoc = chartcontainer.ownerdocument; var canvas = chartdoc.createelement('canvas'); canvas.setattribute('width', chartarea.offsetwidth); canvas.setattribute('height', chartarea.offsetheight); canvas.setattribute( 'style', 'position: absolute; ' + 'top: ' + (-chartarea.offsetheight * 2) + 'px;' + 'left: ' + (-chartarea.offsetwidth * 2) + 'px;'); chartdoc.body.appendchild(canvas); canvg(canvas, svg); var imgdata = canvas.todataurl('image/jpeg'); doc.addimage(imgdata, "jpeg", 10,10); doc.addimage(imgdata, "jpeg", 10,100); canvas.parentnode.removechild(canvas); return imgdata; }
does know of fix or reason it's doing this? or if not; there different way can render pdf containing google chart data (client side preferably) ?
any appreciated!
most visualization api charts support #getimageuri
method, returns uri string can use save .png image file. here docs on printing charts, can follow save them .png image instead: https://developers.google.com/chart/interactive/docs/printing. there should not quality loss importing .png file pdf.
Comments
Post a Comment