Commands
For PHP 7*
composer require mpdf/mpdf
For PHP 5*
composer require mpdf/mpdf
composer require paragonie/random_compat:\<9.99
test.php
<?php
//==============================================================
//==============================================================
//==============================================================
require_once 'vendor/autoload.php';
try {
$mpdf = new \Mpdf\Mpdf();
$mpdf->debug = true;
//$mpdf->SetImportUse();
$pagecount = $mpdf->SetSourceFile('book.pdf');
for ($loop = 1; $loop <= $pagecount; $loop++) {
$tplidx = $mpdf->importPage($loop);
$mpdf->addPage();
$mpdf->useTemplate($tplidx);
}
//$tplId = $mpdf->ImportPage(2);
//$mpdf->UseTemplate($tplId, 1, 100, 100);
//$mpdf->WriteHTML('Hello World');
$mpdf->setProtection(array(),"abc","123");
$mpdf->Output();
} catch (\Mpdf\MpdfException $e) { // Note: safer fully qualified exception
// name used for catch
// Process the exception, log, print etc.
echo $e->getMessage();
}
//exit;
?>
Hello guys, this is
unpossible pog, and in this video I shall tell you how to add
password on pdf using PHP.
unpossible pog, and in this video I shall tell you how to add
password on pdf using PHP.
First you have to
check the php version. You have to perfrom 1 extra action for PHP
version 5.
check the php version. You have to perfrom 1 extra action for PHP
version 5.
First I shall check
the php version which is more than 7.
the php version which is more than 7.
Lets create a
folder, give it any random name.
folder, give it any random name.
Open that folder in
terminal or CMD (if you are using windows), then type this command.
terminal or CMD (if you are using windows), then type this command.
If you have php
version 5 then u also have to run this command.
version 5 then u also have to run this command.
All commands and
codes are in the description.
codes are in the description.
It shall create
packages required for implementing password.
packages required for implementing password.
It takes a lot of
time so I shall fastforward it.
time so I shall fastforward it.
After the process is
done, I shall open IDE, I am using netbeans. You can use any software
you want.
done, I shall open IDE, I am using netbeans. You can use any software
you want.
Now open that folder
and paste the code in any random file. In my case, its “TEST.PHP”
and paste the code in any random file. In my case, its “TEST.PHP”
You can see the
code, copy that from the link given in description.
code, copy that from the link given in description.
I am also pasting
the pdf file for testing.
the pdf file for testing.
ABC and 123 are the
passwords which will be implemented on pdf file. You can change
password if you want.
passwords which will be implemented on pdf file. You can change
password if you want.
And make sure to
give the file name at “BOOK.PDF”
give the file name at “BOOK.PDF”
Now, lets run the
file.
file.
You can see errors,
to solve that you have to perform 2 things.
to solve that you have to perform 2 things.
First, open the
“AUTOLOAD.PHP” file which is inside vendor folder and close the
PHP tag.
“AUTOLOAD.PHP” file which is inside vendor folder and close the
PHP tag.
And Second, if you
using linux, then change the file permission as “CREATE AND DELETE
FILES” and “READ AND WRITE”.
using linux, then change the file permission as “CREATE AND DELETE
FILES” and “READ AND WRITE”.
Lets execute it, and
as you can see, the password pop is appeared when we run file. It
will be unlocked when I type 123. And will give error if I type
incorrect password.
as you can see, the password pop is appeared when we run file. It
will be unlocked when I type 123. And will give error if I type
incorrect password.
that’s it guys,
thank you for watching, dont forget to like share and subscribe.
thank you for watching, dont forget to like share and subscribe.
No comments:
Post a Comment