Reputation: 3457
I am currently trying to generate a pdf through a form, where I want the user data to be passed to the generated pdf. But as I discovered and read about about FPDF, it can't generate other things apart from what the FPDF class does. So here is my question:
How can I implement/use different data in my generated pdf?
I have tried the following (using a session variable in a cell):
require 'fpdf17/fpdf.php';
class PDF extends FPDF
{
function Header() {
$this->setFont("Arial", '', 32);
$this->Image('pics/invoiceLogo.png', 5,5,50);
$this->ln(25);
$this->setTextColor(0,0,0);
$this->setFont("Arial", '', 8);
$this->cell(100, 4, $_SESSION['firstname'] , 0, 0, 'L');
}
...
Btw I'm gettin the error:
FPDF error: Some data has already been output, can't send PDF file
Upvotes: 1
Views: 1796
Reputation: 6275
FPDF is telling you that it cannot change the HTTP headers in the response to then send the PDF as a file. That is, somewhere in your larger program, something has already started output through an echo, inline HTML, or included file.
This is not an error in FPDF. What you posted looks fine.
In the code that tries to call Output()
, wrap this in a try { ... } catch (Exception $e) { ... }
block. You can then do something like echo $e->getMessage();
or print_r($e->getTrace());
to see where the output is started or what's happening.
try {
$my_pdf = new PDF();
// ... work here ...
$my_pdf->Output();
} catch (Exception $e) {
echo $e->getMessage() . "<br>\n";
echo "<pre>";
print_r($e->getTrace());
echo "</pre>";
}
Upvotes: 1