質問

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?

役に立ちましたか?

解決 2

Turns out the answer is quite simple, just needed to start the input with

<html><head></head><body> and end with </body></html>

As my input for whtml2pdf was the content of a div, I just had to insert those html tags into the value of the input being sent to the controller and voila.

他のヒント

According to the documentation of the package you have provided, it says that you need to include the binaries in your composer.json file to make it work:


Note (you must also include wkhtmltopdf binaries) 32-bit systems

{
    "require": {
        "h4cc/wkhtmltopdf-i386": "*"
    }
}

64-bit systems

{
    "require": {
        "h4cc/wkhtmltopdf-amd64": "*"
    }
}

You can include both of these if you need.


Sounds like Laravel is trying to execute the 64bit binary and can't find it. Make sure that:

  • You have it placed in the right folder.
  • It has execution permission set with chmod.
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top