Search code examples
phpwkhtmltopdf

wkhtmltopdf return blank page


I can't convert my php to pdf with wkhtmltopdf.

require 'vendor/autoload.php';

ob_start();
require 'pdf/test.html';
$content = ob_get_clean();
$pdf = new \mikehaertl\wkhtmlto\Pdf($content);
$pdf->send();

I install composer and wkhtmltopdf on my PC is when I launch my code I have a blank page.

do you have a solution to offer me?

Thank you in advance.


Solution

  • Try to use, change '/path/to/page.html' to your page link/url :

    use mikehaertl\wkhtmlto\Pdf;
    
    // You can pass a filename, a HTML string, an URL or an options array to the constructor
    $pdf = new Pdf('/path/to/page.html');
    
    // On some systems you may have to set the path to the wkhtmltopdf executable
    // $pdf->binary = 'C:\...';
    
    if (!$pdf->saveAs('/path/to/page.pdf')) {
        $error = $pdf->getError();
        // ... handle error here
    }