Showing posts with label curl exec. Show all posts
Showing posts with label curl exec. Show all posts

Tuesday, February 05, 2013

Generate PDFs Dynamically With PHP



This following code was used to generate PDFs dynamically. For example newpdffile.pdf just a new empty PDFs file. In pdfgenrate.php file , what ever you want in your PDFs just implement that in the php file dynamically.

Now you can run the following code , the PDFs generate dynamically and you will get the generated PDFs at the same path. 

function GetImageFromUrl($link)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_URL,$link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
return $result; 
}
       
 $filePath = $_SERVER['DOCUMENT_ROOT']."/yoursite/newpdffile.pdf";
$pathurl = "http://www.pdfmyurl.com/?url=http://localhost/yoursite/pdfgenrate.php";
$sourcecode=GetImageFromUrl($pathurl);
$savefile = fopen($filePath, 'w');
fwrite($savefile, $sourcecode);
fclose($savefile);

Cheers and thanks to pdfmyurl.com .