How to export an HTML / C # (Razor) page containing SVG elements for PDF?

7

I'm currently working with Highcharts, a javascript library that generates graphics. It has an export component, but only exports the graphic itself, I still need to assemble the PDF layout.

For export it goes to the highcharts.com server which is not the most appropriate either because the application may need to run offline.

Does anyone have experience with exporting SVG with HTML? Do you have any component tips to help with this work, preferably running offline?

I did not find it necessary to post code in this post, but it would help any example code or some external reference.

    
asked by anonymous 24.01.2014 / 12:53

1 answer

3

I suggest the phantomjs .

For your specific case, the link below might help:

link

Once you have installed phantomjs, create a file htmltopdf.js :

// Usage: htmltopdf.js url pdf
var system = require('system');
var webpage = require('webpage');

var args = system.args;
var url = args[1];
var pdf = args[2];

var page = webpage.create();
page.open(url, function () {
    page.render(pdf);
    phantom.exit();
})

Then, on the command line run:

phantomjs htmltopdf.js http://www.google.com google.pdf

It will generate a pdf file (google.pdf) from url (www.google.com).

    
02.02.2014 / 20:36