Pregunta

having some problems rendering html when I convert to PDF. It's driving me mental and I don't know what's going on. The idea is that I have an html form in a mysql database which stores HTML tags and what not, I pull it out using PHP, render the HTML and display it as a PDF. My issue is that it won't render the HTML. it's just text and the formatting is way off. Here is the code I have so far:

$indemResult = mysqli_query($conn,"SELECT * FROM Indemnity");
$indemRow = mysqli_fetch_array($indemResult);
require('../include/PDFConverter/fpdf.php');
$pdf = new PDF();
$pdf->SetMargins(0,0,0);
$pdf->AddPage();
$pdf->SetFont('Arial','',12);

//Insert Banner
$pdf->Image('../assets/pdfBanner.png');
$pdf->Ln();
$pdf->Ln();

//Insert Indemnity form
$pdf->SetXY(50, 65);
$pdf->cMargin = 10;
$pdf->SetFont('Arial','',24);
$pdf->Cell(0, 10, $pdf->Write(1,'Indemnity Form'), 0, 1,'C', false);

$pdf->SetFont('Arial','',12);
$text=$pdf->WriteHTML(utf8_decode($indemRow['form']));
$wrap=$pdf->WordWrap($text,120);
$pdf->MultiCell(0,0,$pdf->Write($wrap, ''));
¿Fue útil?

Solución

My problem was in the WriteHTML class. It didn't support UL LI tags, so I used this instead:

http://fpdf.de/downloads/addons/53/

I stripped the createPDF class, in the class PDF extends FPDF I removed $_title, $_url, $_debug=false from the PDF function, I also removed $bi from the write HTML function and inside the writeHTML function I removed:

$this->bi=$bi;
        if ($bi)
            $html=strip_tags($html, "<a><img><p>
<font><tr><blockquote><h1><h2><h3><h4><pre><red><blue><ul><li><hr><b><i><u><strong><em>"); 

I hope this helps people who are trying to render HTML before putting it onto PDF

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top