Laravel wkhtmltopdf taking long time to generate pdf with more than 30 pages
I am trying to generate pdf in laravel using wemersonjanuario/laravelpdf. Below is my controller function.
public function generate_pdf($table,$all_data)
{
$pdf_name = $version.'_'.$table.'.pdf';
File::delete('directory/'.$pdf_name);
$view = \View::make('pdf',['all_data'=>$all_data]);
PDF::loadHTML($view)->orientation('Landscape')
->save($pdf_name , new Local(base_path().'/public/'));
return '/public/'.$pdf_name ;
}
Here,
$all_data = Data I have fetched from my table
$view = View that I rendered from the data
$table = Table name After generating the pdf I return the saved path to javascript to open the path using window.open.
Here is the blade area
@php($page = 1)
@foreach ($all_data['p_datas'] as $key => $cols)
<section class="col-lg-12" style="width: {{$line_size}}px;page-break-before: always" >
<table class='mytable' style="border-collapse: collapse;border-spacing: 0px;margin-left: auto; margin-right: auto;">
<thead style="border-top:1px solid #000000;border-bottom: 1px solid #000000; text-align: center">
<tr class='top-border bottom-border top'>
@foreach ($all_data['columns'][$p_no] as $col)
<td class="text-center formate" style="width:{{$all_data['column_width'][$col]}}px; padding-right: {{ $all_data['td_space' ]}}px">{!! $col !!}</td>
@endforeach
</tr>
</thead>
<tbody style="text-align: center;">
@foreach($cols as $i=>$data)
<tr>
@foreach($data as $j=>$dt)
<td style="min-height: 40px;padding-bottom: 8px"> {!! $dt !!} </td>
@endforeach
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="footnote col-sm-12" style="border-top: solid 1px;">
<span class="footnote" id="footnote">{!!$footnote!!}</span>
</div>
<div style="margin-top: 20px; margin-bottom: 10px;">
<table class="row" style="margin-left: 30px">
<tbody>
<td style="width: 400px"><h6>Printed By: {{ $user }}</h6></td>
<td style="width: 300px"><h6> Page <span> {{ $page }}</span></h6></td>
<td style="width: 400px"><h6>Print Date : {{ $date }}</h6></td>
</tbody>
</table>
</div>
</section>
@php($page++)
@endforeach
In the table I have 1000 rows. In the blade file I run the loop for every 25 rows I break per page and render data.
If I only render the view in html using below code it takes highest 10 seconds. But when I try to generate the pdf it is taking a day or more. What is the problem here?
$html = $view->render();
return $html
I have used dompdf and tcpdf also but those appeared same as wkhtmltopdf. Is there any solution?
Please or to participate in this conversation.