I have been working extensively with tcpdf on a recent project of mine and I thought I would share some of the snippets and fixes I had to develop to get it to work the way I needed it to.
Lacking GIF support?
Not any more with the following code added to the TCPDF class.
/**
* Extract info from a GIF file
* @access protected
*/
protected function _parsegif($file) {
$a=GetImageSize($file);
if(empty($a)) {
$this->Error('Missing or incorrect image file: '.$file);
}
if($a[2]!=1) {
$this->Error('Not a GIF file: '.$file);
}
$tmp_filename = tempnam(K_PATH_CACHE,'img');
$img = imagecreatefromgif($file);
imagepng($img,$tmp_filename);
rename($tmp_filename, $tmp_filename . '.png');
return $this->_parsepng($tmp_filename . '.png');
}Recognize more html attributes
e.g. I need to be able to draw a "HR" in multiple colors and thicknesses. this is what I added to the tcpdf.php file in the case 'hr': section
if ((isset($attr['size'])) AND ($attr['size'] != '')) {
$hrSize = $attr['size'];
}
else {
$hrSize = 1;
}
if (isset($attr['color']) AND $attr['color']!='') {
$coul = $this->convertColorHexToDec($attr['color']);
$this->SetDrawColor($coul['R'],$coul['G'],$coul['B']);
} else {
$this->SetDrawColor(0);
}
$this->SetLineWidth(0.2*$hrSize);and then feed it the appropriate html like so:
<hr color="#ff0000" size="2">You get the idea - the attributes are stored in the $attr variable and mostly unused for you to extend the HTML writer anyway you want it to.
Problems with accented characters?
search for
$pattern = '/(<[^>]+>)/Uu';
and remove the 'u' in the end. you may get whacked if you are using utf8 characters but I have not seen a problem yet. Or you may choose to feed the writeHTML function strings that are passed through utf8_encode() in the pdfview.php file.