Thanks! yeah, Iām slowly doing my way to a functional plugin based on that example.
Some help would be great as Iām no expert in php functions.
so basically www.website.com/makepdf?url=http%3A%2F%2website.com/page%2F
returns a pdf but is making one letter per page( more than a thousand pages ).
anybody notices something strange in this code?
<?php
@include_once __DIR__ . '/vendor/autoload.php';
Kirby::plugin('KirbyPrint', [
'routes' => [
[
'pattern' => 'makepdf',
'action' => function () {
$mpdf = new \Mpdf\Mpdf();
$url = urldecode($_REQUEST['url']);
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();
$mpdf->useSubstitutions = true; // optional - just as an example
$mpdf->SetHeader($url . "\n\n" . 'Page {PAGENO}'); // optional - just as an example
$mpdf->CSSselectMedia = 'style';
$mpdf->setBasePath($url);
$mpdf->WriteHTML($html);
$mpdf->Output();
}
]
]
]);