right, I have installed the service provider for wkhtmltopdf (https://github.com/ignited/laravel-pdf) and when I add
Route::get('/', function() {
$pdf = PDF::make();
$pdf->addPage('<html><head></head><body><b>Hello World</b></body></html>');
$pdf->send();
});
in my routes.php it generates a pdf file.
What I am trying to do is to POST a whole div to my controller and then generate a PDF from that.
My form:
<form id="convert" action="{{{ URL::to('') }}}/pdf" method="post">
<input type="hidden" name="body" id="body">
<input type="submit" class="btn btn-success pdf" value="Done? Convert to PDF!">
</form>
the jQuery:
$('form#convert').submit(function(){
$("input#body").val($("#preview").html());
});
routes.php:
Route::post('pdf', 'PdfController@index');
and finally my controller (PdfController):
<?php
class PdfController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$data = Input::get('body');
$pdf = PDF::make();
$pdf->addPage($data);
$pdf->send('test.pdf');
if(!$pdf->send())
return $pdf->getError();
}
}
Somehow I think it;s a basic POST vs GET thing, or I'm not doing things right.
Right now I get the error Could not run command '/var/www/docassembly/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64'
but if I replace my variable inside my controller by straight html I get the same error.
If I use GET in the form and the route and pass straight html as a parameter, the error is different:
Could not run command '/var/www/docassembly/vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64' test /tmp/tmp_WkHtmlToPdf_Hq98EZ: Loading pages (1/6) [> ] 0% [======> ] 10% [============================================================] 100% Error: Failed loading page http://test (sometimes it will work just to ignore this error with --load-error-handling ignore)
So having it in the controller is also an issue. Any leads?