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

setEncryption not working with variable #3437

Closed
tavitomedcol opened this issue Apr 16, 2024 · 7 comments
Closed

setEncryption not working with variable #3437

tavitomedcol opened this issue Apr 16, 2024 · 7 comments

Comments

@tavitomedcol
Copy link

Hello, when I try to encrypt a pdf with a password, it only works with a direct string, example: setEncryption(1234, 5678) but I need the password to be a variable setEncryption($var,123456789). any solution? thanks

this is my line of code:

$dompdf->getCanvas() ->get_cpdf() ->setEncryption($var, '123456789', ['print', 'modify', 'copy', 'add']);

@bsweeney
Copy link
Member

Should be no difference in functionality whether you use a string or variable. What values have you tried for $var? Do you receive any errors when calling the method?

@tavitomedcol
Copy link
Author

No error is displayed. It just says that the pdf cannot be opened. It only opens what is inside the quotes '$var' opens with $var but does not take the value of the variable, even if the variable is found alone $var without quotes

@bsweeney
Copy link
Member

At what point are you setting $var and at what point do you call setEncryption?

@tavitomedcol
Copy link
Author

tavitomedcol commented Apr 29, 2024

This is my code

session_start();
$id=$_REQUEST['id'];
ob_start();

require_once 'printpdf.php';

$html = ob_get_clean();


$_SESSION['pdf']['content'] = $html;
$_SESSION['pdf']['filename'] = 'INF'.$id.'.pdf';

$html = $_SESSION['pdf']['content'];
$filename = $_SESSION['pdf']['filename'];

$options = new Options();
$options->set('isRemoteEnabled', true);
$dompdf = new DOMPDF($options);
 
$dompdf->loadHtml($html);
$dompdf->set_paper('letter', 'portrait');

$dompdf->render();

$password=$rs->idper;
$dompdf->getCanvas() ->get_cpdf() ->setEncryption($password, '12108', array('print', 'modify', 'copy', 'add'));
$output=$dompdf->output();
//$dompdf->stream();
file_put_contents($filename, $output);

unset($_SESSION['pdf']);

@tavitomedcol
Copy link
Author

tavitomedcol commented Apr 29, 2024

$password='1234';
$dompdf->getCanvas() ->get_cpdf() ->setEncryption($password, '12108', array('print', 'modify', 'copy', 'add'));
$output=$dompdf->output();
//$dompdf->stream();
file_put_contents($filename, $output);

unset($_SESSION['pdf']);

image

not open
image

Only open with 12108 not with de var $password

@bsweeney
Copy link
Member

Your logic looks OK. Are you running under a locale other than en_US? I would not expect that to cause issues with the password functionality, but I haven't tested that scenario in a while.

@tavitomedcol
Copy link
Author

Solved, the variable changes its value per session variable, so the value did not clear and always kept the same value, why? magic, for no reason. Thanks

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