2
votes

I'm new to symfony2 and very to use external libraries. I want to use the KNP Snappy Bundle, my first third party bundle.

I did exactly that is told in the git link.

{
    "require": {
        "knplabs/knp-snappy-bundle": "dev-master"
    }
}

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        //...
        new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),

app/config/config.yml

knp_snappy:
    pdf:
        enabled:    true
        binary:     /usr/local/bin/wkhtmltopdf
        options:    []
    image:
        enabled:    true
        binary:     /usr/local/bin/wkhtmltoimage
        options:    []

Then I added following line in ACME welcome controller to test

$this->get('knp_snappy.pdf')->generate('http://www.google.fr', '/Symfony/file.pdf');

It says The exit status code '1' says something went wrong: stderr: "The system cannot find the path specified. " stdout: "" command: /usr/local/bin/wkhtmltoimage --format "jpg" "http://www.google.fr" "/Symfony/file.pdf".

I tried

$this->get('knp_snappy.pdf')->generateFromHtml(
    $this->renderView(
        'AcmeDemoBundle:Welcome:index.html.twig'),
        '/Symfony/file.pdf'
    );

It shows The exit status code '1' says something went wrong: stderr: "The system cannot find the path specified. " stdout: "" command: /usr/local/bin/wkhtmltopdf --lowquality "C:\Windows\TEMP\knp_snappy530da4525584b8.92211088.html" "/Symfony/file.pdf".

What I'm missing? Do I need to install anything ? Please describe how can I run it and generate a proper pdf????? I searched, I'm guessing I need to install wkhtmltoimage etc. But from where and how?

3
well, it looks like you're on Windows, and you specified a Linux path... I assume you didn't download the binaries.Touki
@Touki Installed the binaries. By failing to configure the path for windows. Binaries are in C:\Program Files\wkhtmltopdf\bin. So I showed the path in config.php. It still saying The exit status code '1' says something went wrong: stderr: "'C:/Program' is not recognized as an internal or external command, operable program or batch file.AtanuCSE
Show us the config fileguy_fawkes
@abbiya It's already there app/config/config.yml I also tried that Ahmed Samy AnsweredAtanuCSE
What is the path of this file please app / AppKernel.php I don't have it, I imagine I have to create itPedro Ávila

3 Answers

7
votes

you can also manage wkhtmltopdf with composer too, I did it in a recent project:

in your composer.json you can add:

"h4cc/wkhtmltopdf-amd64": "0.11.0-RC1"

and in your config.yml:

binary:     %kernel.root_dir%/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64
4
votes

Few months later, but here is what helped me.

I put the path to wkthmltopdf folder in escaped double quotes.

knp_snappy:
   pdf:
      binary: "\"C:/Program Files (x86)/wkhtmltopdf/wkhtmltopdf.exe\""
0
votes

You can do one of these

1- Update your config.yml

 pdf:
    enabled:    true
    binary:     wkhtmltopdf
    options:    []
  • And update your windows environment PATH with path/to/my/wkhtmltopdf

2- Or set the path directly in config.yml

pdf:
        enabled:    true
        binary:     /path/to/my/wkhtmltopdf
        options:    []