Add Digital Signature to PDF via PHP

Digital signature generation and verification using server-side Aspose.PDF for PHP via Java APIs. Native and high performance library

How to add Digitally Sign to PDF File Using PHP via Java Tool

In order to add sign in PDF file, we’ll use Aspose.PDF for PHP via Java API which is a feature-rich, powerful and easy-to-use document manipulation tool in php-java. Install Tomcat 9.0 version on any location, add Aspose.PDF.war, for more details check the GitHub page.

Add Digitally Sign to PDF via PHP


You need Aspose.PDF for PHP via Java to try the code in your environment.

  1. Load the PDF with an instance of Document.
  2. Load all the PDF files with full path.
  3. Set the style of text like font, font size, color etc.
  4. Save PDF file, You will get the document with signature inserted.
  5. To verify the validity of the signature use PdfFileSignature.VerifySigned() method.

Add Electronic Signature to a PDF File using - PHP

This sample code shows how to Signature PDF Pages - PHP

Input file:

File not added

Certificate file:

File not added

Output format:

Output file:


    // Open document
    $document = new Document($inputFile);    
    $signature = new facades_PdfFileSignature($document);
    $pkcs = new PKCS7($inputPKCS7, 'Pa$$w0rd2020'); // Use PKCS7/PKCS7Detached
    $rectangle = new Rectangle(300,100,420,160);
    $signature->sign(1, true, $rectangle->toRect(), $pkcs);
    // Save output PDF file
    $signature->save($outputFile);    
    $document->close();