DavBfr / dart_pdf

Pdf creation module for dart/flutter
https://pub.dev/packages/pdf
Apache License 2.0
1.42k stars 633 forks source link

How to use Signature? How to digitally sign the generated PDF. #1730

Open xSuperMu opened 2 months ago

xSuperMu commented 2 months ago

Screenshot 2024-08-28 at 5 26 36 PM

pw.Container(
            width: double.infinity,
            padding: const pw.EdgeInsets.all(8),
            decoration: pw.BoxDecoration(
              border: pw.Border.all(
                color: PdfColors.blue,
                width: .5,
              ),
            ),
            child: pw.Column(
              crossAxisAlignment: pw.CrossAxisAlignment.start,
              children: [
                pw.Row(
                  children: [
                    pw.Text(
                      'First Name:',
                      style: customerDetailsTextStyle,
                    ),
                    pw.SizedBox(width: 10),
                    pw.Text(
                      _fNameCtrl.text,
                    ),
                  ],
                ),
                pw.SizedBox(height: 8),
                pw.Row(
                  children: [
                    pw.Text(
                      'Surname:',
                      style: customerDetailsTextStyle,
                    ),
                    pw.SizedBox(width: 10),
                    pw.Text(
                      _surNameCtrl.text,
                    ),
                  ],
                ),
                pw.SizedBox(height: 8),
                pw.Row(
                  children: [
                    pw.Text(
                      'Installation Address:',
                      style: customerDetailsTextStyle,
                    ),
                    pw.SizedBox(width: 10),
                    pw.Text(
                      _addressCtrl.text,
                    ),
                  ],
                ),
                pw.SizedBox(height: 8),
                pw.Row(
                  children: [
                    pw.Text(
                      'Email:',
                      style: customerDetailsTextStyle,
                    ),
                    pw.SizedBox(width: 10),
                    pw.Text(
                      _emailCtrl.text,
                    ),
                  ],
                ),
                pw.SizedBox(height: 8),
                pw.Signature(
                  name: 'signature',
                  child: pw.Text('Please sign here'),
                  // value: ,  <<<<<<<---------------------------------------------
                ),
              ],
            ),
          )

How to use the value attribute?

DavBfr commented 2 months ago

Something like:

Signature(
          name: 'Signature',
          value: PdfSign.rsaSha1(
            privateKey: privateKey,
            certificates: chain,
          ),
          child: PdfLogo(),
        ),

It's described here: https://pub.nfet.net/pdf_crypto/

xSuperMu commented 2 months ago

@DavBfr This is a paid feature, Right?

DavBfr commented 2 months ago

Yes it is. It's for digital cryptographic signature, not for hand-signed.

xSuperMu commented 2 months ago

Thank you @DavBfr for the prompt response. I think that I only need the hand-signed feature. How to achieve that?

DavBfr commented 2 months ago

Ask the user to draw with a hand sign flutter plugin and add it as an image in the pdf.