<?php
require('fpdf.php');
class PDF extends FPDF
function WriteHTML($sum)
{
// HTML parser
$sum = str_replace("\n",' ',$sum);
$a = preg_split('/<(.*)>/U',$sum,-1,PREG_SPLIT_DELIM_CAPTURE);
foreach($a as $i=>$e)
{
if($i%2==0)
{
// Text
if($this->HREF)
$this->PutLink($this->HREF,$e);
else
$this->Write(5,$e);
}
else
{
// Tag
if($e[0]=='/')
$this->CloseTag(strtoupper(substr($e,1)));
else
{
// Extract attributes
$a2 = explode(' ',$e);
$tag = strtoupper(array_shift($a2));
$attr = array();
foreach($a2 as $v)
{
if(preg_match('/([^=]*)=["\']?([^"\']*)/',$v,$a3))
$attr[strtoupper($a3[1])] = $a3[2];
}
$this->OpenTag($tag,$attr);
}
}
}
}
$sum = 1+2;
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
WriteHTML((string)$sum);
$pdf->Output();
?>