I'm trying to require a php view dynamically. So that it print a pdf using phpwkhtmltopdf.
First I send the name of the viewer page from my handler page by using a button:
<form action="print.php" method="get">
<button name="printit" type="submit" value="m_dpgmi1.php">print</button>
</form>
Then I catch it in the page where I've the phpwkhtmltopdf function:
<?php
require '../vendor/autoload.php';
$template = $_GET['printit'];
use mikehaertl\wkhtmlto\Pdf;
ob_start();
require "'$template'";
$content = ob_get_clean();
// You can pass a filename, a HTML string, an URL or an options array to the constructor
$pdf = new Pdf($content);
$pdf -> setOptions(['orientation' => 'Landscape']);
$pdf->binary = 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe';
$pdf->send();
?>
Unfortunately I get an error:Warning: require('m_dpgmi1.php'): failed to open stream: No such file or directory
It looks right require('m_dpgmi1.php')
, except for the braces. Is there a way to place a variable value as an require argument?