Alex (SirShurf) Frenkel's Blog

A web log of a PHP professional

How to use Zend-Framework-PDF-Table-Helper

with 10 comments

Here is the example of how to user ZendFramework PDF-Table-Helper.

You can get the code from GitHub here:

One of the prerequisites is that you mast have the zf_autoloader on and configured since I am relaying on it to auto load files.

first you have to in instantiate the class:

$pdf = new SirShurf_Pdf_TableSet ();

You can instantiate it with a Zend_PDF object and without it, in which case it will be created for you, but if you are instantating with Zend_PDF you have to tell the system on what page you are working (Default is page 0).

Now what you need it to initialise a Table you are going to work with:
$objTableRow = $table->addRow ();

Each table can have his own number of columns and settings.
Each table can have a different number of rows a row can be added using this method:

And as with HTML a row has a number of cells (or columns):
$objTableRow->addCol ( $strCourseId, array (
'bold' => false, 'colspan' => 1, 'align' => 'center'
) );
$objTableRow->addCol ( Labadmin_Models_Static::convertHebrew ( $this->view->translate ( 'LBL_GRADE_FORM_COURSE_ID' ) ), array (
'bold' => false, 'colspan' => 1, 'align' => 'center', 'font' => 'arial.ttf', 'fontBold' => 'arialbd.ttf'
) );

The Cell can have each own definitions as the example here shows, and you can iterate over the data to create it.

And finally you can call render(); in order to render the changes to PDF, or build(‘fileName’) to save the finale PDF to a file.

$pdf->build ( $strGradeFileLocation . $intTimeStamp . ".grade.pdf" );

Advertisements

Written by Alex (Shurf) Frenkel

July 26, 2011 at 3:15 pm

10 Responses

Subscribe to comments with RSS.

  1. Hi Alex,

    Can you please give us complete example on how to use this pdf table helper ?

    Thanks and Regards
    Durgaprasad

    Durgaprasad Budhwani

    August 21, 2011 at 10:30 am

    • I will create a more complete example for it.

      Alex (Shurf) Frenkel

      August 22, 2011 at 7:22 pm

      • Hi, where can I find your example please? Thanks for your great work.

        Johnny

        October 20, 2011 at 12:03 pm

      • What type of the example are you looking for? I can create one, it’s just that I think that the one I did was self explanatory…

        Can you tell me what do you need me to do an example of?

        Alex (Shurf) Frenkel

        October 20, 2011 at 8:25 pm

  2. Maybe I can help someone

    example:
    $pdf = new SirShurf_Pdf_TableSet();
    $table = $pdf->addTable();
    $objTableRow = $table->addRow();

    $objTableRow->addCol( ‘test1’ , array (‘font’ => ‘arial.ttf’,’size’=>10) );
    $objTableRow->addCol( ‘text2’ , array (‘font’ => ‘arial.ttf’,’size’=>10) );

    $filename = “export.pdf”;

    header(‘Content-type: application/pdf’);
    header(“Content-Disposition: attachment; filename=$filename”);

    Daniel Meyer

    January 17, 2012 at 1:46 pm

  3. What other file formats we can use rather than Pdf ?

    Zend Framework

    March 1, 2012 at 3:05 pm

  4. hello,
    how to add border to table?
    Thank you

    Jekin

    December 25, 2012 at 8:29 am


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: