Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Password not setting when setPaper() is called #3417

Open
T4-OmkarS opened this issue Mar 15, 2024 · 3 comments
Open

Password not setting when setPaper() is called #3417

T4-OmkarS opened this issue Mar 15, 2024 · 3 comments
Milestone

Comments

@T4-OmkarS
Copy link

T4-OmkarS commented Mar 15, 2024

if call setPaper() then generated PDF is not password protected, if setPaper() is commented out then generated PDF is password protected. Here is my code:

$dompdf = new Dompdf();
$dompdf->setPaper('A4');
$dompdf->getCanvas()->get_cpdf()->setEncryption('a1234', 'a1234', ['print', 'modify', 'copy', 'add']);
$dompdf->loadHtml($html);
$dompdf->render();
$dompdf->stream();
@T4-OmkarS
Copy link
Author

I am using dom pdf version 2.0.4 and my PHP version is 7.4

@bsweeney bsweeney added this to the 3.0.1 milestone Mar 15, 2024
@bsweeney
Copy link
Member

bsweeney commented Mar 15, 2024

Due to a quirk in the way Dompdf manages the Cpdf canvas adapter if the page size differs from the page size specified in the Options when Dompdf is initialized, then Cpdf is re-initialized on render. You can work around the issue by either:

  1. set the password after the document is rendered
  2. initialize Dompdf with the desired page size (e.g., $dompdf = new Dompdf(["defaultPaperSize" => "A4"]))

@T4-OmkarS
Copy link
Author

Thanks for quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants