title: knp snappy bundle and wkhtmltopdf ContextErrorException
body: <p>i've installed knp snappy bundle with composer and followed the tutorial for usage and configuration at <a href="https://github.com/KnpLabs/KnpSnappyBundle" rel="nofollow">https://github.com/KnpLabs/KnpSnappyBundle</a></p>
  
  <p>i've installed wkhtmltopdf-0.9.9-installer.exe and changed the default path in the the config.yml file</p>
  
  <pre><code># knp_snappy Configuration
  knp_snappy:
      pdf:
          enabled:    true
          binary:     C:\Program Files (x86)\wkhtmltopdf
          options:    []
  </code></pre>
  
  <p>here is the function</p>
  
  <pre><code>/**
   * @Route("/print", name="invite_print")
   * @Method("GET")
   */
  public function printAction() {
      $entity = new Invite();
      $form = $this-&gt;createCreateForm($entity);
  
      $html = $this-&gt;renderView('PrifProtocoleBundle:Invite:new.html.twig', array(
          'entity' =&gt; $entity,
          'form' =&gt; $form-&gt;createView()
      ));
  
      return new Response(
              $this-&gt;get('knp_snappy.pdf')-&gt;getOutputFromHtml($html), 200, array(
          'Content-Type' =&gt; 'application/pdf',
          'Content-Disposition' =&gt; 'attachment; filename="file.pdf"',
          'charset' =&gt; 'UTF-8',
              )
      );
  }
  </code></pre>
  
  <p>but unfortunateley i have these errors messages: </p>
  
  <h1>error 1:</h1>
  
  <pre><code>ContextErrorException: Warning: json_encode(): Invalid UTF-8 sequence in argument in  C:\wamp\www\protocole\app\cache\dev\classes.php line 4592
  </code></pre>
  
  <h1>error 2:</h1>
  
  <pre><code>ContextErrorException: Warning: json_encode(): Invalid UTF-8 sequence in argument in C:\wamp\www\protocole\vendor\monolog\monolog\src\Monolog\Formatter\NormalizerFormatter.php line 132
  </code></pre>
  
  <p>can someone tell me what to do to resolve this problem? Thanks</p>
  
  <h1>The json_encode function (strangely empty) in the json.php file</h1>
  
  <pre><code>/**
   * (PHP 5 &amp;gt;= 5.2.0, PECL json &amp;gt;= 1.2.0)&lt;br/&gt;
   * Returns the JSON representation of a value
   * @link http://php.net/manual/en/function.json-encode.php
   * @param mixed $value &lt;p&gt;
   * The &lt;i&gt;value&lt;/i&gt; being encoded. Can be any type except
   * a resource.
   * &lt;/p&gt;
   * &lt;p&gt;
   * This function only works with UTF-8 encoded data.
   * &lt;/p&gt;
   * @param int $options [optional] &lt;p&gt;
   * Bitmask consisting of &lt;b&gt;JSON_HEX_QUOT&lt;/b&gt;,
   * &lt;b&gt;JSON_HEX_TAG&lt;/b&gt;,
   * &lt;b&gt;JSON_HEX_AMP&lt;/b&gt;,
   * &lt;b&gt;JSON_HEX_APOS&lt;/b&gt;,
   * &lt;b&gt;JSON_NUMERIC_CHECK&lt;/b&gt;,
   * &lt;b&gt;JSON_PRETTY_PRINT&lt;/b&gt;,
   * &lt;b&gt;JSON_UNESCAPED_SLASHES&lt;/b&gt;,
   * &lt;b&gt;JSON_FORCE_OBJECT&lt;/b&gt;,
   * &lt;b&gt;JSON_UNESCAPED_UNICODE&lt;/b&gt;. The behaviour of these
   * constants is described on
   * the JSON constants page.
   * &lt;/p&gt;
   * @param int $depth [optional]
   * @return string a JSON encoded string on success or &lt;b&gt;FALSE&lt;/b&gt; on failure.
   */
   function json_encode ($value, $options = 0, $depth = 512) {}
  </code></pre>
  
  <h1>The NormalizerFormatter.php file for error 2</h1>
  
  <pre><code>protected function toJson($data, $ignoreErrors = false)
  {
      // suppress json_encode errors since it's twitchy with some inputs
      if ($ignoreErrors) {
          if (version_compare(PHP_VERSION, '5.4.0', '&gt;=')) {
              return @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
          }
  
          return @json_encode($data);
      }
  
      if (version_compare(PHP_VERSION, '5.4.0', '&gt;=')) {
          return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
      }
  
      return json_encode($data);
  }
  </code></pre>
  
  <h1>The config.yml file</h1>
  
  <pre><code># Doctrine Configuration
  doctrine:
  dbal:
      driver:   %database_driver%
      host:     %database_host%
      port:     %database_port%
      dbname:   %database_name%
      user:     %database_user%
      password: %database_password%
      charset:  UTF8
      # if using pdo_sqlite as your database driver, add the path in parameters.yml
      # e.g. database_path: %kernel.root_dir%/data/data.db3
      # path:     %database_path%
  
  orm:
      auto_generate_proxy_classes: %kernel.debug%
      auto_mapping: true
      naming_strategy: doctrine.orm.naming_strategy.underscore
  </code></pre>
  
  <h1>The twig files</h1>
  
  <pre><code>{# app/Resources/views/layout.html.twig #}
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html" charset="utf-8" &gt;
      &lt;link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet"  media="screen"&gt;
      {% block body %}
  
  {% endblock %}
  </code></pre>
  
  <p>=================== </p>
  
  <pre><code>{# PrifBundle/invite/new.html.twig #}
  {% extends 'PrifBundle::layout.html.twig' %}
  
  {% block body %}
  
  &lt;div class="well"&gt;
  
  &lt;div class="form-horizontal" role="form"&gt; 
  
  
  {{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}         
  {# Les erreurs générales du formulaire. #}
  {{ form_errors(form) }}
  </code></pre>