1

I am new at using FPDF. I am facing a real problem. I have multiple database values which are stored in arrays like this.

foreach($values as $value){
$arr1[]=$value['user_name'];
$arr2[]=$value['last_name'];
} 

$value['user_name'] is database table1, $value['last_name'] is database table2

I want to create PDF table using this values. Can anyone guide me on how to solve this real problem?

1 Answer 1

1

Do you need to create the table on the fly, or can you use a PDF form and fill it out via code, merging it into a static PDF when you are done?

If the form thing will work for you....

1) Create a PDF form. I use OpenOffice to do it... 2) Get a FDF template file of the form. On a Linux machine (I use Mint, but Mint, Ubuntu or Debian should all work this way) install the pdftk package and use the pdftk command to generate a FDF template file

pdftk demo3.pdf generate_fdf

You should see your form data field names in the resulting output file.

3) Fill it out with PHP, perhaps "stamp" an image or other PDF file onto it (ie, make a certificate with a "signature") and send it to the client.

<?php

include('./fpdf/fpdf.php');

// set up a bunch of temp file names
$FDFfile = tempnam(sys_get_temp_dir(), gethostname());
$tempPDF=tempnam(sys_get_temp_dir(), gethostname());
$PDFfile=tempnam(sys_get_temp_dir(), gethostname());
$ImageFileName=tempnam(sys_get_temp_dir(), gethostname());
$ImagePDFfilename=tempnam(sys_get_temp_dir(), gethostname());

// build our FDF data file string
//
// bring in top part of FDF file
$dataFile=file_get_contents("header.fdf");
// insert our participants name in the right spot
$dataFile.="<< /T (part_name) /V (".$_POST['lis_person_name_full'].") >> \n";
// finish the FDF file
$dataFile.=file_get_contents("footer.fdf");

// put the FDF data into the tempfile
file_put_contents($FDFfile, $dataFile);

// use pdftk to merge data/pdf form and then
// flatten to prevent editing
exec("pdftk demo3.pdf fill_form ".$FDFfile." output ".$tempPDF." flatten");

// create a new PDF file wtih our image code on it
$pdf = new FPDF();
$pdf->AddPage();
// put  image in bottom right corner of US letter paper
$pdf->Image($ImageFileName, 183, 250, 25, 25, 'PNG' );
$pdf->Output("F",$ImagePDFfilename);
// use pdftk to "stamp" the contents of one pdf onto the other
exec("pdftk ".$tempPDF." stamp ".$ImagePDFfilename." output ".$PDFfile);

// send final pdf file to browser
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename=certificate.pdf' );
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($PDFfile));
readfile($PDFfile);

// get rid of temp files
unlink($FDFfile);
unlink($tempPDF);
unlink($PDFfile);
unlink($ImageFileName);
unlink($ImagePDFfilename);
exit;

?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.