How to merge or append pdf to dompdf export option

is there an easy way to merge or append a pdf file into the pdf export option in phpmaker?

I’m trying to figure out how to do it too

Did you mean you want to append your additional content to the exported pdf file?

yes, I would also like to merge the attached pdf files
I’m trying like this:

function Page_Exporting(&$doc)
{
      return false;
}

il global code:

use Dompdf\Dompdf;
use Dompdf\Options;
use setasign\Fpdi\Fpdi;

function generaPDF($html) {
    $options = new Options();
   $options->set('isHtml5ParserEnabled', true);
    $options->set('isRemoteEnabled', true);
    $dompdf = new Dompdf();
    $dompdf->loadHtml($html);
    $dompdf->setPaper('A4', 'portrait');
    $dompdf->render();
    return $dompdf->output();
}


function Row_Export($doc, $rs)
{
    $html = $rs['testorapportohtml'];
    
    // Genera il PDF dal contenuto HTML
    $pdfContent = generaPDF($html);
    $rapportoId = $rs['idrapporto']; 
    $pdfPath = "files/rapporto_$rapportoId.pdf";
    file_put_contents($pdfPath, $pdfContent);


    $allegati = ExecuteRows("SELECT * FROM allegati WHERE idrapporto=".$rapportoId);

    $pdfFiles = [$pdfPath];
 foreach ($allegati as $allegato) {
        // Costruisci il percorso del file PDF allegato
        $filePath = 'files/'.$allegato['allegato'];
        $pdfFiles[] = $filePath;
    }


    $pdf = new FPDI();


    foreach ($pdfFiles as $file) {
        $pageCount = $pdf->setSourceFile($file);
        for ($i = 1; $i <= $pageCount; $i++) {
            $tplIdx = $pdf->importPage($i);
            $pdf->AddPage();
            $pdf->useTemplate($tplIdx);
        }
    }

    $mergedPdfPath = "pdf/unito_$rapportoId.pdf";
    $pdf->Output('F', $mergedPdfPath);

    return $mergedPdfPath;
}

if click to export pdf:SyntaxError: Unexpected token ‘<’, "
"… is not valid JSON

  1. Row_Export server event is used to export a row, not a document.
  2. The server events for export still uses the $doc to output, if you don’t use it at all, the output will be wrong.
  3. In your case you better use Row_CustomAction server event.

How do I merge all the pdf attachments of the table, with the same id, into a single file?

Currentyl, there are no pdf merging feature.As mentioned, you should use Row_CustomAction server event for such case.