Reputation: 361
I am trying to convert an html code which has tables and background images to pdf. I have used fpdf, dompdf, tcpdf and html2pdf available on internet. I can either use tables or div tags with background properties, width etc. It converts the html to pdf but does not pickup many attributes like background image, width, height, etc.
Is there a code which i can use to make pdf as it is displayed in html.
In using div tags i have seen it displays data but in vertical way i.e. 1st one will be displayed in line 1 and the others in line 2,3,4,5.
DOMPDF CODE:
<?php
Include("dompdf/dompdf_config.inc.php");
$html = <<<'ENDHTML'
<html>
<body>
<div style="position:absolute;top:38;left:89"><img width="665" height="156" src="daso_template/header.jpg" ALT=""></div>
<div style="position:absolute;top:196;left:84"><img width="668" height="113" src="daso_template/MB-1.jpg" ALT=""></div>
<div style="position:absolute;top:58;left:326"><span class="ft0"> </span></div>
<div style="position:absolute;top:51;left:381"><span class="ft1"> Deliverable Authorization Sign-off</span></div>
<div style="position:absolute;top:120;left:89"><span class="ft5">Project No.:</span> </div>
</body>
</html>
ENDHTML;
$dompdf->load_html($html);
$dompdf->render();
This is just one code, it produces a pdf but not with formatting and background images.
Please do help, appreciate it.
$dompdf->stream("hello.pdf"); ?>
Upvotes: 0
Views: 4963
Reputation: 1817
I think you should go with "MPDF", which supports html for generating pdf.
<?php
$html = '
<h1><a name="top"></a>mPDF</h1>
<h2>Basic HTML Example</h2>
This file demonstrates most of the HTML elements.
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
<p>P: Nulla felis erat, imperdiet eu, ullamcorper non, nonummy quis, elit. Suspendisse potenti. Ut a eros at ligula vehicula pretium. Maecenas feugiat pede vel risus. Nulla et lectus. Fusce eleifend neque sit amet erat. Integer consectetuer nulla non orci. Morbi feugiat pulvinar dolor. Cras odio. Donec mattis, nisi id euismod auctor, neque metus pellentesque risus, at eleifend lacus sapien et risus. Phasellus metus. Phasellus feugiat, lectus ac aliquam molestie, leo lacus tincidunt turpis, vel aliquam quam odio et sapien. Mauris ante pede, auctor ac, suscipit quis, malesuada sed, nulla. Integer sit amet odio sit amet lectus luctus euismod. Donec et nulla. Sed quis orci. </p>
<hr />
<div><img src="tiger.wmf" style="float:right;">DIV: Proin aliquet lorem id felis. Curabitur vel libero at mauris nonummy tincidunt. Donec imperdiet. Vestibulum sem sem, lacinia vel, molestie et, laoreet eget, urna. Curabitur viverra faucibus pede. Morbi lobortis. Donec dapibus. Donec tempus. Ut arcu enim, rhoncus ac, venenatis eu, porttitor mollis, dui. Sed vitae risus. In elementum sem placerat dui. Nam tristique eros in nisl. Nulla cursus sapien non quam porta porttitor. Quisque dictum ipsum ornare tortor. Fusce ornare tempus enim. </div>
';
include("../mpdf.php");
$mpdf=new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
?>
Upvotes: 1