.

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 = "<path on your server>/test.pdf"; file_put_contents($pdfFile,$output); echo '<a href="<url>/test.pdf" target="_blank">pdf</a>'; } exit; Or as curl command
curl -X POST -L -H "Content-Type: application/json" -d "{\"key\":\"abc123\",\"html:\"<!doctype html>\\r\\n<html>\\r\\n<head>\\r\\n<meta charset=\\\"UTF-8\\\">\\r\\n<title>my title</title>\\r\\n\\t<script src=\\\"script.js\\\"></script>\\r\\n</head>\\r\\n\\r\\n<body><div>My PDF</div></body>\\r\\n</html>\"}" https://services.scideas.net/perfectpdf/api


Test mode