php to pdf
<?php
//install Dompdf library at link below:
//https://github.com/dompdf/dompdf
use Dompdf\Dompdf;
session_start();
// Include the database
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$html = '<table border=1>';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th>ID</th>';
$html .= '<th>Collum1</th>';
$html .= '<th>Collum2</th>';
$html .= '<th>Collum3</th>';
$html .= '</tr>';
$html .= '</thead>';
$html .= '<tbody>';
$sql = "SELECT * FROM tableName";
$sql = mysqli_query($conn, $sql);
while($row = mysqli_fetch_assoc($sql)){
$html = ''; // your html code
}
// include autoloader
require_once("dompdf/autoload.inc.php");
//Create instance
$dompdf = new DOMPDF();
// Upload your HTML code
$dompdf->load_html('
<h1 style="text-align: center;">RentCar</h1>
'. $html .'
');
//Render html
$dompdf->render();
//Create and output the pdf
$pdf = $dompdf->output();
//Visualize the page
$dompdf->stream(
"form.pdf",
array(
"Attachment" => false //To download turn it to true, to preview pdf turn it to false
)
);
?>
4.5
6
Important: Please note that this answer was written in 2009 and it might not be the most cost-effective solution today in 2019. Online alternatives are better today at this than they were back then.
Here are some online services that you can use:
PDFShift
Restpack
PDF Layer
DocRaptor
HTMLPDFAPI
HTML to PDF Rocket
Have a look at PrinceXML.
It's definitely the best HTML/CSS to PDF converter out there, although it's not free (But hey, your programming might not be free either, so if it saves you 10 hours of work, you're home free (since you also need to take into account that the alternative solutions will require you to setup a dedicated server with the right software)
Oh yeah, did I mention that this is the first (and probably only) HTML2PDF solution that does full ACID2 ?
PrinceXML Samples
Thank you!
6
0
Are there any code examples left?
New code examples in category PHP
-
PHP 2022-03-27 22:40:03 index:of curiosa 2019 mp4
-
PHP 2022-03-27 22:35:13 Dijkstra’s algorithm php
-
PHP 2022-03-27 22:35:12 get_declared_classes
-
PHP 2022-03-27 22:30:23 php move index of a value to first position in array
-
PHP 2022-03-27 22:25:01 wordpress get_date
-
PHP 2022-03-27 21:30:38 php shorten string with dots
-
PHP 2022-03-27 21:10:46 php header 500
-
PHP 2022-03-27 21:05:06 laravel schedule run
-
PHP 2022-03-27 20:25:12 Get page title, excerpt or content by id
-
PHP 2022-03-27 20:00:27 php convert date from dd/mm/yyyy to yyyy-mm-dd