Sample code for 30+ languages & platforms
PHP

Get PDF Signer Certs

See more PDF Signatures Examples

This example demonstrates how to validate the signatures in a PDF and also shows how to get

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Cert;
use Chilkat2\JsonObject;
use Chilkat2\Pdf;

$success = false;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$pdf = new Pdf();

// Load a PDF that has cryptographic signatures to be validated
try {
    $pdf->LoadFile('qa_data/pdf/sign_testing_1/helloSigned2.pdf');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// Each time we verify a signature, information about the signature is written into
// sigInfo (replacing whatever sigInfo previously contained).
$sigInfo = new JsonObject();

// Iterate over each signature and validate each.
$numSignatures = $pdf->NumSignatures;
$validated = false;
$cert = new Cert();
$i = 0;
while ($i < $numSignatures) {
    try {
        $pdf->VerifySignature($i, $sigInfo);
        $validated = true;
    } catch (\Chilkat2\Exception $e) {
        $validated = false;
    }
    echo 'Signature ', $i, ' validated: ', ($validated ? 'true' : 'false'), "\n";

    // After calling VerifySignature, you can get the signer certificate by calling
    // GetSignerCert with the same index.
    try {
        $pdf->GetSignerCert($i, $cert);
        $success = true;
    } catch (\Chilkat2\Exception $e) {
        $success = false;
    }
    if ($success) {
        echo 'PDF signer certificate: ', $cert->SubjectDN, "\n";
    }

    $i = $i + 1;
}

echo "Finished.\n";