mikehaertl / phpwkhtmltopdf wrapper - 从命令行运行PHP文件时工作

I have made the following file:

test.php

<?php

require 'vendor/autoload.php';
use mikehaertl\wkhtmlto\Pdf;

$htmlString = <<<EOT
<!DOCTYPE html>
    test
</html>    
EOT;

$pdf = new Pdf($htmlString);
$pdf->setOptions(array(
    'orientation' => 'landscape'
));

$pdf->saveAs('new.pdf');

?>

When I run from the command line (Ubuntu 12.x):

sudo php test.php

I get a file that shows up in my directory and works as intended. However now take the following file where I am trying to apply the above to a real world scenario - note: when I echo $htmlString I get a valid and expected string.

testPDF.php

<?php
    // Start session and check if user is logged in
    session_start();
    if(!isset($_SESSION['permission']))
    {
        die('Please login.');
    }
    // Dependencies
    require 'vendor/autoload.php';
    use mikehaertl\wkhtmlto\Pdf;
    require 'database.php';
    // Initialize
    $client = $db->real_escape_string($_GET['client']);
    $start_date = $db->real_escape_string($_GET['start_date']);
    $end_date = $db->real_escape_string($_GET['end_date']);
    $jobs = array();
    $htmlString = '';
    // Get list of jobs from DB & save to array
    $query = "SELECT somecolumns FROM mydatabase WHERE start_date > '{$start_date}' AND end_date < '{$end_date}' AND client = '{$client}'";
    if(!$result = $db->query($query))
    {
        die('There was an error running the query [' . $db->error . ']');
    }
    while($r = mysqli_fetch_assoc($result)) 
    {
        $jobs[] = $r;
    }
    // Loop through jobs array and formulate HTML string
    foreach($jobs as $value)
    {
        $id = $value['id'];
        $name = $value['name'];
        $tech = $value['tech'];
        $time_closed = $value['time_closed'];
        $time_total = $value['time_total'];
        $time_charged = $value['time_charged'];
        $description = $value['description'];

        $htmlString = $htmlString . <<<EOT
                <h4 style="text-align: center;">{$id} - {$name}</h5>
                    <table id="simple-table" class="table table-striped table-bordered table-hover">
                        <thead>
                            <tr>
                                <th style="width: 180px;">Date</th>
                                <th>Description</th>
                                <th style="width: 50px;">Duration</th>
                                <th style="width: 150px;">Time Charged</th>
                                <th style="width: 150px;">Technician</th>
                            </tr>
                        </thead>
                        <tbody id="jobs_start">
                            <tr>
                                <td>{$time_closed}</td>
                                <td>{$description}</td>
                                <td>{$time_total}</td>
                                <td>{$time_charged}</td>
                                <td>{$tech}</td>
                            </tr>
                        </tbody>
                    </table>
EOT;
    }

    $pdf = new Pdf($htmlString);
    $pdf->setOptions(array(
        'orientation' => 'landscape'
    ));

    $pdf->saveAs('new.pdf');

?>

When I try to run the above by browsing to testPDF.php as a logged in user, I get nothing. No file is generated and no error/warning in the error logs. I've tried using $pdf->send() as well but no success.

My initial thought that this is a permissions issue, however I've tried setting testPDF.php to owner root and permission 755 but it still does not resolve the issue.

The issue is that when sending a HTML string to the pdf object, it looks for the tag to determine if it's html.

The first example has a HTML tag, while the 2nd file does not have any html tag thus is fails, silently.

https://github.com/mikehaertl/phpwkhtmltopdf/blob/master/src/Pdf.php