HTML2PDF

Télécharger au format docx, pdf ou txt
Télécharger au format docx, pdf ou txt
Vous êtes sur la page 1sur 13

HTML2PDF

HTML2PDF est un convertisseur de code HTML en PDF crit en PHP.


Vous pouvez tlcharger le code source du logiciel cette adresse : html2pdf.fr

Installation HTML2PDF
Aprs avoir tlcharger la source, placez le plugin dans le dossier de votre choix de votre projet.

Cration d'un PDF

<?php
ob_start();
?>
<style type="text/css">
<!-table
{
width: 100%;
border:none;
border-collapse: collapse;
}
th
{
text-align: center;
border: solid 1px #eee;
background: #f8f8f8;
}
td
{
text-align: center;
border: solid 1px #eee;
}
-->
</style>
<table>
<col style="width: 33%">
<col style="width: 33%">
<col style="width: 33%">

<tr>
<th>Nom</th>
<th>Prnom</th>
<th>Ville</th>
</tr>
<tr>
<td>ENGEL</td>
<td>Olivier</td>
<td>New York</td>
</tr>
<tr>
<td>Batman</td>
<td>Bruce</td>
<td>Gotham</td>
</tr>
</table>
<?php
$content = ob_get_clean();
require_once( __DIR__ . "/html2pdf.class.php");
try
{
$html2pdf = new HTML2PDF("P", "A4", "fr");
$html2pdf->setDefaultFont("Arial");
$html2pdf->writeHTML($content);
$html2pdf->Output("votre_pdf.pdf");
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;

}
?>

Cration d'un PDF depuis une page externe


<?php
ob_start();
include( "votre_fichier_html.php" );
$content = ob_get_clean();
require_once( __DIR__ . "/html2pdf.class.php");
try
{
$html2pdf = new HTML2PDF("P", "A4", "fr");
// $html2pdf->setModeDebug();
$html2pdf->setDefaultFont("Arial");
$html2pdf->writeHTML($content);
$html2pdf->Output("votre_pdf.pdf");
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
?>

Crer une facture/commande en PDF

Pour crer la commande suivante :

<?php
ob_start();
?>
<style type="text/css">
<!-table
{
width: 100%;
border:none;
border-collapse: collapse;
}
th
{
text-align: center;
border: solid 1px #eee;
background: #f8f8f8;
}
td
{
text-align: center;

}
.dataTable td{
padding:10px 5px;
background-color:#efefef;

}
.dataTable th{
padding:10px 5px;
}
-->
</style>
<page style="font-size: 12pt" backimg="./images/sign.png" backimgy="bottom">
<table cellspacing="0" style="width: 100%; text-align: center; font-size: 14px">
<tr>
<td style="width: 25%; color: #444444;">
<img style="width: 100%;" src="./images/cssw_logo.png" alt="Logo"><br><br>
COMMANDE CSSW
</td>
<td style="width: 75%;">
<table cellspacing="0" style="width: 100%; text-align: left; font-size: 11pt;">
<tr>
<td style="width:50%;"></td>
<td style="width:14%;text-align:left; ">Client</td>
<td style="width:36%">M. Bruce Wayne</td>
</tr>
<tr>
<td style="width:50%;"></td>
<td style="width:14%;text-align:left; ">Adresse</td>
<td style="width:36%">
Rsidence Bruce Wayne<br>
1 ALLEE CHAUVE SOURIS<br>
00 000 - Gotham<br>

</td>
</tr>
<tr>
<td style="width:50%;"></td>
<td style="width:14%;text-align:left; ">Mail</td>
<td style="width:36%">batman@gotham.com</td>
</tr>
<tr>
<td style="width:50%;"></td>
<td style="width:14%;text-align:left; ">BatTel</td>
<td style="width:36%">33 (0) 1 00 00 00 00</td>
</tr>
</table>

<barcode type="EAN13" value="123467891245" style="margin-left:100mm;margin-top:10mm;width: 30mm; height: 12mm; font-size: 4


</td>
</tr>
</table>
<br>
<br>
<table cellspacing="0" style="width: 100%; text-align: left;font-size: 10pt">
<tr>
<td style="width:50%;"></td>
<td style="width:50%; ">Gotam City, le 23/11/2013</td>
</tr>
</table>
<br>
<i>

<b><u>Objet </u>: &laquo; Problme de costume &raquo;</b><br><br>


Compte client : 004560100001<br>
Rfrence du Dossier : 5406666<br>
</i>
<br>
<br>
Madame, Monsieur, SuperHero, Cher Client,<br>
<br>
<br>
Voici votre commande: <br />
<br>
<table class="dataTable" cellspacing="0" style="width: 100%; border: solid 1px black; background: #E7E7E7; text-align: center; font-size: 10pt;">
<tr>
<th style="width: 20%">Produit</th>
<th style="width: 20%">Dsignation</th>
<th style="width: 20%">Prix Unitaire</th>
<th style="width: 20%">Quantit</th>
<th style="width: 20%">Prix Net</th>
</tr>
</table>
<table class="dataTable" cellspacing="0" style="width: 100%; border: solid 1px black; background: #E7E7E7; text-align: center; font-size: 10pt;">
<tr>
<td style="width: 20%">Oreilles</td>
<td style="width: 20%">Oreille pour costume</td>
<td style="width: 20%; text-align:right;">1 500 &euro;</td>
<td style="width: 20%; text-align:right;">4x</td>
<td style="width: 20%; text-align:right;">6 000 &euro;</td>
</tr>
<tr>
<td style="width: 20%">Cape</td>

<td style="width: 20%">Cape pour costume</td>


<td style="width: 20%; text-align:right;">100 &euro;</td>
<td style="width: 20%; text-align:right;">3x</td>
<td style="width: 20%; text-align:right;">300 &euro;</td>
</tr>
<tr>
<th style="width: 20%;"></th>
<th style="width: 20%;"></th>
<th style="width: 20%;"></th>
<th style="width: 20%; text-align:right;">Total</th>
<th style="width: 20%; text-align:right;">6 300 &euro;</th>
</tr>
</table>
</page>
<br /><br /><br /><br /><br />
A bientt,
<br /><br /><br /><br />
Olivier ENGEL.
<?php
$content = ob_get_clean();
require_once( __DIR__ . "/html2pdf.class.php");
try
{
$html2pdf = new HTML2PDF("P", "A4", "fr");
$html2pdf->setDefaultFont("Arial");
$html2pdf->writeHTML($content);

$html2pdf->Output("votre_pdf.pdf");
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
?>

Vous pouvez visualiser le PDF Commande PDF

Vous aimerez peut-être aussi