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