hot4devs/document-signer

Add Signature to PDF Documents (https://gitlab.com/hot4devs/document-signer)

1.1.7 2025-04-02 08:19 UTC

README

DOCUMENT-SIGNER

Add signature to your documents

FEATURES

  • Add crt, key signature to PDF documents
  • Sign PDF documents using FPDI adapter
  • Returns SignedDocument
  • Store document signed on disk
  • SignedDocument can be returned as base64
  • SignedDocument can be returned as string

USAGE

For PDF Documents

  • Using factory (password needed; assume you have the crt and key files on same folder)

In this example use the following folder '/var/cert/valid':


// $name is the name of the crt and key file
$signedDocument = FpdiSigner::sign(
            setup: SignerSetting::setup(
                certPath: __DIR__ . '/var/cert',
                name: 'h4d',
                keyPassword: 'somepassowrd',
                documentPath: __DIR__ . '/var/document/example.pdf',
            )
        );



  • Get SignedDocument AS base64
    
    

// as base64 $base64 = $signedDocument->toBase64();

- Get SignedDocument AS File

If first parameter ($path) is null, the file will be stored in the same folder of the original document

// to file // usign DestinationFolder

use Hot4devs\DocumentSigner\Document\DestinationFolder

$destinationFolder = DestinationFolder::create('/var/destinationPath'); $signedDocument->toFile(destination:$destinationFolder) ->fullPath(); // returns the full path of the file

-  Get SignedDocument AS string

// as string $string = $signedDocument->content();

 
**FULLCODE EXAMPLE**

use Hot4devs\DocumentSigner\Document\Contract\SignedDocument; use Hot4devs\DocumentSigner\Signer\Fpdi\FpdiSigner; use Hot4devs\DocumentSigner\Signer\SignerSetting;

$signedDocument = FpdiSigner::sign(

        setup: SignerSetting::setup(
            certPath: __DIR__ . '/var/cert',
            name: 'h4d',
            keyPassword: 'somepassowrd',
            documentPath: __DIR__ . '/var/document/example.pdf',
        )
    );

// save on same folder $signedDocument->toFile();

// returns /var/document/example_signed.pdf $fullPath = $signedDocument->fullPath();


**LIMITATIONS**

- Only works with PDF documents
- Only works with crt and key files
- Not add any image or mark