PHP code example of lsnepomuceno / laravel-a1-pdf-sign
1. Go to this page and download the library: Download lsnepomuceno/laravel-a1-pdf-sign 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/ */
lsnepomuceno / laravel-a1-pdf-sign example snippets
use LSNepomuceno\Signet\Exceptions\SignetException;
$exceptions->report(function (SignetException $e) { … });
use LSNepomuceno\LaravelA1PdfSign\Facades\A1PdfSign;
$signed = A1PdfSign::newSignature()
->certificate($pfxPath, $password)
->pdf($pdfPath)
->info(name: 'Lucas', reason: 'Contract')
->seal() // omit for an invisible signature
->sign();
$signed->contents; // string
$signed->save($path); // path
$signed->download('contract.pdf'); // BinaryFileResponse
Process::fake(); // the openssl shell-out, for validation and legacy PFX files
Http::fake(); // the timestamp authority, OCSP and CRL
Http::preventStrayRequests(); // proves a pades-b-b signature reaches no network at all
Storage::fake('s3'); // signing from a disk and writing back to one
app()->instance(SignatureTransport::class, new LocalTimestampAuthority(app(ProcessRunner::class)));
// PKCS#12
A1PdfSign::newSignature()->certificate($pfxPath, $password);
// PEM, key in the same file or in its own
A1PdfSign::newSignature()->certificatePem($certificatePath, $keyPath, $password);
// From an upload or a secret store
A1PdfSign::newSignature()->certificateFromPem($bytes);
$stored = A1PdfSign::encryptCertificate($uploadedOrPath, $password);
$stored->hash; // the key both values were encrypted with. Required to read them back
$stored->certificate;
$stored->password;
$certificate = A1PdfSign::decryptCertificate($stored->hash, $stored->certificate, $stored->password);
$prepared = A1PdfSign::newSignature()
->certificatePublic($certificatePem) // the public half is enough to reserve the space
->pdf($contract)
->prepare();
$cms = $yourHsm->sign($prepared->digestValue); // the only step that touches the key
$signed = A1PdfSign::complete($prepared, $cms);
A1PdfSign::newSignature()->certificate($pfx, $password)->pdf($path)
->certify('form-filling') // no-changes | form-filling | annotations
->lock(FieldLock::only(['Amount'])) // ->lock() for every field
->sign();
A1PdfSign::newSignature()
->certificate($pfxPath, $certificatePassword)
->pdf($path, 'the document password')
->sign();
$report = A1PdfSign::validate($pdfPath);
$report->isValid(); // every signature verifies against the bytes it covers
$report->count(); // how many signatures the document carries
$report->signers(); // structured signer identity
$report->isCertified(); // whether the author certified the document
$signature = $report->latest();
$signature?->attestedAt(); // the timestamp authority's time, or null. Never the signer's own clock
$signature?->profile; // the level it actually satisfies, not the one it claims
$signature?->isRevoked(); // what the document's own OCSP responses and CRLs say
$signature?->coversWholeDocument;
$store = TrustStore::fromFile(storage_path('icp-brasil.pem'));
$report = A1PdfSign::validate($pdfPath, $store);
$report->isTrusted(); // ?bool. null when no store was given: nobody was asked
$signer = A1PdfSign::validate($path)->signers()[0];
$signer->icpBrasil?->cpf; // '11144477735'
$signer->icpBrasil?->cnpj; // the company, for an e-CNPJ
$signer->icpBrasil?->formattedRegistry(); // '11.222.333/0001-81'
$signer->name(); // the name, without the number glued to it
public function tools(): iterable
{
return [
new McpServerTool(new ValidatePdfSignature()),
new SignPdf(), // the certificate comes from a resolver you bind, never from the model
];
}
$response = new ContractAssistant()->forUser($user)->prompt('Sign the Acme contract.');
$response->pendingApprovals->first()->reason;
// Sign [acme.pdf] on the disk [contracts] with the certificate of MARIA DA SILVA (111.444.777-35), valid until …