laravel-snappy: The exit status code '1' says something went wrong: stderr: "" stdout: "" command: ...

Hey,

I’m now trying for hours to get wkhtmltopdf to run properly. Locally everything’s fine, but on the test server with Windows 2008 R2, IIS 7 it just won’t work. This is the error I get:

The exit status code '1' says something went wrong: stderr: "" stdout: "" 
command: "C:\path\to\wkhtmltopdf.exe" --lowquality "http://www.google.com" "c:\test.pdf". 

There is no error besides this general error code “1”. The command works fine from command line and even if I just put the command directly in an exec-function. But it does not work with proc_open, which Symfony seems to use. Does anyone have an idea what the problem is or why there is no error?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 20

Commits related to this issue

Most upvoted comments

Dealing with the exact same problem

Never mind … I fixed it with the following config:

return array(
    'pdf' => array(
        'enabled' => true,
        'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"',
        'options' => array(),
    ),
    'image' => array(
        'enabled' => true,
        'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"',
        'options' => array(),
    ),
);

I also get this issue in windows 10. then I found this QA and fixed it by changing in executeCommand function vendor\knplabs\knp-snappy\src\Knp\Snappy\AbstractGenerator.php

$process->getExitCode()!=1?:0,

return [
            $process->getExitCode,
            $process->getOutput(),
            $process->getErrorOutput(),
        ];

to

return [
            $process->getExitCode()!=1?:0,
            $process->getOutput(),
            $process->getErrorOutput(),
        ];

I narrowed it down to being a problem with the Symfonys Process Class, used in the executeCommand method of the AbstractGenerator class.

$process = new \Symfony\Component\Process\Process($command, NULL, $this->env);

I solved the problem with a hack, replacing the executeCommand method in generate with directly executing the command:

public function generate($input, $output, array $options = array(), $overwrite = false)
    {
        if (null === $this->binary) {
            throw new \LogicException(
                'You must define a binary prior to conversion.'
            );
        }

        $this->prepareOutput($output, $overwrite);

        $command = $this->getCommand($input, $output, $options);

        /** Workaround for Windows Server 2008 + IIS7 */
        exec($command);
//         list($status, $stdout, $stderr) = $this->executeCommand($command);
//         $this->checkProcessStatus($status, $stdout, $stderr, $command);
        /** Workaround End */

        $this->checkOutput($output, $command);
    }

I wasn’t really satisfied with that solution, but it worked the last two months without any problems.

I also get this issue in windows 10. then I found this QA and fixed it by changing in executeCommand function vendor\knplabs\knp-snappy\src\Knp\Snappy\AbstractGenerator.php

$process->getExitCode()!=1?:0,

return [
            $process->getExitCode,
            $process->getOutput(),
            $process->getErrorOutput(),
        ];

to

return [
            $process->getExitCode()!=1?:0,
            $process->getOutput(),
            $process->getErrorOutput(),
        ];

Good Idea! But it doesn’t show image

Same problem, but i just want to show another way instead of removing @include blades. On config folder (snappy.php) instead use the first solution you can use this

return array( ‘pdf’ => array( ‘enabled’ => true, ‘binary’ => base_path(‘vendor\wemersonjanuario\wkhtmltopdf-windows\bin\64bit\wkhtmltopdf’), ‘timeout’ => false, ‘options’ => array(), ‘env’ => array(), ), ‘image’ => array( ‘enabled’ => true, ‘binary’ => base_path(‘vendor\wemersonjanuario\wkhtmltopdf-windows\bin\64bit\wkhtmltopdf’), ‘timeout’ => false, ‘options’ => array(), ‘env’ => array(), ) );

and it doesn’t require to install wkhtml on windows, just using vendor folder. It worked for me