HTML to PDF conversion with external CSS support in Codeigniter
Finally i fixed the bug. The problem is loading image inside the view page. Here i am adding header with Company name and logo.
http://domain.com/assets/other_uploads/photo/photo.png
If i give the above source in image URL, it tries to load the image in my view page and it fails. So, i used the below code to fix this.
var/www/domain/assets/other_uploads/photo/photo.png
For external css issue, i added the css part in view page as internal css.
It works now!!!
function WriteHTML($html,$bi) { //remove all unsupported tags $this->bi=$bi; if ($bi) $html=strip_tags($html,"<a><img><p><br><font><tr><blockquote><h1><h2><h3><h4><pre><red><blue><ul><li><hr><b><i><u><strong><em>"); else $html=strip_tags($html,"<a><img><p><br><font><tr><blockquote><h1><h2><h3><h4><pre><red><blue><ul><li><hr>"); $html=str_replace("\n",' ',$html); //replace carriage returns with spaces // debug if ($this->debug) { echo $html; exit; } $html = str_replace('™','™',$html); $html = str_replace('©','©',$html); $html = str_replace('€','€',$html); $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE); $skip=false; foreach($a as $i=>$e) { if (!$skip) { if($this->HREF) $e=str_replace("\n","",str_replace("\r","",$e)); if($i%2==0) { // new line if($this->PRE) $e=str_replace("\r","\n",$e); else $e=str_replace("\r","",$e); //Text if($this->HREF) { $this->PutLink($this->HREF,$e); $skip=true; } else $this->Write(5,stripslashes(txtentities($e))); } else { //Tag if (substr(trim($e),0,1)=='/') $this->CloseTag(strtoupper(substr($e,strpos($e,'/')))); 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); } } } else { $this->HREF=''; $skip=false; } } }