I am trying to generate PDF using a very simple HTML. However, it contains 5 images (less than 50KB in total).
It is generating PDF very slow. It's taking over 12 second to generate the PDF. I am running on Windows 10 (i5-4590) with XAMPP.
Below is my code:
<?php
require_once 'dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$dompdf = new DOMPDF();
$html = <<<EOD
<html>
<head>
<style type="text/css">
html {
margin: 1%;
padding: 0;
}
.header,
.footer {
width: 100%;
text-align: center;
position: fixed;
font-size: 26px;
}
.header {
top: 0px;
}
.footer {
bottom: 18px;
}
.center {
margin: 0 auto;
}
.divTable{
display: table;
width: 100px;
text-align: center;
margin: 0 auto;
}
.divTableRow {
display: table-row;
}
.divTableHeading {
margin: 0 auto;
}
.divTableCell, .divTableHead {
display: table-cell;
padding: 0 33px;
}
.bottom .divTableCell {
padding-top: 30px;
}
.divTableHeading {
display: table-header-group;
font-weight: bold;
}
.divTableFoot {
display: table-footer-group;
font-weight: bold;
}
.divTableBody {
display: table-row-group;
}
div.img-border img {
border-style: solid solid solid solid;
border-width: 2px 2px 2px 2px;
border-color: #eb0089;
}
</style>
</head>
<body>
<div class="center">
<div class="divTable top">
<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell" style="padding-left:0px;"><div class="img-border"><img src="300-small.png"></div></div>
<div class="divTableCell"><div class="img-border"><img src="300-small.png"></div></div>
<div class="divTableCell" style="padding-right:0px;"><div class="img-border"><img src="300-small.png"></div></div>
</div>
</div>
</div>
<div class="divTable bottom">
<div class="divTableBody">
<div class="divTableRow">
<div class="divTableCell" style="padding-left:0px;"><div class="img-border"><img src="300-large.png"></div></div>
<div class="divTableCell" style="padding-right:0px;"><div class="img-border"><img src="300-large.png"></div></div>
</div>
</div>
</div>
</div>
<div class="footer">
$customer_title - $customer_order_number
</div>
</body>
</html>
EOD;
$dompdf->set_option( 'dpi' , '300' );
$dompdf->load_html($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream("sample.pdf", array("Attachment"=>0));
I am failing to understand on how to make it process faster.
In the third DIV of the first table row you forgot a closing quote for the class
attribute:
<div class="divTableCell style="padding-right:0px;">
should be
<div class="divTableCell" style="padding-right:0px;">
And the same error again in the second DIV of the second row.
I have also pdf download loading issue because of image.
Must convert image into base64 then put base64 string to img src attribute
Ex. <img src="data:image/png;base64,'.$base64String.'" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.