私は四半期ごとのトランザクションの 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();
}
しかし、これは上記と同じです。ブレード ビュー ファイルを使用して、URL を呼び出さずに PDF を生成したいと考えています。しかし、私はこれを機能させることができません:
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 を生成したかどうかを教えてください。私はここで立ち往生しているようです。ありがとう。