1. Go to this page and download the library: Download jeidison/signer-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use SignerPHP\Application\DTO\ProtectionOptionsDto;
use SignerPHP\Presentation\Signer;
$protectedPdf = Signer::protection()
->withPdfContent(file_get_contents('/tmp/input.pdf'))
->withProtection(ProtectionOptionsDto::preventCopy(
ownerPassword: 'owner-secret',
userPassword: ''
))
->protect();
file_put_contents('/tmp/output-protected.pdf', $protectedPdf);
use SignerPHP\Application\DTO\ProtectionOptionsDto;
use SignerPHP\Presentation\Signer;
$signedProtectedPdf = Signer::signer()
->withPdfContent(file_get_contents('/tmp/input.pdf'))
->withProtection(ProtectionOptionsDto::preventCopy(
ownerPassword: 'owner-secret',
userPassword: ''
))
->withCertificatePath('/tmp/certificate.pfx', 'secret-password')
->protectThenSign();
file_put_contents('/tmp/output-protected-signed.pdf', $signedProtectedPdf);
use SignerPHP\Presentation\Signer;
$validation = Signer::validation()
->withPdfContent(file_get_contents('/tmp/input.pdf'))
->validate();
if (! $validation->hasSignatures) {
// PDF has no signatures
}
if ($validation->allValid) {
// all signatures were verified
}
use SignerPHP\Presentation\Signer;
$validation = Signer::validation()
->withPdfContent(file_get_contents('/tmp/input.pdf'))
->enableTrustChainValidation('/etc/ssl/certs/ca-certificates.crt') // optional; if omitted, tries the system default bundle
->validate();
foreach ($validation->entries as $entry) {
var_dump($entry->trustValid); // true|false|null
}
use SignerPHP\Presentation\Signer;
$validation = Signer::validation()
->withPdfContent(file_get_contents('/tmp/input.pdf'))
->withBrazilPolicy('/path/to/icp-brasil-bundle.pem')
->validate();
use SignerPHP\Application\DTO\BrazilPolicyLpaUrlsDto;
use SignerPHP\Application\DTO\BrazilTrustAnchorsOptionsDto;
use SignerPHP\Presentation\Signer;
$validation = Signer::validation()
->withPdfContent(file_get_contents('/tmp/input.pdf'))
->withBrazilPolicy(
'/path/to/icp-brasil-bundle.pem',
new BrazilPolicyLpaUrlsDto(
lpaUrlAsn1Pades: 'https://your-endpoint/LPA_PAdES.der',
lpaUrlAsn1SignaturePades: 'https://your-endpoint/LPA_PAdES.p7s',
),
new BrazilTrustAnchorsOptionsDto(
directory: '/tmp/my-trust-anchors-cache',
urls: [
'http://acraiz.icpbrasil.gov.br/Certificado_AC_Raiz.crt',
'http://acraiz.icpbrasil.gov.br/credenciadas/RAIZ/ICP-Brasilv7.crt',
],
),
)
->validate();