problème au cours de reduire fichier pdf

Par med001, il y a 10 ans


Salut,J'utilise bundle html2pdf pour reduire un fichier pdf mais je trouve ce problème

quelle est la solution et merci d'avance

6 réponses

Lartak, il y a 10 ans

Bonjour.
Il s'emblerait tout simplement que tu utilises une balise <script> dans ton code pour générer le fichier PDF, sauf qu'à priori ce n'est pas supporté par HTML2PDF.

med001, il y a 10 ans

donc quelle est la solution ??

Lartak, il y a 10 ans

La solution est de ne pas utiliser de balise <script> dans ton code pour générer les PDF.

med001, il y a 10 ans

mais j'utilise pas la balisde <script>

voila code du service facture qui permet de générer les PDF

<?php namespace ventenligneBundle\Services; use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\DependencyInjection\ContainerInterface; class GetFacture { public function __construct(ContainerInterface $container) { $this->container = $container; } public function facture($facture) { $html = $this->container->get('templating')->render('UserBundle:Default:layout/facturePDF.html.twig', array('facture' => $facture)); $html2pdf = new \Html2Pdf_Html2Pdf('P','A4','fr'); $html2pdf->pdf->SetAuthor('DevAndClick'); $html2pdf->pdf->SetTitle('Facture '.$facture->getReference()); $html2pdf->pdf->SetSubject('Facture DevAndClick'); $html2pdf->pdf->SetKeywords('facture,devandclick'); $html2pdf->pdf->SetDisplayMode('real'); $html2pdf->writeHTML($html); $html2pdf->Output('Facture.pdf'); $response = new Response(); $response->headers->set('Content-type' , 'application/pdf'); return $response; } }
Lartak, il y a 10 ans

mais j'utilise pas la balisde

S'il détecte une balise <script>, c'est quelle doit y être, il ne l'invente pas.
Montres le contenu de ta page facturePDF.html.twig.

med001, il y a 10 ans

oui Lartak ,il y'a des balises <script> en page twig , mais maintenant , je fais 2 methodes pour generere fichier twig l'un pour utilisateur et la deuxiéme pour admin, la méthode pour admin fonctionne mai methode pour utilisateur je trouve ce probleme

la methode en controller :

public function facturesPDFAction($id) { $em = $this->getDoctrine()->getManager(); $facture = $em->getRepository('ventenligneBundle:Commandes')->findOneBy(array('utilisateur' => $this->getUser(), 'valider' => 1, 'id' => $id)); if (!$facture) { $this->get('session')->getFlashBag()->add('error', 'Une erreur est survenue'); return $this->redirect($this->generateUrl('facutres')); } $this->container->get('setNewFacture')->facture($facture)->Output('Facture.pdf'); $response = new Response(); $response->headers->set('Content-type' , 'application/pdf'); return $response; }

fichier facturePDF.html.twig

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Facture</title> <link rel="stylesheet" href="{{ asset ('bundles/crud/css/bootstrap.css') }}" /> <link rel="stylesheet" href="{{ asset ('bundles/crud/css/bootstrap-responsive.css') }}" /> <link rel="stylesheet" href="{{ asset ('bundles/crud/css/style.css') }}" /> <link rel="stylesheet" href=" {{ asset ('bundles/crud/css/font-awesome.css') }}" /> <link href=" {{ asset ('bundles/crud/css/facture.css') }}" rel="stylesheet" /> </head> <body style="background-color:#444;"> <h1>DevAndClick</h1> <table id="enTete"> <tr> <td colspan="1"></td> <td colspan="1"><h1>Facture</h1></td> <td colspan="1"></td> </tr> <tr> <td width="80">Page</td> <td width="100">Date</td> <td width="120">Ref</td> </tr> <tr> <td class="color">[[page_nb]]</td> <td class="color">{{ facture.date|date('d-m-Y') }}</td> <td class="color">{{ facture.reference }}</td> </tr> </table> <ul id="coordonnes"> <li>{{ facture.commande.facturation.nom }} {{ facture.commande.facturation.prenom }}</li> <li>{{ facture.commande.facturation.adresse}}</li> <li>{{ facture.commande.facturation.cp }} {{ facture.commande.facturation.ville }} - {{ facture.commande.facturation.pays }}</li> </ul> <table id="entity"> <tr> <td width="280">DESIGNATION</td> <td width="105">QUANTITE</td> <td width="100">P.U - HT</td> <td width="105">MONTANT HT</td> <td width="105">MONTANT TTC</td> </tr> {% for produit in facture.commande.produit %} <tr> <td class="color">{{ produit.reference }}</td> <td class="color">{{ produit.quantite }}</td> <td class="color">{{ produit.prixHT }} €</td> <td class="color">{{ produit.prixHT * produit.quantite }} €</td> <td class="color">{{ produit.prixTTC * produit.quantite }} €</td> </tr> {% endfor %} </table> <table id="total"> <tr> <td width="110">TOTAL HT :</td> <td width="100" class="color">{{ facture.commande.prixHT }} €</td> </tr> {% for key, tva in facture.commande.tva %} <tr> <td width="110">TVA <span class="color min">{{ key }}</span> :</td> <td width="100" class="color">{{ tva }} €</td> </tr> {% endfor %} <tr> <td width="110">TOTAL TTC :</td> <td width="100" class="color">{{ facture.commande.prixTTC }} €</td> </tr> </table> <div id="footer"> </div> </body> </html>

quelle est la solution et merci d'avance