123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- // require composer autoload
- require __DIR__ . '/vendor/autoload.php';
- $mpdf = new mPDF();
- $stylesheet = file_get_contents('canvas-pdf.css');
- $mpdf->WriteHTML($stylesheet,1);
- $url = urldecode($_REQUEST['url']);
- // To prevent anyone else using your script to create their PDF files
- // if (!preg_match('/^http:\/\/www\.mydomain\.com/', $url)) {
- // die("Access denied");
- // }
- // For $_POST i.e. forms with fields
- if (count($_POST) > 0) {
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1 );
- foreach($_POST as $name => $post) {
- $formvars = array($name => $post . " \n");
- }
- curl_setopt($ch, CURLOPT_POSTFIELDS, $formvars);
- $html = curl_exec($ch);
- curl_close($ch);
- } elseif (ini_get('allow_url_fopen')) {
- $html = file_get_contents($url);
- } else {
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
- $html = curl_exec($ch);
- curl_close($ch);
- }
- $mpdf = new mPDF();
- $mpdf->useSubstitutions = true; // optional - just as an example
- $mpdf->SetHeader($url . "\n\n" . 'Page {PAGENO}'); // optional - just as an example
- //$mpdf->CSSselectMedia='mpdf'; // assuming you used this in the document header
- $mpdf->setBasePath($url);
- $mpdf->WriteHTML($html);
- $mpdf->Output();
|