Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gaan10's avatar

How to add encryption for generated PDF

I want to add encryption to my pdf. I am using Dompdf library. Currently i am able to generated pdf but without any encryption. This is how i am generating the pdf in controller:

$pdf = PDF::loadView('pdffileview',compact('new_records'));
return $pdf->download('Report_of_' .$records['Name']. '_with_' .$records['Mob']. '_mobile.pdf');

Plz give some pointers on how to add encryption on top of this. Thanks.

0 likes
4 replies
gaan10's avatar

I tried that ,But got this error:

Call to undefined method Barryvdh\DomPDF\PDF::setEncryption()
munazzil's avatar

Use this is in your header.

    use Barryvdh\DomPDF\Facade as PDF;
gaan10's avatar

This is already used. same error.

Please or to participate in this conversation.