Hi, the replace of currenty page number [page] and total page [toPage] not working when use footer-html. It's the expected behavior? I really need this.
This work fine: http://stackoverflow.com/a/37807113/4470071
I'ts the correcty/only way? Maybe add this on documentation is a good idea.
Try setting the footer text via the options in config/snappy.php file.
'pdf' => array(
'enabled' => true,
'binary' => base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'),
'timeout' => false,
'options' => array(
'page-size' => 'A4',
'margin-top' => 5,
'margin-right' => 5,
'margin-left' => 5,
'margin-bottom' => 6,
'orientation' => 'Landscape',
'footer-center' => 'Page [page] of [toPage]',
'footer-font-size' => 8,
'footer-left' => 'Confidential'
),
'env' => array(),
)
You can see a full list of options in the wkhtmltopdf documentation.
This is how I do it, I haven't tried this, but you should also be able to set options at runtime using chain methods.
PDF::loadHTML($html)->setOption('footer-center', 'Page [page]')->save('myfile.pdf');
Thanks for reply @oscarAG. With footer-center/footer-right work fine, i've tested. But, the question is over footer-html.
@rafwell
I think I got it working.
as Doc of wkhtmltopdf stand :
As can be seen from the example, the arguments are sent to the header/footer
html documents in get fashion.
1) prepare route, for example:
Route::get('pdf/footer', 'PDFController@getFooter')->name('pdf.footer');
2) construct PDF, with route passed to 'footer-html' for example:
$pdf = PDF::loadView('content.pdf', $data)
->setOption('footer-html', route('pdf.footer'))
->setOption('margin-bottom', 10)
->setPaper('a4');
return $pdf->inline();
3) in PDFController - compact "$_GET params" to your footer blade
public function getFooter(Request $request)
{
$query = $request->all();
return view('pdfFooter',compact('query'));
}
4) now in footer blade you have an array, sth like:
"page" => "1"
"section" => ""
"sitepage" => "1"
"title" => null
"subsection" => ""
"frompage" => "1"
"subsubsection" => null
"isodate" => "2017-06-12"
"topage" => "1"
"doctitle" => null
"sitepages" => "1"
"webpage" => ""
"time" => "16:02:14"
"date" => "2017-06-12"
]
5) and can access it like:
Page {{ $query['page'] }} of {{ $query['topage'] }}
Sorry for my english. Any code improvements are welcomed.
@rafwell: the javascript mentioned on the StackOverflow link works. (y) ,
Passing $_GET param doesn't work for me.
@twf-nikhila ,
you must be sure that the route you request by footer-html and header-html is public without any Auth middleware.
@rafwell
I think I got it working.as Doc of wkhtmltopdf stand :
As can be seen from the example, the arguments are sent to the header/footer
html documents in get fashion.
- prepare route, for example:
Route::get('pdf/footer', 'PDFController@getFooter')->name('pdf.footer');- construct PDF, with route passed to 'footer-html' for example:
$pdf = PDF::loadView('content.pdf', $data) ->setOption('footer-html', route('pdf.footer')) ->setOption('margin-bottom', 10) ->setPaper('a4'); return $pdf->inline();
- in PDFController - compact "$_GET params" to your footer blade
public function getFooter(Request $request) { $query = $request->all(); return view('pdfFooter',compact('query')); }
- now in footer blade you have an array, sth like:
"page" => "1" "section" => "" "sitepage" => "1" "title" => null "subsection" => "" "frompage" => "1" "subsubsection" => null "isodate" => "2017-06-12" "topage" => "1" "doctitle" => null "sitepages" => "1" "webpage" => "" "time" => "16:02:14" "date" => "2017-06-12" ]
- and can access it like:
Page {{ $query['page'] }} of {{ $query['topage'] }}Sorry for my english. Any code improvements are welcomed.
I like the approach but I'm getting the error:
Failed to load ... with network status code 3 and http status code 0 - Host ... not found.
@enricooliva
Did you find the solution?
@enricooliva
Did you find the solution?
I used the approach with JavaScript code mentioned in the documentation and StackOverflow in the header-html and also upgrading the wkhtmltopdf package on Ubuntu.
$pdf->setOption('header-html', $header);
JavaScript code:
function subst() {
var vars={};
var x=window.location.search.substring(1).split('&');
for (var i in x) {
var z=x[i].split('=',2);
vars[z[0]] = unescape(z[1]);
}
if(vars.page > 1){
...
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy.
If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.
Most helpful comment
Try setting the footer text via the options in config/snappy.php file.
You can see a full list of options in the wkhtmltopdf documentation.
This is how I do it, I haven't tried this, but you should also be able to set options at runtime using chain methods.
PDF::loadHTML($html)->setOption('footer-center', 'Page [page]')->save('myfile.pdf');