Jspdf: How to Rendered SVG FIles into PDF in JSPDF using javascript

Created on 9 Jan 2015  路  2Comments  路  Source: MrRio/jsPDF

I struggled to rendered SVG Files into PDF using JSPDF.Here i Worked in following code.


var doc = new jsPDF();
var test = $.get('amChart.svg', function(svgText){
// console.log(svgText);
var svgAsText = new XMLSerializer().serializeToString(svgText.documentElement);
console.log(svgAsText);
doc.addSVG(svgAsText, 20, 20, doc.internal.pageSize.width - 20*2)
//console.log(doc);
// Save the PDF
doc.output('datauri');
});

And I also i working in SVGELEMENTOPDF function from this GITHUB URL and I worked in this code also.

// I recommend to keep the svg visible as a preview
var svg = $('#container > svg').get(0);
// you should set the format dynamically, write [width, height] instead of 'a4'
var pdf = new jsPDF('p', 'pt', 'a4');
svgElementToPdf(svg, pdf, {
scale: 72/96, // this is the ratio of px to pt units
removeInvalid: true // this removes elements that could not be translated to pdf from the source svg
});
pdf.output('datauri'); // use output() to get the jsPDF buffer

But I can`t achieved it..And kindly advise me... How to solve this problem in JSPDF

REFER SO QUESTION :http://stackoverflow.com/questions/27856670/how-to-rendered-svg-files-into-pdf-in-jspdf-using-javascript

Most helpful comment

Hi

The svg example is great, but it uses an old library (canvg, 2 years old) which only supports very simple svgs (I have tested a few exported from illustrator).

Would be neat if you can update it to use fabric.js instead of canvg!

Thanks

All 2 comments

Hi there,

There's now an svg example :)

Get the latest master and try:

npm install
npm start

Then visit localhost:8000/examples/canvg_context2d/bar_graph_with_text_and_lines.html

Hope this works well for you :)

Many thanks,
James

Hi

The svg example is great, but it uses an old library (canvg, 2 years old) which only supports very simple svgs (I have tested a few exported from illustrator).

Would be neat if you can update it to use fabric.js instead of canvg!

Thanks

Was this page helpful?
0 / 5 - 0 ratings