jlamim

Free convert HTML to PDF

Apr 10th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. $PDFContent = "page HTML CONTENT";
  2.  
  3. //API URL
  4. $url = 'http://freehtmltopdf.com';
  5.  
  6. //API PARAMS
  7. $data = array('convert' => '',
  8.           'html' => $PDFContent,
  9.           'baseurl' => base_url(),
  10.           'width' => '210mm',
  11.           'enablejs' => 0,
  12.           'orientation' => 'portrait');
  13.  
  14. // use key 'http' even if you send the request to https://...
  15. $options = array('http' => array('header'  => "Content-type: application/x-www-form-urlencoded\r\n",
  16.                  'method'  => 'POST',
  17.                  'content' => http_build_query($data)),);
  18. //PREPARE OPTIONS VARIABLE
  19. $context  = stream_context_create($options);
  20.  
  21. //GET PDF CONTENT
  22. $result = file_get_contents($url, false, $context);
  23.  
  24. // set the pdf data as download content:
  25. header('Content-type: application/pdf');
  26.  
  27. //OPEN PDF FILE IN YOUR BROWSER
  28. echo $result;
Advertisement
Add Comment
Please, Sign In to add comment