Partage
  • Partager sur Facebook
  • Partager sur Twitter

Utiliser style personnel avec KnpSnappyBundle

    18 novembre 2017 à 16:38:15

    Salut!

    Alors j'utilise le bundle KnpSnappyBundle pour la génération de fichiers PDF. Tous se passe bien mais dès que je définie une "class" personnelle sur une balise html, j'obtiens l'erreur suivante:

    The exit status code '1' says something went wrong:
    stderr: "Loading pages (1/6)
    [> ] 0%
    [======> ] 10%
    [=======> ] 12%
    [=======================> ] 39%
    [========================> ] 40%
    [=========================> ] 43%
    [===========================> ] 46%
    [============================> ] 48%
    [==============================> ] 50%
    [======================================> ] 64%
    [==========================================> ] 71%
    [=============================================> ] 75%
    [============================================================] 100%
    Counting pages (2/6)
    [============================================================] Object 1 of 1
    Warning: Received createRequest signal on a disposed ResourceObject's NetworkAccessManager. This might be an indication of an iframe taking too long to load.
    Resolving links (4/6)
    [============================================================] Object 1 of 1
    Loading headers and footers (5/6)
    Printing pages (6/6)
    [> ] Preparing
    [============================================================] Page 1 of 1
    Done
    Exit with code 1 due to network error: ContentNotFoundError
    "
    stdout: ""
    command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" --lowquality --encoding "UTF-8" "C:\WINDOWS\TEMP\knp_snappy5a104ee3cc6652.63593218.html" "C:\WINDOWS\TEMP\knp_snappy5a104ee3cce479.20604760.pdf".

    Je veux donc pouvoir styliser le rendu (le pdf donc) avec une mise en forme personnelle.

    Voici mes code pour plus de détails:

    Controller:

      public function tirerListeDeLaClasseAction(Request $request, $as, $regime, $classeId)
      {
    
        $repoEleve  = $this->getDoctrine()->getManager()->getRepository('ISIBundle:Eleve');
        $repoClasse = $this->getDoctrine()->getManager()->getRepository('ISIBundle:Classe');
    
        $classe = $repoClasse->find($classeId);
        $eleves = $repoEleve->lesElevesDeLaClasse($as, $classeId);
    
        $snappy = $this->get("knp_snappy.pdf");
        $snappy->setOption("encoding", "UTF-8");
        $filename = "liste-de-classe-de-".$classe->getNiveau()->getLibelleFr()." - ".$classe->getLibelleClasseFr();
    
        $html = $this->renderView('ISIBundle:Scolarite:liste-de-la-classe.html.twig', [
          // "title" => "Titre de mon document",
          "classe" => $classe,
          "eleves" => $eleves,
        ]);
    
        return new Response(
            $snappy->getOutputFromHtml($html),
            200,
            [
                'Content-Type'        => 'application/pdf',
                'Content-Disposition' => 'inline; filename="'.$filename.'.pdf"'
            ]
        );
      }

    La vue pdf.html.twig

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="UTF-8" />
        <title>{% block title %}Accueil{% endblock %}</title>
        {% block stylesheets %}
            {# <link rel="stylesheet" type="text/css" href="../../vendor/semantic/ui/dist/semantic.min.css" /> #}
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/semantic.min.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/reset.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/site.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/grid.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/menu.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/input.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/icon.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/button.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/dropdown.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/transition.css" />
            <link rel="stylesheet" type="text/css" href="file:///C:/wamp64/www/markaz/vendor/semantic/ui/dist/components/popup.css" />
            
            <link rel="stylesheet" href="file:///C:/wamp64/www/markaz/web/css/style.css" />
    
            <lin rel="stylesheet" href="{{ asset('../vendor/twbs/bootstrap/dist/css/bootstrap.min.css') }}" />
        {% endblock %}
        <link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
    </head>
    
    <body>
        <header>
            <center>
                <img src="file:///C:/wamp64/www/markaz/web/images/en-tete.png" alt="">
            </center>
        </header>
        {% block body %} 
        {% endblock %}
    
        {% block javascripts %}
    
        <script>
            $(document).ready(function () {
                // configure the bootstrap datepicker
                $('.js-datepicker').datepicker({
                    format: 'dd-mm-yyyy'
                });
            });
        </script>
    
        {# Bundle JS routing #}
        {# <script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
        <script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script> #}
        {% endblock %}
    </body>
    
    </html>



    Vue twig qui étend pdf.html.twig, c'est cette vue même qui affiche mes données:

    {# ISIBundle/Ressources/views/Scolarite #} 
    {% extends "::pdf.html.twig" %} 
        {% block title %} Liste de classe - {{ parent()}} 
    {% endblock %}
    
    {% block body %}
    
        {% if eleves is empty %}
            <p>Inscrivez d'abord des élèves dans cette classe.</p>
        {% else %}
            <center>
                <h1>LISTE DE CLASSE</h1>
            </center>
            <div>
                <span>Classe: <span class="libelleClasse">{{classe.niveau.libelleFr}} - {{classe.libelleClasseFr}}</span></span>
            </div>
            {# {{dump(eleves)}} #}
            <table width="90%" class="">
                <thead>
                    <tr>
                        <th>N°</th>
                        <th>Matricule</th>
                        <th>Nom & Prénom</th>
                        <th><span class="">الاسم و اللقب</span></th>
                    </tr>
                </thead>
                <tbody>
                    {% set numero = 0 %}
                    {% for eleve in eleves %} 
                        {% set numero = numero + 1 %}
                        <tr>
                            <td>{{numero}}</td>
                            <td>{{eleve.matricule}}</td>
                            <td>{{eleve.nomFr}} {{eleve.pnomFr}}</td>
                            <td>{{eleve.nomAr}} {{eleve.pnomAr}}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        {% endif %}
    
    {% endblock %}

    Des idées pour me mettre sur la bonne voie me ferais énormément plaisir.

    • Partager sur Facebook
    • Partager sur Twitter

    Utiliser style personnel avec KnpSnappyBundle

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown