What are the best practices for modifying PDF document properties in PHP, especially when dealing with headers on specific pages?

When modifying PDF document properties in PHP, especially when dealing with headers on specific pages, it is important to use a library like TCPDF or FPDI to handle the PDF manipulation. These libraries provide functions to set document properties such as title, author, subject, and keywords. To modify headers on specific pages, you can use the SetHeader() function in TCPDF to set custom headers for each page.

// Include the TCPDF library
require_once('tcpdf/tcpdf.php');

// Create new TCPDF object
$pdf = new TCPDF();

// Set document properties
$pdf->SetCreator('Creator Name');
$pdf->SetTitle('Document Title');
$pdf->SetAuthor('Author Name');
$pdf->SetSubject('Document Subject');
$pdf->SetKeywords('keyword1, keyword2, keyword3');

// Set custom header for specific page
$pdf->AddPage();
$pdf->SetHeader('Custom Header for Page 1');

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