Output a HTML Table to file PDF use FPDF


Informations

Class: PDFTable
Author: vietcom
License: Freeware
Version: 1.95 (15 Mar 2012) View log file

In this class, I use class HTMLParser from Jose Solorzano and class FPDF from Olivier PLATHEY
Special thanks to Vincent Tomi for ver 1.3

Description

This script allows you to print a HTML table to file PDF.

It supports the follow tags:

Doesn't support yet:

Special note:

Example

<?php
$html = <<<MYTABLE
  <table border="1" align="center">
    <tr>
      <td rowspan="2" valign="middle" border="0">rowspan=2, valign=middle</td>
      <td>Normal</td>
      <td>Normal</td>
      <td>Normal</td>
      <td colspan="2" rowspan="2" valign="bottom" bgcolor="#FF00FF">colspan=2<br>rowspan=2<br>valign=bottom</td>
    </tr>
    <tr>
      <td height="15">Normal</td>
      <td rowspan="2" align="right" bgcolor="#aaaaaa" border="0">rowspan=2</td>
      <td border="0">border=0</td>
    </tr>
    <tr>
      <td>Normal</td>
      <td>Normal</td>
      <td>Normal</td>
      <td rowspan="3" valign="top" bgcolor="#CC3366">rowspan=3</td>
      <td>Normal</td>
    </tr>
    <tr bgcolor="#cccccc">
      <td>Normal</td>
      <td colspan="3" align="center">align center, colspan=3</td>
      <td>Normal</td>
    </tr>
    <tr>
      <td align="right" valign="bottom">align=right<br>valign=bottom</td>
      <td>Normal</td>
      <td>&nbsp;</td>
      <td>Normal</td>
      <td height="20">height=20</td>
    </tr>
  </table>
MYTABLE;
define('FPDF_FONTPATH','font/');
require('pdftable.inc.php');
$p = new PDFTable();
$p->AddPage();
$p->setfont('times','',12);
$p->htmltable($html);
$p->output('','I');
?>
Result in my browser (opera 7.5):
Result in your browser:
rowspan=2, valign=middle Normal Normal Normal colspan=2
rowspan=2
valign=bottom
Normal rowspan=2 border=0
Normal Normal Normal rowspan=3 Normal
Normal align center, colspan=3 Normal
align=right
valign=bottom
Normal   Normal height=20
Result in file pdf: example.pdf (Note: HTML dosen't support border='0' for each <td>)

Example 2

This file has a long table wrote on 3 pages: example2.pdf

Example 3

File with some fonts, colors, styles and Vietnamese font: example3.pdf

Source

Dowload here: pdftable v1.95