When importing and modifying a PDF file inside a Joomla component using the FPDF and FPDI libraries, after sending the file to the browser, the PDF viewer claims the XREFS table to be broken.
Here's part of what I have:
<?php
...
use \setasign\Fpdi\Fpdi;
include "fpdf/fpdf.php";
include "fpdi2/src/autoload.php";
class MycompoViewMycompo extends JViewLegacy
{
protected $pdf;
function display($tpl = null) {
...
$this->pdf = new Fpdi();
$this->pdf->AddPage();
$this->pdf->setSourceFile('components/com_mycompo/views/mycompo/template.pdf');
$tplIdx = $this->pdf->importPage(1);
$this->pdf->useImportedPage($tplIdx, 0, 0, null, null, true);
$this->pdf->SetFont('Arial', '', 13);
$this->pdf->SetTextColor(0, 0, 0);
$this->pdf->SetXY(175, 49);
$pdf->Cell(0, 0, 'some Text', 0, 0, 'R');
// This actually happens in the layout...
// But I'd like to simplify here
$doc =& JFactory::getDocument();
$doc->setMimeEncoding('application/pdf');
$this->pdf->Output('gift_coupon_generated.pdf', 'D', true);
}
...
}
?>
The document is sent to the browser. It also can be downloaded and opened by a PDF viewer (I use PDF Exchange Editor). All the file's conents seem to be correct. No visible problems. But a warning is shown that the XREFS table is broken. (The exact message reads like "One or more XREF data streams were not found". I don't know the exact English message, as I use a different language version)
When working with the same code OUTSIDE of Joomla (i. e. in a standard PHP environment and a simple php web page), the file is also created perfectly fine and this error is not shown.
Any ideas on what might be the reason for this error message? Or how I could debug it further?
Or is using FPDF/FPDI not supported with Joomla?
Please find the generated file here: https://file.re/2021/10/16/banktransferform/
Best regards Tom