siamkreative / Contract-Killer-Generator

Based on the popular open-source contract for web designers and developers, this generator lets you create a contract within minutes and export it to PDF.
https://siamkreative-ckg.surge.sh/
GNU General Public License v2.0
89 stars 52 forks source link

Find a more reliable HTML > PDF API #1

Closed siamkreative closed 9 years ago

siamkreative commented 9 years ago

I'm looking for a more reliable API to do the HTML to PDF conversion. The current one doesn't render well and it's sometimes super slow.

Actually, at the moment something went wrong and the PDF aren't created. That's probably my fault...

How about one of these?

siamkreative commented 9 years ago

What it could look like with the 2nd API I mentioned.

$url = 'http://freehtmltopdf.com';
$data = array(
    'convert' => '', 
    'html' => $_POST['html'],
    'baseurl' => 'http://labs.siamkreative.com/contract-killer-generator/'
    );

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data),
        ),
    );
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

// set the pdf data as download content:
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="contract-'.$_POST['customername'].'.pdf"');
var_dump($result);
JamesPaden commented 9 years ago

Biased, but https://docraptor.com is a great option (although not free)

siamkreative commented 9 years ago

Thanks @JamesPaden but I'd like to keep the service free for both users and I. html2pdfrocket.com will become paid on July 1st, so I gotta find a replacement. Perhaps a self hosted PHP script.

Several services and scripts listed here: http://stackoverflow.com/questions/391005/convert-html-css-to-pdf-with-php

JamesPaden commented 9 years ago

Understandable. We're listed on that page as well, but from our testing, the best open-source/free solution is wkhtmltopdf, or a tool that uses it like Snappy - but that requires a server of some sort.

https://parall.ax/products/jspdf might be an option for you, but that's not HTML to pdf.

siamkreative commented 9 years ago

James, I'll try https://parall.ax/products/jspdf and host everything on https://surge.sh/. I'll do that tomorrow