How can fpdf be used to add password protection to a document?

To add password protection to a PDF document using fpdf in PHP, you can use the SetProtection() method provided by fpdf. This method allows you to set a password for opening the document, restricting permissions for printing, modifying, copying, and more.

require('fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 12);
$pdf->Cell(0, 10, 'Hello World!', 0, 1);

// Set password protection
$pdf->SetProtection(array('print', 'copy'), 'user_password', 'owner_password');

$pdf->Output('protected_pdf.pdf', 'F');