How can PHP be used to create new PDFs from existing PDFs?

To create new PDFs from existing PDFs using PHP, you can use a library like TCPDF or FPDF. These libraries allow you to import existing PDF files and manipulate them to create new PDFs with added content or modifications.

require_once('tcpdf_include.php');

$pdf = new TCPDF();
$pdf->AddPage();

// Import existing PDF
$pdf->setSourceFile('existing.pdf');
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx, 0, 0, 210);

// Add new content
$pdf->SetFont('helvetica', '', 12);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetXY(10, 10);
$pdf->Write(0, 'New content added to existing PDF');

// Output the new PDF
$pdf->Output('new.pdf', 'I');