Rocstar
Rocstar

Reputation: 1487

How to use PHP libraries whithout composer (FPDI with FPDI protection)

I use FPDI without composer so my file looks like this:

...
use \setasign\Fpdi;
require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/fpdi2/src/autoload.php');

// initiate FPDI
$pdf = new Fpdi\Fpdi();
...

I would like to add FPDI Protection to protect the PDFs I just generated

But on their readme, it shows only the procedure to follow if one uses composer

use setasign\FpdiProtection\FpdiProtection;

// setup the autoload function
require_once('vendor/autoload.php');

$pdf = new FpdiProtection();
$ownerPassword = $pdf->setProtection(
    FpdiProtection::PERM_PRINT | FpdiProtection::PERM_COPY,
    'the user password',
    'the owner password'
);

How to make FPDI uninitialized with FPDI Protection? I do not understand how to do ..

Upvotes: 0

Views: 4863

Answers (1)

Jan Slabon
Jan Slabon

Reputation: 5058

It is documented here:

If you do not use composer, just require the autoload.php in the /src folder:

require_once('src/autoload.php');

If you have a PSR-4 autoloader implemented, just register the src path as follows:

$loader = new \Example\Psr4AutoloaderClass;
$loader->register();
$loader->addNamespace('setasign\FpdiProtection', 'path/to/src/');

So in your case, just require both autoload.php files from FPDI and FPDI Protection:

use setasign\FpdiProtection\FpdiProtection;

require_once($_SERVER['DOCUMENT_ROOT'].'/fpdf/fpdf.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/fpdi2/src/autoload.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/fpdi_protection/src/autoload.php');

$pdf = new FpdiProtection();
...

Upvotes: 1

Related Questions