I am doing this project where I need to generate a pdf report for quarterly transactions. I have created the blade view files and I am able to generate the pdf's using wkhtmltopdf library with shell_exec(). Here my code for that:
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);
}
Now, In this approach I need to make an http call from my server to itself, which in theory should not be required for this problem. I came across this library phpwkhtmltopdf library
which is a wrapper around wkhtmltopdf. I can get it to work doing:
$pdf = new Pdf($url_home.'page1/'.$quarter.'/'.$year);
if (!$pdf->saveAs(.$temp_path.'page1.pdf')) {
echo $pdf->getError();
}
But, this would be same as above, I want to use the blade view files to generate pdf without calling the urls. But, I can't get this to work:
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();
}
}
It gives me the error:
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.
Please let me know if anyone generated pdfs using this library with blade view files. I seem to have stuck here. Thanks.