0

我正在做这个项目,我需要为季度交易生成 pdf 报告。我已经创建了刀片视图文件,并且能够使用带有 shell_exec() 的 wkhtmltopdf 库生成 pdf。这是我的代码:

public function generate_report($quarter, $year){

    $url_home = 'http://localhost.welcomehome.com/testreport/';
    $temp_path = storage_path().'/temp/';
    $stmt = ' ';
    $stmt = 'wkhtmltopdf --margin-top 0 --margin-left 0 --margin-bottom 0 --margin-right 0 '.$url_home.'page1/'.$quarter.'/'.$year.' '.$temp_path.'page1.pdf ';
   //appending similar strings to $stmt
    shell_exec ($stmt);
   }

现在,在这种方法中,我需要从我的服务器对其自身进行 http 调用,理论上这个问题不需要。我遇到了这个库 phpwkhtmltopdf 库

它是 wkhtmltopdf 的包装器。我可以让它工作:

$pdf = new Pdf($url_home.'page1/'.$quarter.'/'.$year);
if (!$pdf->saveAs(.$temp_path.'page1.pdf')) {
    echo $pdf->getError();
}

但是,这与上面相同,我想使用刀片视图文件生成 pdf 而无需调用 url。但是,我不能让它工作:

 public function generate_report_v2($quarter,$year)
 {
    $pdf = new Pdf(view('research_reports/about',['quarter' => $quarter, 'year' => $year]););
    $temp_path = storage_path().'/temp/';
    if(!$pdf->saveAs($temp_path.'page.pdf'))
    {
        echo $pdf->getError();
    }
 }

它给了我错误:

You need to specify at least one input file, and exactly one output file Use - for stdin or stdout Name: wkhtmltopdf 0.12.3 (with patched qt) Synopsis: wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... Document objects: wkhtmltopdf is able to put several objects into the output file, an object is either a single webpage, a cover webpage or a table of content. The objects are put into the output......and some more lines.

如果有人使用带有刀片视图文件的库生成 pdf,请告诉我。我好像卡在这里了。谢谢。

4

0 回答 0