Codeigniter使用密码创建pdf文件

Is possible to create PDF file with password protected in codeigniter ? I need to use password for protect the PDF file which I send via email.

Anyone know to do that ?

In mpdf library use this as per https://mpdf.github.io/reference/mpdf-functions/setprotection.html#examples

 <?php

    $mpdf = new mPDF();

    // Encrypt the file and grant no permissions to the user to copy, print etc.

    // The user will be able to open the file as no password is specified

    // Owner cannot access full rights because no owner_password was set

    $mpdf->SetProtection(array(), 'UserPassword', 'MyPassword');

    $mpdf->WriteHTML('
    Hallo World
    ');

    $mpdf->Output('filename.pdf');

    ?>

for mail use this example.

Example - Sending file as e-mail (and also to browser)

<?php

$mpdf = new mPDF();

$mpdf->WriteHTML($html);

$mpdf->SetProtection(array(), 'UserPassword', 'MyPassword'); //set password

$content = $mpdf->Output('', 'S');

$content = chunk_split(base64_encode($content));

$mailto = 'recipient@domain.com';

$from_name = 'Your name';

$from_mail = 'sender@domain.com';

$replyto = 'sender@domain.com';

$uid = md5(uniqid(time()));

$subject = 'Your e-mail subject here';

$message = 'Your e-mail message here';

$filename = 'filename.pdf';

$header = "From: ".$from_name." <".$from_mail.">
";

$header .= "Reply-To: ".$replyto."
";

$header .= "MIME-Version: 1.0
";

$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"

";

$header .= "This is a multi-part message in MIME format.
";

$header .= "--".$uid."
";

$header .= "Content-type:text/plain; charset=iso-8859-1
";

$header .= "Content-Transfer-Encoding: 7bit

";

$header .= $message."

";

$header .= "--".$uid."
";

$header .= "Content-Type: application/pdf; name=\"".$filename."\"
";

$header .= "Content-Transfer-Encoding: base64
";

$header .= "Content-Disposition: attachment; filename=\"".$filename."\"

";

$header .= $content."

";

$header .= "--".$uid."--";

$is_sent = @mail($mailto, $subject, "", $header);

$mpdf->Output();