I have the below file that opens a pdf and puts some text at the top. This is working fine. But what i want to do now is replace mypdf.pdf with the results of a mysql query. Similar to this:
$pageCount = $pdf->setSourceFile('../folder/folder/$mypdf');
and
$pdf->Write(0, '$sampletext');
Each person going to this page could receive a different pdf, hence the need to query the database to get the pdf they need.
Here is my code page:
<?php
// brings the id from previous page to use in database query
$id = $_GET['id'];
// trying to query database errors the page
use setasign\Fpdi\Fpdi;
require_once 'fpdi/src/autoload.php';
require_once('fpdf/fpdf.php');
// initiate FPDI
$pdf = new Fpdi();
// get the page count
$pageCount = $pdf->setSourceFile('../folder/folder/mypdf.pdf');
// iterate through all pages
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
// import a page
$templateId = $pdf->importPage($pageNo);
$pdf->AddPage();
// use the imported page and adjust the page size
$pdf->useTemplate($templateId, ['adjustPageSize' => true]);
// now write some text above the imported page
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 10);
$pdf->Write(0, 'This is just a simple text');
}
// Output the new PDF
$pdf->Output();
?>
How can i query the database and put in my variables without erroring the page?
I hope this makes sense. If someone can point me in the right direction it would be appreciate.
Thanks.