2
votes

At the moment, I'm trying to trace where this issue arose from given that nothing major was changed.

But at the moment I currently use laravel-snappy to generate pdfs, I haven't had an issue until now when I am all of a sudden receiving the following errors:

The file 'C:\Users\ADMINI~1\AppData\Local\Temp\knp_snappy5a7d3011c11883.41249127.pdf' was not created (command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf" --lowquality --images --enable-javascript --javascript-delay "10" "C:\Users\ADMINI~1\AppData\Local\Temp\knp_snappy5a7d3011b9a179.91650543.html" "C:\Users\ADMINI~1\AppData\Local\Temp\knp_snappy5a7d3011c11883.41249127.pdf").

Unfortunately, it doesn't tell me why it wasn't created. At this point in time, the error handler points to this specific line where it is returning this error:

if (!$this->fileExists($output)) {
    throw new \RuntimeException(sprintf(
        'The file \'%s\' was not created (command: %s).',
        $output, $command
    ));
}

This line comes from this file: vendor\knplabs\knp-snappy\src\Knp\Snappy\AbstractGenerator.php

My wkhtmltopdf binary is located in the correct place, and nothing has changed in response to the setup of these files. And yes, at the moment these files are hosted and served on a Windows Server platform.

My config for the snappy:

<?php

return array(

    'pdf' => array(
        'enabled' => true,
        'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),
    'image' => array(
        'enabled' => true,
        'binary'  => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage"',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),

);

My files are being generated as such through my controller:

  public function downloadPDF(Shipment $shipment) {
      $shipment_details = $shipment->shipment_details;
      $shipment->print_date = Carbon::now();
      $shipment->save();

      $pdf = PDF::loadView('shipments.pdf', compact('shipment','shipment_details'))
                    ->setOption('images', true)
                    ->setOption('enable-javascript', true)
                    ->setOption('javascript-delay', 10);
      return $pdf->download('shipment'.$shipment->uuid.'.pdf');

      $shipment->print_date = Carbon::now();
      $shipment->save();
  }
2
I get the same issue...MathieuAuclair
Actually, if you're pasting the command in the terminal, it looks like wkhtmltopdf is trying to make an HTTP request instead of reading the path, also I recommend you to use vanilla snappy instead of laravel-snappy, it's much better maintained than laravel-snappy which last commit has been made in 2016... I've done enough programming tonight, tomorrow I'll find an answer for windowsMathieuAuclair
you could also work with Docker under Linux everything works fine. install it with chocoMathieuAuclair

2 Answers

2
votes

Posting this in case someone else googling has the same problem, and they don't like the accepted answer of "just do it in Linux"

For me it was because Visual C++ 2013 wasn't installed - running the file in the command line gave me errors about missing dlls that were included in the redist.

1
votes

The easiest way to get around this is to exec a raw command, wkhtmltopdf does not have the same command line parameter on Linux/Windows, this means that the snappy wrapper only works with amd64 and fail when it's used with a 64bit windows executable.

exec("C:/path/to/wkhtmltopdf.exe path/to/my.html destination/for/my.pdf");

since this solution is terrible and that wkhtmltopdf functionality are limited on windows, I strongly recommend you to deploy with docker, or to just develop under Linux. Or else you won't be able to use multiples functionality like pdf footer, pdf encoding utf-8 and much more...

Here's a tutorial on how to use docker compose for laravel!