├── .docker └── Dockerfile ├── .gitignore ├── README-br.md ├── composer.json ├── composer.lock ├── docker-compose.yml ├── kool.yml ├── phpunit.xml ├── src ├── Buffer.php ├── Metadata.php ├── ObjectParser.php ├── PDFObject.php ├── PageInfo.php ├── PdfDocument.php ├── PdfValue │ ├── PDFValue.php │ ├── PDFValueHexString.php │ ├── PDFValueList.php │ ├── PDFValueObject.php │ ├── PDFValueReference.php │ ├── PDFValueSimple.php │ ├── PDFValueString.php │ └── PDFValueType.php ├── Signature.php ├── SignatureAppearance.php ├── SignatureObject.php ├── Signer.php ├── StreamReader.php ├── Struct.php ├── Trailer.php ├── Utils │ ├── ContentGeneration.php │ ├── Date.php │ ├── Img.php │ ├── Mime.php │ ├── Str.php │ └── helpers.php └── Xref │ ├── XRef14.php │ ├── XRef15.php │ └── Xref.php └── tests ├── Feature └── ExampleTest.php ├── Pest.php ├── TestCase.php └── Unit └── ExampleTest.php /.docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM kooldev/php:8.2 2 | 3 | RUN sed -i '/^default = default_sect/a legacy = legacy_sect' /etc/ssl/openssl.cnf 4 | RUN sed -i '/^\[default_sect\]/a activate = 1' /etc/ssl/openssl.cnf 5 | RUN printf "[legacy_sect]\nactivate = 1" >> /etc/ssl/openssl.cnf 6 | 7 | CMD [ "php-fpm" ] -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | .idea/ 3 | file-tests/ 4 | -------------------------------------------------------------------------------- /README-br.md: -------------------------------------------------------------------------------- 1 | # PHP-SIGNER 2 | 3 | Esse é um pacote escrito inteiramente em PHP para assinar PDF's com suporte a multiplas assinaturas. 4 | 5 | ## INSTALAÇÃO: 6 | ```bash 7 | composer require jeidison/pdf-signer 8 | ``` 9 | 10 | ## EXEMPLOS: 11 | 12 | Assinando documentos: 13 | ```php 14 | $pathFileCertificate = 'path_do_seu_arquivo.pfx'; 15 | $passwordCertificate = 'senha do seu pfx'; 16 | $fileContent = file_get_contents('path_do_seu_certificado.pdf'); 17 | 18 | $fileContentSigned = Signer::new() 19 | ->withCertificate($pathFileCertificate, $passwordCertificate) 20 | ->withContent($fileContent) 21 | ->sign(); 22 | 23 | file_put_contents('path_onde_vc_quer_salvar_o_seu_pdf.pdf', $fileContentSigned); 24 | ``` 25 | 26 | Assinando documentos com metadados(Razão, Nome, Local, Informações de contato): 27 | ```php 28 | $pathFileCertificate = 'path_do_seu_arquivo.pfx'; 29 | $passwordCertificate = 'senha do seu pfx'; 30 | $fileContent = file_get_contents('path_do_seu_certificado.pdf'); 31 | 32 | $fileContentSigned = Signer::new() 33 | ->withCertificate($pathFileCertificate, $passwordCertificate) 34 | ->withContent($fileContent) 35 | ->withMetadata( 36 | Metadata::new() 37 | ->withReason('ASSINATURA DE DOCUMENTOS PARA TESTES.') 38 | ->withName('JEIDISON SANTOS FARIAS') 39 | ->withLocation('Araras/SP') 40 | ->withContactInfo('Jeidison Farias ') 41 | ) 42 | ->sign(); 43 | 44 | file_put_contents('path_onde_vc_quer_salvar_o_seu_pdf.pdf', $fileContentSigned); 45 | ``` 46 | 47 | Assinando documentos com assinatura visível: 48 | ```php 49 | $pathFileCertificate = 'path_do_seu_arquivo.pfx'; 50 | $passwordCertificate = 'senha do seu pfx'; 51 | $fileContent = file_get_contents('path_do_seu_certificado.pdf'); 52 | 53 | $fileContentSigned = Signer::new() 54 | ->withCertificate($pathFileCertificate, $passwordCertificate) 55 | ->withContent($fileContent) 56 | ->withSignatureAppearance( 57 | SignatureAppearance::new() 58 | ->withImage('/path_do_seu_icone.png') 59 | ->withRect([350, 770, 400, 820]) 60 | ) 61 | ->sign(); 62 | 63 | file_put_contents('path_onde_vc_quer_salvar_o_seu_pdf.pdf', $fileContentSigned); 64 | ``` 65 | 66 | Adicionando carimbo de tempo na assinatura: 67 | ```php 68 | // Ainda não implementado. 69 | ``` 70 | 71 | ## Credits 72 | - [Jeidison Farias](https://github.com/jeidison) 73 | - [All Contributors](../../contributors) -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jeidison/pdf-signer", 3 | "description": "Project to add digital signature in pdf files", 4 | "type": "library", 5 | "require": { 6 | "php": "^8.1", 7 | "ext-openssl": "*", 8 | "ext-zlib": "*", 9 | "ext-fileinfo": "*", 10 | "ramsey/uuid": "^4.7" 11 | }, 12 | "require-dev": { 13 | "pestphp/pest": "v2.20.0", 14 | "laravel/pint": "v1.13.2", 15 | "symfony/var-dumper": "^6.4.2" 16 | }, 17 | "license": "MIT", 18 | "autoload": { 19 | "psr-4": { 20 | "Jeidison\\PdfSigner\\": "src/" 21 | }, 22 | "files": [ 23 | "src/Utils/helpers.php" 24 | ] 25 | }, 26 | "autoload-dev": { 27 | "psr-4": { 28 | "Tests\\": "tests/" 29 | } 30 | }, 31 | "authors": [ 32 | { 33 | "name": "Jeidison Farias" 34 | } 35 | ], 36 | "minimum-stability": "dev", 37 | "config": { 38 | "allow-plugins": { 39 | "pestphp/pest-plugin": true 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.8" 2 | # 3 | # Services definitions 4 | # 5 | services: 6 | app: 7 | build: .docker 8 | ports: 9 | - "${KOOL_APP_PORT:-80}:80" 10 | - "9003:9003" 11 | environment: 12 | ASUSER: "${KOOL_ASUSER:-0}" 13 | UID: "${UID:-0}" 14 | ENABLE_XDEBUG: "true" 15 | XDEBUG_MODE: "debug,develop,coverage" 16 | XDEBUG_CONFIG: "client_host=host.docker.internal" 17 | volumes: 18 | - .:/app:delegated 19 | networks: 20 | - kool_local 21 | - kool_global 22 | # 23 | # Networks definitions 24 | # 25 | networks: 26 | kool_local: 27 | kool_global: 28 | external: true 29 | name: "${KOOL_GLOBAL_NETWORK:-kool_global}" 30 | -------------------------------------------------------------------------------- /kool.yml: -------------------------------------------------------------------------------- 1 | # Here you can define shortcuts and aliases to common tasks (commands) 2 | # you will run in your local environment or CI or deploy. 3 | # Use the scripts defined below with: 4 | # $ kool run