PHP Classes
elePHPant
Icontem

File: XFPDFTest.php

Recommend this page to a friend!
  Classes of Stefan Kientzler  >  PHP PDF Table using FPDF  >  XFPDFTest.php  >  Download  
File: XFPDFTest.php
Role: Example script
Content type: text/plain
Description: Example Datagrid
Class: PHP PDF Table using FPDF
Generate PDF documents with tables displaying data
Author: By
Last change: demonstrates new functions for
- total, subtotals and carryover
- formating for currency, number and datetime
Date: 9 days ago
Size: 1,957 bytes
 

 

Contents

Class file image Download
<?php
require_once 'lib/XFPDF/xfpdf.php';
require_once
'XFPDFExample.class.php';

   
   
$pdf = new ExampleXPDF();
   
   
// set some file informationv and generall settings
   
$pdf->SetInfo( 'XFPDF', 'Example', 'PHP classes');
   
$pdf->AddPageHeader('Create PDF Table', 'images/elephpant.png', 'using extended FPDF class');
   
$pdf->InitGrid('xfpdf-sample.json');

   
// playing with fonts and colors...
    /*
     * -> xfpdf-sample.json contains all settings :-)
     *
    $pdf->SetHeaderFont('Times', 'B', 14);
    $pdf->SetSubHeaderFont('Arial', '', 10);
    $pdf->SetColHeaderColors('#FFF', '#4F5B93');
    $pdf->SetRowColors('#000', '#000', '#CCF');
   
    $pdf->EnableTotals(XPDF::TOTALS | XPDF::SUBTOTALS | XPDF::CARRY_OVER);
    $pdf->SetTotalsText('Totals', 'Subtotals', 'Carry over');
    */
   
   
$pdf->SetNumberFormat(1, '', ' kg');
   
   
// prepare grid and just insert a bulk of lines
   
$pdf->Prepare();
   
$date = time();
   
$iGroup = 1;
   
   
// enable totals and pagetotals
   
$pdf->EnableTotals(XPDF::TOTALS | XPDF::PAGE_TOTALS);

   
// definition of the cols to be calculated for totals/subtotals see
    // constructor of ExampleXPDF
   
    // to start group for subtotals
   
$pdf->StartGroup('Totals Group ' . $iGroup . ':', 'Group ' . $iGroup);
    for (
$iRow=1; $iRow <= 100; $iRow++) {
       
// most cases data comes from DB-query ;-)
       
$row = array(
           
'field1' => 'Text in first Col, Line ' . $iRow,
           
'field2' => 'second Col Line ' . $iRow,
           
'field3' => date('Y-m-d', $date),
           
'field4' => (rand(10, 2000) / 9),
           
'field5' => (rand(10, 500) / 10)
        );
       
$pdf->Row($row);
       
$date += 24 * 60 * 60;
        if (
$iRow % 32 == 0) {
           
// just to demosntrate subtotals...
            // ... ed group and start next!
           
$pdf->EndGroup();
           
$pdf->StartGroup('Totals Group ' . ++$iGroup . ':', 'Group ' . $iGroup);
        }
    }
   
// for subtotals of last group...
   
$pdf->EndGroup();
   
// ...and end of the grid
   
$pdf->EndGrid();
   
   
$pdf->CreatePDF('example');