-
Notifications
You must be signed in to change notification settings - Fork 0
/
dompdf.php
87 lines (74 loc) · 2.74 KB
/
dompdf.php
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
<?php
require 'vendor/autoload.php';
use Dompdf\Dompdf;
use Dompdf\Options;
//option part
$options = new Options();
$options->set('defaultFont', 'Courier');
$dompdf = new Dompdf($options);
// PDF size option
$dompdf->setPaper('A4', '');
//you can add bootstrap and font awesome...
$html = '<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="jumbotron text-center">
<h1>Simple pdf generator using dompdf</h1>
<p>Perfect!! All things working... including fontawesome</p>
</div>
<div class="jumbotron">
<div class="row">
<div class="col-xs-3">
<div class="card border-info mx-xs-1 p-3">
<div class="text-info text-center mt-3"><h4>Cars</h4></div>
<div class="text-info text-center mt-2"><h1>234</h1></div>
</div>
</div>
<div class="col-xs-3">
<div class="card border-success mx-xs-1 p-3">
<div class="text-success text-center mt-3"><h4>Eyes</h4></div>
<div class="text-success text-center mt-2"><h1>9332</h1></div>
</div>
</div>
<div class="col-xs-3">
<div class="card border-danger mx-xs-1 p-3">
<div class="text-danger text-center mt-3"><h4>Hearts</h4></div>
<div class="text-danger text-center mt-2"><h1>346</h1></div>
</div>
</div>
</div>
</div>
<div class="container">
<i class="fa fa-car"></i>
<i class="fa fa-car" style="font-size:48px;"></i>
<i class="fa fa-car" style="font-size:60px;color:red;"></i>
</div>
</div>
</body>
</html>';
$dompdf->set_option('isHtml5ParserEnabled', true); //allow html5
$download = 0;
pdfGenerate($dompdf, $html, $download);
function pdfGenerate($dompdf, $html, $download) {
if ($download != 0) {
$dompdf->loadHtml($html);
$dompdf->render();
$dompdf->stream("download.pdf"); //download pdf
}
else {
$dompdf->loadHtml($html);
$dompdf->render();
$dompdf->stream("show.pdf", array("Attachment" => false)); //show you pdf not download
}
}
?>