Search code examples
phparrayspdffpdf

FPDF + associative array key value column


I'm trying to create a PDF with the FPDF library. I have an array like this:

array (size=27)
'JobTitle' => string 'test-job' (length=8)
'lastName' => string 'zaezaeza' (length=8)
'firstName' => string 'zaezaeaz' (length=8)
'street' => string 'azezaeza' (length=8)
'streetNr' => string '54' (length=2)
'place' => string 'zaezaeza' (length=8)
'postalCode' => string '9870' (length=4)
'country' => string 'zeazeza' (length=7)
'mobile' => string '056154871' (length=9)
'email' => string 'aez@dqd.com' (length=11)
'placeOfBirth' => string 'azzazae' (length=7)
'nationality' => string 'zaezzae' (length=7)
'driversLicence' => string 'yes' (length=3)
'driversLicenceCategory' => string 'b' (length=1)
'ownCar' => string 'yes' (length=3)
'celibate' => string 'celibate' (length=8)
'LowerSecondaryStudies' => string 'degreeTitle: zaeaz
                                   educationAuthority: zaezaezaeza
                                   graduationYear: 2014' (length=75)
'dutch' => string 'No selections' (length=13)
'french' => string '' (length=0)
'english' => string '' (length=0)
'german' => string '' (length=0)
'computerKnowledge' => string 'zaezaza' (length=7)
'interestsCareer' => string 'azezaeza' (length=8)
'strongPoints' => string 'zaeazeza' (length=8)
'contact' => string 'employees: true
                     employeesWho: zaezaeza' (length=41)
'worklocation' => string 'merelbeke: true' (length=17)
'motivationSolicitation' => string 'zaezaezaeza' (length=11)

Now I would like the following output in my pdf:

enter image description here

But I'm really stuck at how I can create this table.. . I've read this tutorial from fpdf but didn't get any wiser from it. Can somebody help me on my way?


Solution

  • <?php
    require('mc_table.php');
    
    $pdf=new PDF_MC_Table();
    $pdf->AddPage();
    $pdf->SetFont('Arial','',14);
    //Table with 27 rows and 2 columns since you have 27 values 
    $pdf->SetWidths(array(30,60));
    
    $pdf->Row(array('Key','Value'));
    $pdf->Row(array('JobTitle','test-job'));
    $pdf->Row(array()); //Do the same thing as above
    .
    .
    .
    .
    //Do it for 27 times since you have 27 values
    //Or store them in array and use a loop
    $pdf->Output();
    ?>