How does using FPDI in PHP differ from using fpdf for form generation?

When generating PDF forms in PHP, using FPDI allows you to import an existing PDF document and add form fields to it, while fpdf does not have built-in support for creating interactive forms. FPDI is an extension of fpdf that enables you to work with existing PDF files as templates for form generation.

// Include the necessary libraries
require_once('fpdf.php');
require_once('fpdi.php');

// Create a new FPDI instance
$pdf = new FPDI();

// Add a page in the PDF document
$pdf->AddPage();

// Import an existing PDF document as a template
$pdf->setSourceFile('existing_form.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 0, 0);

// Add form fields to the PDF document
$pdf->TextField('field_name', 50, 100, 100, 10);

// Output the PDF document
$pdf->Output();