承接 creagia/laravel-sign-pad 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

creagia/laravel-sign-pad

Composer 安装命令:

composer require creagia/laravel-sign-pad

包简介

Laravel package for of E-Signature with Signature Pad and Digital Certified Sign with TCPDF

README 文档

README

A Laravel package to sign documents and optionally generate certified PDFs associated to a Eloquent model.

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Requirements

Laravel pad signature requires PHP 8.2 - 8.5 and Laravel 11 - 13.

Installation

You can install the package via composer:

composer require creagia/laravel-sign-pad

Publish the config and the migration files and migrate the database

php artisan sign-pad:install

Publish the .js assets:

php artisan vendor:publish --tag=sign-pad-assets

This will copy the package assets inside the public/vendor/sign-pad/ folder.

Configuration

In the published config file config/sign-pad.php you'll be able to configure many important aspects of the package, like the route name where users will be redirected after signing the document or where do you want to store the signed documents. You can customize the disk and route to store signatures and documents.

Notice that the redirect_route_name will receive the parameter $uuid with the uuid of the signature model in the database.

Preparing your model

Add the RequiresSignature trait and implement the CanBeSigned class to the model you would like.

<?php

namespace App\Models;

use Creagia\LaravelSignPad\Concerns\RequiresSignature;
use Creagia\LaravelSignPad\Contracts\CanBeSigned;

class MyModel extends Model implements CanBeSigned
{
    use RequiresSignature;

}

?>

If you want to generate PDF documents with the signature, you should implement the ShouldGenerateSignatureDocument class . Define your document template with the getSignatureDocumentTemplate method.

<?php

namespace App\Models;

use Creagia\LaravelSignPad\Concerns\RequiresSignature;
use Creagia\LaravelSignPad\Contracts\CanBeSigned;
use Creagia\LaravelSignPad\Contracts\ShouldGenerateSignatureDocument;
use Creagia\LaravelSignPad\Templates\BladeDocumentTemplate;
use Creagia\LaravelSignPad\Templates\PdfDocumentTemplate;
use Creagia\LaravelSignPad\SignatureDocumentTemplate;
use Creagia\LaravelSignPad\SignaturePosition;

class MyModel extends Model implements CanBeSigned, ShouldGenerateSignatureDocument
{
    use RequiresSignature;
    
    public function getSignatureDocumentTemplate(): SignatureDocumentTemplate
    {
        return new SignatureDocumentTemplate(
            outputPdfPrefix: 'document', // optional
            // template: new BladeDocumentTemplate('pdf/my-pdf-blade-template'), // Uncomment for Blade template
            // template: new PdfDocumentTemplate(storage_path('pdf/template.pdf')), // Uncomment for PDF template
            signaturePositions: [
                 new SignaturePosition(
                     signaturePage: 1,
                     signatureX: 20,
                     signatureY: 25,
                 ),
                 new SignaturePosition(
                     signaturePage: 2,
                     signatureX: 25,
                     signatureY: 50,
                 ),
            ]               
        );
    }
}

?>

A $model object will be automatically injected into the Blade template, so you will be able to access all the needed properties of the model.

Usage

At this point, all you need is to create the form with the sign pad canvas in your template. For the route of the form, you have to call the method getSignatureRoute() from the instance of the model you prepared before:

@if (!$myModel->hasBeenSigned())
    <form action="{{ $myModel->getSignatureRoute() }}" method="POST">
        @csrf
        <div style="text-align: center">
            <x-creagia-signature-pad />
        </div>
    </form>
    <script src="{{ asset('vendor/sign-pad/sign-pad.min.js') }}"></script>
@endif

Retrieving signatures

You can retrieve your model signature using the Eloquent relation $myModel->signature. After that, you can use:

  • getSignatureImagePath() returns the signature image path.
  • getSignatureImageAbsolutePath() returns the signature image absolute path.
  • getSignedDocumentPath() returns the generated PDF document path.
  • getSignedDocumentAbsolutePath() returns the generated PDF document absolute path.
echo $myModel->signature->getSignatureImagePath();
echo $myModel->signature->getSignedDocumentPath();

Deleting signatures

You can delete your model signature using

  • deleteSignature() method in the model.
echo $myModel->deleteSignature();

Customizing the component

From the same template, you can change the look of the component by passing some properties:

  • border-color (hex) to change the border color of the canvas
  • pad-classes and button-classes (strings) indicates which classes will have the sign area or the submit & clear buttons
  • clear-name and submit-name (strings) allows you to modify de default "Submit" and "Clear" values of the buttons.
  • disabled-without-signature (boolean) indicates if the submit button should be disabled when the user has not signed yet.

An example with an app using Tailwind would be:

  <x-creagia-signature-pad
      border-color="#eaeaea"
      pad-classes="rounded-xl border-2"
      button-classes="bg-gray-100 px-4 py-2 rounded-xl mt-4"
      clear-name="Clear"
      submit-name="Submit"
      :disabled-without-signature="true"
  />

Certifying the PDFs

To certify your signature with TCPDF, you will have to create your own SSL certificate with OpenSSL. Otherwise you can find the TCPDF demo certificate here : TCPDF Demo Certificate

To create your own certificate use this command :

cd storage/app
openssl req -x509 -nodes -days 365000 -newkey rsa:1024 -keyout certificate.crt -out certificate.crt

More information in the TCPDF documentation

After generating the certificate, you'll have to change the value of the variable certify_documents in the config/sign-pad.php file and set it to true.

When the variable certify_documents is set to true, the package will search the file allocated in the certificate_file path to sign the documents. Feel free to modify the location or the name of certificate file by changing its value.

Inside the same config/sign-pad.php we encourage you to fill all the fields of the array certificate_info to be more specific with the certificate.

Finally, you can change the certificate type by modifying the value of the variable cert_type (by default 2). You can find more information about certificates types at TCPDF setSignature reference.

Upgrading

See UPGRADING for details.

License

The MIT License (MIT). Please see License File for more information.

creagia/laravel-sign-pad 适用场景与选型建议

creagia/laravel-sign-pad 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 123.83k 次下载、GitHub Stars 达 544, 最近一次更新时间为 2022 年 10 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 creagia/laravel-sign-pad 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 creagia/laravel-sign-pad 我们能提供哪些服务?
定制开发 / 二次开发

基于 creagia/laravel-sign-pad 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 123.83k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 544
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 544
  • Watchers: 9
  • Forks: 52
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-03