makepdf.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. error_reporting(E_ALL);
  3. ini_set('display_errors', 1);
  4. // require composer autoload
  5. require __DIR__ . '/vendor/autoload.php';
  6. $mpdf = new mPDF();
  7. $stylesheet = file_get_contents('canvas-pdf.css');
  8. $mpdf->WriteHTML($stylesheet,1);
  9. $url = urldecode($_REQUEST['url']);
  10. // To prevent anyone else using your script to create their PDF files
  11. // if (!preg_match('/^http:\/\/www\.mydomain\.com/', $url)) {
  12. // die("Access denied");
  13. // }
  14. // For $_POST i.e. forms with fields
  15. if (count($_POST) > 0) {
  16. $ch = curl_init($url);
  17. curl_setopt($ch, CURLOPT_HEADER, 0);
  18. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1 );
  19. foreach($_POST as $name => $post) {
  20. $formvars = array($name => $post . " \n");
  21. }
  22. curl_setopt($ch, CURLOPT_POSTFIELDS, $formvars);
  23. $html = curl_exec($ch);
  24. curl_close($ch);
  25. } elseif (ini_get('allow_url_fopen')) {
  26. $html = file_get_contents($url);
  27. } else {
  28. $ch = curl_init($url);
  29. curl_setopt($ch, CURLOPT_HEADER, 0);
  30. curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
  31. $html = curl_exec($ch);
  32. curl_close($ch);
  33. }
  34. $mpdf = new mPDF();
  35. $mpdf->useSubstitutions = true; // optional - just as an example
  36. $mpdf->SetHeader($url . "\n\n" . 'Page {PAGENO}'); // optional - just as an example
  37. //$mpdf->CSSselectMedia='mpdf'; // assuming you used this in the document header
  38. $mpdf->setBasePath($url);
  39. $mpdf->WriteHTML($html);
  40. $mpdf->Output();