I'm using floats to position 2 divs beside each other.
<a href="printbox.php">print</a>
<?php ob_start(); ?>
<style>
#sidedish{
float: left;
border: 1px solid black;
width: 100px;
height: 100px;
}
#maindish{
float: right;
width: 200px;
border: 1px solid black;
height: 100px;
text-align: center;
}
#container{
width: 304px;
height: 100px;
border: 1px solid black;
}
</style>
<div id="container">
<div id="sidedish"></div>
<div id="maindish"><div id="box">name</div></div>
</div>
<?php $_SESSION['boxes'] = ob_get_contents(); ?>
Here is what printbox do, it just renders the buffered data into a pdf, but somehow the floats that were set were lost in the process.
<?php require_once('html2pdf/html2pdf.class.php'); ?>
<?php
$html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8', array(0, 0, 0, 0));
$html2pdf->writeHTML($_SESSION['boxes']);
$html2pdf->Output('random.pdf');
?>
It works fine on html:
but when I click on print it turns to this:
Any idea what the problem is?
You can see the quick documentation online in french here: http://demo.html2pdf.fr/examples/pdf/about.pdf
('Les float ne sont gérés que pour la balise IMG')
= Floats are only handled for img markups by the class.
Handled css properties are also listed in the doc.
Speaking from personal experiences, I would say styling the output of
HTML2PDF
is, at best, esoteric black magic science. The main reasons for this are:To be fair, this is not only the issue for
HTML2PDF
but also for theTCPDF
thatHTML2PDF
uses.It might be possible that
HTML2PDF
, being just an almost-zero-setup, quick & easy alternative interface for theTCPDF
, cuts more CSS support off — but I'm sure that evenTCPDF
wouldn't supportfloat
properly.The best workaround that you could use is to send your floating divs to the nineties:
You could also hide this embarrassment from the public HTML: