We want to create dynamically generated PDFs via HTML - but we also want to use an existing template for each generated page.
Using a template via FPDI
is straight forward enough:
// Generate the FPDI instance
$pdf = new \setasign\Fpdi\Tcpdf\Fpdi(…);
// Add the first page
$pdf->AddPage();
// Load the template
$pagecount = $pdf->setSourceFile('template.pdf');
$tpl = $pdf->importPage(1);
$pdf->useTemplate($tpl);
// Write the HTML
$pdf->writeHTML($html, true, 0, true, 0);
However, when the written HTML causes an automatic page wrap, the subsequent pages do not use the template.
Since I cannot know beforehand how many pages there will be generated due to the dynamically generated HTML - how can I instruct TCPDF/FPDI to use a given template for all pages automatically? Similar to mPDFs SetDocTemplate
function, where you can define that the last page of the template should be repeated as needed.
tecnickcom/tcpdf
version6.2.26
setasign/fpdi
version2.2.0