wkhtmltopdf Issue


wkhtmltopdf Issue

1)我将"wkhtmltopdf-i386"重命名为"wkhtmltopdf",并将"wkhtml/topdf"上传到名为"/usr/local/bin"的文件夹中的服务器

2) 我在同一文件夹中上传了php集成脚本,并将其命名为"pdf_class.php"(https://github.com/aur1mas/Wkhtmltopdf/blob/master/Wkhtmltopdf.php)

我将这两个文件上传到"/home/kacmaz/domains/xxx.com/public_html/test_pdf/"

3) 我上传了一个名为"test.php"的文件,位于同一文件夹中,其中包含:

    <?php
include "pdf_class.php";
  try 
{
    $wkhtmltopdf = new Wkhtmltopdf(array('path' =>'/home/kacmaz/domains/xxx.com/public_html/test_pdf'));
    //$wkhtmltopdf = new Wkhtmltopdf(array('path' => APPLICATION_PATH . '/../public/uploads/'));
    $wkhtmltopdf->setTitle("Title");
    $wkhtmltopdf->setHtml("http://www.google.com");
    $wkhtmltopdf->output(Wkhtmltopdf::MODE_DOWNLOAD, "myfile.pdf");
} 
catch (Exception $e) 
{
    echo $e->getMessage();
}
?>

它创建了像"779753975.html"749335291.html"这样的文件到"/home/kacmaz/domains/xxx.com/public_html/test_pdf/"(文件为21字节,它写入)http://www.google.com"在文件内)

但它给出了这个错误

WKHTMLTOPDF未返回任何数据

而且没有pdf文件,我该如何解决这个问题?

我目前无法真正复制环境,但我建议尝试替换

$wkhtmltopdf->setHtml("http://www.google.com");

带有

$wkhtmltopdf->setHtml("<h1>This Is A Test</h1><p>Ponies</p>");

看看这会产生什么。听起来像是生成了一些临时文件,setHtml将其内容写入临时文件,并基于这些文件生成pdf,这就是为什么你没有得到数据,因为它实际上不是HTML内容。

此外,像往常一样,在命令行中使用类似的内容进行测试,看看它是否有效,这可能会消除一些问题。