.
perfectpdf: an html to pdf api
from scideas software
.
perfectpdf api PHP code example
.
The code
//your perfectpdf api key
$key = "abc123";
//your POST fields
//api key
$p['api_key'] = $key;
//read in your html source
$p['html'] = file_get_contents("example.html");
//the perfectpdf api endpoint
$url = "https://services.scideas.net/perfectpdf/api";
//encode payload array as JSON
$postData = json_encode($p);
//create php curl command
$ch = curl_init();
//set curl parameters
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//
$output=curl_exec($ch);
if ($output === false) {
$output = curl_error($ch) . " " .curl_errno($ch);
}
curl_close($ch);
//display output
if(stristr($output,"error")){
echo $output;
}else
{
$pdfFile = "/test.pdf";
file_put_contents($pdfFile,$output);
echo 'pdf';
}
exit;
Or as curl command
curl -X POST -L -H "Content-Type: application/json" -d "{\"key\":\"abc123\",\"html:\"\\r\\n\\r\\n\\r\\n\\r\\nmy title\\r\\n\\t\\r\\n\\r\\n\\r\\nMy PDF
\\r\\n\"}" https://services.scideas.net/perfectpdf/api