Générer un pdf avec Html2Pdf
Bonjour
J'ai un formulaire qui me renvoi les données saisies sur une autre page (afficherform.php) que je veux par la suite imprimer.
J'utilise la librairie Html2Pdf. Mon code ne fonctionne pas, je n'arrive pas à générer le pdf, quelqu'un pourrait-il m'aider svp ? Merci
Voici mon code pour télécharger et imprimer en pdf:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| <?php/**
* Html2Pdf Library - example
*
* HTML => PDF converter
* distributed under the OSL-3.0 License
*
* @package Html2pdf
* @author Laurent MINGUET <webmaster@html2pdf.fr>
* @copyright 2017 Laurent MINGUET
*/
require_once dirname(__FILE__).'/../vendor/autoload.php';
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
try {
ob_start();
include dirname(__FILE__).'afficherform.php';
$content = ob_get_clean();
$html2pdf = new Html2Pdf('P', 'A4', 'fr');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content);
$html2pdf->output('exemple01.pdf');
} catch (Html2PdfException $e) {
$html2pdf->clean();
$formatter = new ExceptionFormatter($e);
echo $formatter->getHtmlMessage();
} |
Voici mon fichier afficherform.php
:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| <?phprequire_once 'connexion.php';
// On vérifie si la variable existe et sinon elle vaut NULL
$num = isset($_POST['num']) ? $_POST['num'] : NULL;
$client = isset($_POST['client']) ? $_POST['client'] : NULL;
$prestation = isset($_POST['prestation']) ? $_POST['prestation'] : NULL;
$nbjours = isset($_POST['nbjours']) ? $_POST['nbjours'] : NULL;
$tarifjour = isset($_POST['tarifjour']) ? $_POST['tarifjour'] : NULL;
//$montantHT = isset($_POST['montantHT']) ? $_POST['montantHT'] : NULL;
// $req = $base->prepare('INSERT INTO facturation (num, client, prestation, nbjours, tarifjour)
// VALUES ("'.$num.'", "'.$client.'", "'.$prestation.'", "'.$nbjours.'", "'.$tarifjour.'")');
// $req->execute(array( 'num' => $num,
// 'client' => $client,
// 'prestation'=> $prestation,
// 'nbjours'=> $nbjours,
// 'tarifjour'=> $tarifjour ));
// //echo "les données ont bien étés insérées dans la base de données";
// $base = null;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Afficher une Facture</title>
<link rel="stylesheet" href="style.css" media="all" />
</head>
<body>
<header class="clearfix">
<div id="logo">
<img src="logo.png">
</div>
<div id="company">
<h2 class="name">Micro-Entreprise hebergement</h2>
<div>
<p>RUE RÉTIMARE LOGT 0xx, IMM. ADOLPHE ADAM
76190 PARIS,<br/> Inscrite au registre du commerce et des sociétés de Rouen sous le n° xxx xxxx xxxx<br/> Représentée par hebergement agissant en qualité de gérante
</P>
</div>
</div>
</div>
</header>
<main>
<div id="details" class="clearfix">
<div id="client">
<div class="to"><h2>Facture à:</h2> <?php echo $client ?></div>
</div>
<div id="invoice">
<h1>FACTURE N° <?php echo $num ?></h1>
<div class="date">Date: <?php echo date("d-m-Y"); ?></div>
</div>
</div>
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th class="no">#</th>
<th class="desc">PRESTATION</th>
<th class="qty">NOMBRE DE JOURS</th>
<th class="unit">TARIF JOURNALIER</th>
<th class="total">TOTAL HT</th>
</tr>
</thead>
<tbody>
<tr>
<td class="no">01</td>
<td class="desc"><?php echo $prestation ?></td>
<td class="qty"><?php echo $nbjours ?></td>
<td class="unit"><?php echo $tarifjour ?></td>
<td class="total"><?php echo $tarifjour * $nbjours ?></td>
</tr>
</tbody>
<tfoot>
<!-- <tr>
<td colspan="2"></td>
<td colspan="2">SUBTOTAL</td>
<td>$5,200.00</td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">TAX 25%</td>
<td>$1,300.00</td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">GRAND TOTAL</td>
<td>$6,500.00</td>
</tr> -->
</tfoot>
</table>
<div id="notices">
<div><h2>Moyen de paiement:</h2></div>
<div class="notice">A verser au compte de :<br/>
Mlle hebergement<br/>
RIB : xxxxxxxxxxxxxxx / Banque : BNP PARIBAS<br/>
IBAN : FR76 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx / BIC : xxxxxxxxxxxxxxxxxxxx</div>
</div>
<a href="imprimer.php" target="_blank">Imprimer</a>
</main>
<?php require_once('includes/footer.php') ?>
</body>
</html> |