What HTML to PDF libraries handle javascript?
Asked Answered
F

3

8

I'm trying to figure out how to generate a PDF from HTML that contains charts generated with the flot javascript library. Dompdf was my original conversion library but after adding flot charts it fails miserably. I've looked around SO (particularly at https://stackoverflow.com/questions/3178448/list-of-html-to-pdf-converters) and googled for a while but can't seem to find any that explicitly provide javascript support. I'm working in PHP. I saw someone mention in that post that they had used php-wkhtmltox successfully in all cases but a chart generated by a different javascript library. Is that my only chance? I could possibly pay up to a couple hundred dollars if there is a commercial option available.

If this is something that really isn't possible with current libraries, what exactly is the challenge that makes it so much harder to convert html generated by javascript vs. normal html?

Thanks

Fromma answered 1/2, 2011 at 4:9 Comment(0)
K
8

You can use wkhtmltopdf

Just extract it onto your server, run the command (check out the manual here).

Thank you.

Katharynkathe answered 1/2, 2011 at 4:32 Comment(2)
Well, it didn't help but you're the only response so you win. This library may work well, but the documentation for how to implement it from PHP as opposed to the command line, as well as any discussion of what it can and can't do with javascript has convinced me to give up on my current approach. I'm going to drop flot and use a native PHP library to generate charts as images and then use dompdf which I already had working for everything OTHER than the flot charts.Fromma
Thanks for accpting.Please let me know if you need more help on this.Katharynkathe
D
3

The Pdfcrowd HTML to PDF online API can run JavaScript. You can download a client library for PHP and give it a try.

It is a commercial SaaS solution, here is the docs: http://pdfcrowd.com/html-to-pdf-api/.

Delete answered 5/2, 2011 at 20:54 Comment(0)
M
1

PDFPY

sudo npm i pdfpy

var pdfpy = require('pdfpy');

File

var pdfpy = require('pdfpy');

    var data = {
        //the key as to be same as below
        input: "./test.html",
        output: "./output.pdf"
    }
    pdfpy.file(data, function(err, res) {
        if(err) throw err

        if(res) console.log("success")
    });

URL

var pdfpy = require('pdfpy');

var data = {
    //the key as to be same as below
    input: "http://google.com",
    output: "./output.pdf"
}
pdfpy.url(data, function(err, res) {
    if(err) throw err

    if(res) console.log("success")
});
Monmouthshire answered 21/2, 2017 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.