1<?php
2//install Dompdf library at link below:
3//https://github.com/dompdf/dompdf
4use Dompdf\Dompdf;
5session_start();
6
7 // Include the database
8 $servername = "";
9 $username = "";
10 $password = "";
11 $dbname = "";
12
13 // Create connection
14 $conn = new mysqli($servername, $username, $password, $dbname);
15 // Check connection
16 if ($conn->connect_error) {
17 die("Connection failed: " . $conn->connect_error);
18 }
19
20 $html = '<table border=1>';
21 $html .= '<thead>';
22 $html .= '<tr>';
23 $html .= '<th>ID</th>';
24 $html .= '<th>Collum1</th>';
25 $html .= '<th>Collum2</th>';
26 $html .= '<th>Collum3</th>';
27 $html .= '</tr>';
28 $html .= '</thead>';
29 $html .= '<tbody>';
30
31 $sql = "SELECT * FROM tableName";
32 $sql = mysqli_query($conn, $sql);
33 while($row = mysqli_fetch_assoc($sql)){
34 $html = ''; // your html code
35 }
36
37 // include autoloader
38 require_once("dompdf/autoload.inc.php");
39
40 //Create instance
41 $dompdf = new DOMPDF();
42
43 // Upload your HTML code
44 $dompdf->load_html('
45 <h1 style="text-align: center;">RentCar</h1>
46 '. $html .'
47 ');
48
49 //Render html
50 $dompdf->render();
51
52 //Create and output the pdf
53 $pdf = $dompdf->output();
54
55 //Visualize the page
56 $dompdf->stream(
57 "form.pdf",
58 array(
59 "Attachment" => false //To download turn it to true, to preview pdf turn it to false
60 )
61 );
62
63?>