PHP code example of nihillabs / pades-core

1. Go to this page and download the library: Download nihillabs/pades-core 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/ */

    

nihillabs / pades-core example snippets


use NihilLabs\Pades\Credentials\PfxCredential;
use NihilLabs\Pades\Pades;
use NihilLabs\Pades\PadesSignatureOptions;

$credential = PfxCredential::fromFile(
    path: '/secure/certificate.pfx',
    password: $passwordTypedWhenSigning
);

$result = Pades::signBb(
    inputPdf: 'document.pdf',
    outputPdf: 'document-signed.pdf',
    credential: $credential,
    options: new PadesSignatureOptions(
        signatureName: 'Signer Name',
        signatureReason: 'Digital signature',
        signatureLocation: 'Internal system',
        signatureContactInfo: '[email protected]'
    )
);

use NihilLabs\Pades\Credentials\PfxCredential;
use NihilLabs\Pades\Crypto\Timestamp\HttpTimestampClient;
use NihilLabs\Pades\Pades;
use NihilLabs\Pades\PadesSignatureOptions;

$result = Pades::signBt(
    inputPdf: 'document.pdf',
    outputPdf: 'document-signed.pdf',
    credential: PfxCredential::fromFile('/secure/certificate.pfx', $passwordTypedWhenSigning),
    timestampProvider: new HttpTimestampClient('https://tsa.example.com/tsr'),
    options: new PadesSignatureOptions(
        signatureName: 'Signer Name',
        signatureReason: 'Digital signature',
        signatureLocation: 'Internal system',
        signatureContactInfo: '[email protected]'
    )
);

use NihilLabs\Pades\Certificate\PfxCertificateImporter;
use NihilLabs\Pades\Pades;
use NihilLabs\Pades\PadesSignatureOptions;
use NihilLabs\Pades\Signing\PfxSignatureCredential;

$uploadedPfxContents = file_get_contents($_FILES['certificate']['tmp_name']);

$metadata = (new PfxCertificateImporter())->inspectContents(
    contents: $uploadedPfxContents,
    password: $passwordTypedOnImport
);

// Store $uploadedPfxContents and selected $metadata fields.
// Do not store the certificate password.

$credential = PfxSignatureCredential::fromContents(
    contents: $storedPfxContents,
    password: $passwordTypedWhenSigning
);

Pades::signBb(
    inputPdf: 'document.pdf',
    outputPdf: 'document-signed.pdf',
    credential: $credential,
    options: new PadesSignatureOptions(
        visibleSignature: true,
        signatureRect: [48, 48, 547, 96],
        signatureName: 'Admin User',
        signatureReason: 'Assinatura digital',
        signatureLocation: 'Prontuario Eletronico',
        signatureContactInfo: '[email protected]'
    )
);