1 | <?php
|
---|
2 | /**
|
---|
3 | * Html2Pdf Library - example
|
---|
4 | *
|
---|
5 | * HTML => PDF converter
|
---|
6 | * distributed under the OSL-3.0 License
|
---|
7 | *
|
---|
8 | * @package Html2pdf
|
---|
9 | * @author Laurent MINGUET <webmaster@html2pdf.fr>
|
---|
10 | * @copyright 2017 Laurent MINGUET
|
---|
11 | */
|
---|
12 | require_once dirname(__FILE__).'/../vendor/autoload.php';
|
---|
13 |
|
---|
14 | use Spipu\Html2Pdf\Html2Pdf;
|
---|
15 | use Spipu\Html2Pdf\Exception\Html2PdfException;
|
---|
16 | use Spipu\Html2Pdf\Exception\ExceptionFormatter;
|
---|
17 |
|
---|
18 | if (isset($_SERVER['REQUEST_URI'])) {
|
---|
19 | $generate = isset($_GET['make_pdf']);
|
---|
20 | $nom = isset($_GET['nom']) ? $_GET['nom'] : 'inconnu';
|
---|
21 | $url = dirname($_SERVER['REQUEST_URI']);
|
---|
22 | if (substr($url, 0, 7)!=='http://') {
|
---|
23 | $url = 'http://'.$_SERVER['HTTP_HOST'].$url;
|
---|
24 | }
|
---|
25 | } else {
|
---|
26 | $generate = true;
|
---|
27 | $nom = 'spipu';
|
---|
28 | $url = 'http://localhost/html2pdf/examples/';
|
---|
29 | }
|
---|
30 |
|
---|
31 | $nom = substr(preg_replace('/[^a-zA-Z0-9]/isU', '', $nom), 0, 26);
|
---|
32 | $url.= '/res/example09.png.php?px=5&py=20';
|
---|
33 |
|
---|
34 |
|
---|
35 | if ($generate) {
|
---|
36 | ob_start();
|
---|
37 | } else {
|
---|
38 | ?>
|
---|
39 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
40 | <html>
|
---|
41 | <head>
|
---|
42 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
|
---|
43 | <title>Exemple d'auto génération de PDF</title>
|
---|
44 | </head>
|
---|
45 | <body>
|
---|
46 | <?php
|
---|
47 | }
|
---|
48 | ?>
|
---|
49 | <br>
|
---|
50 | Ceci est un exemple de génération de PDF via un bouton :)<br>
|
---|
51 | <br>
|
---|
52 | <img src="<?php echo $url; ?>" alt="image_php" ><br>
|
---|
53 | <br>
|
---|
54 | <?php
|
---|
55 | if ($generate) {
|
---|
56 | ?>
|
---|
57 | Bonjour <b><?php echo $nom; ?></b>, ton nom peut s'écrire : <br>
|
---|
58 | <barcode type="C39" value="<?php echo strtoupper($nom); ?>" style="color: #770000" ></barcode><hr>
|
---|
59 | <br>
|
---|
60 | <?php
|
---|
61 | }
|
---|
62 | ?>
|
---|
63 | <br>
|
---|
64 | <?php
|
---|
65 | if ($generate) {
|
---|
66 | $content = ob_get_clean();
|
---|
67 |
|
---|
68 | try {
|
---|
69 | $html2pdf = new Html2Pdf('P', 'A4', 'fr');
|
---|
70 | $html2pdf->writeHTML($content);
|
---|
71 | $html2pdf->output('example09.pdf');
|
---|
72 | exit;
|
---|
73 | } catch (Html2PdfException $e) {
|
---|
74 | $html2pdf->clean();
|
---|
75 |
|
---|
76 | $formatter = new ExceptionFormatter($e);
|
---|
77 | echo $formatter->getHtmlMessage();
|
---|
78 | exit;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | ?>
|
---|
82 | <form method="get" action="">
|
---|
83 | <input type="hidden" name="make_pdf" value="">
|
---|
84 | Ton nom : <input type="text" name="nom" value=""> -
|
---|
85 | <input type="submit" value="Generer le PDF" >
|
---|
86 | </form>
|
---|
87 | </body>
|
---|
88 | </html>
|
---|