PDF digital signature usig PointCasttle

Hi

I need to digitally sign (RSA and ECDSA) a PDF document using the PointCastle Library(https://pub.dev/packages/pointycastle).

Can anybody help me? Any sample code?

Thanks in advance




20 Replies

SV Surya Venkatesan Syncfusion Team February 18, 2022 07:42 PM UTC

Hi Marcio,


As of now, We do not have support for signing PDF document by using PointCastle Library(https://pub.dev/packages/pointycastle). Currently, we are analyzing on this and we will update the further details on February 22nd 2022.


Refer to the following article to get more for signing a PDF document,

https://help.syncfusion.com/flutter/pdf/working-with-digital-signature


Regards,

Surya V



MA Marcio replied to Surya Venkatesan February 18, 2022 09:23 PM UTC

Surya

Thanks for your prompt response. As I could understand in the code sample for digital signature, you use PointCastle n the X.509 package. Am I correct ? 


Thanks again

Regards




SV Surya Venkatesan Syncfusion Team replied to Marcio February 21, 2022 03:47 PM UTC

Hi Marcio,


No, We are not using PointyCastle for our digital signing process. As we said earlier, we are analyzing on this and we will update the further details on February 22nd 2022.


Regards,

Surya V



SV Surya Venkatesan Syncfusion Team February 22, 2022 06:35 PM UTC

Hi Marcio,


We won’t be able to sign the PDF document directly using the pointycastle package but it is possible to use pointycastle package to generate signed bytes and externally sign the PDF document using the signature data.


Kindly use the following link for externally signing the PDF document, https://help.syncfusion.com/flutter/pdf/working-with-digital-signature#externally-sign-a-pdf-document


Kindly use the following code snippet for add signed data to PDF,

//Class for singing a PDF document externally.

class PdfExternalSigner implements IPdfExternalSigner {

  //Hash algorithm.

  @override

  DigestAlgorithm get hashAlgorithm => DigestAlgorithm.sha256;

 

  //Sign message digest.

  @override

  SignerResult sign(List<int> message) {

    final privateKey = _ InitializeRSAPrivateKey();

    var signer = RSASigner(SHA256Digest(), '0609608648016503040201');

    signer.init(true, PrivateKeyParameter<RSAPrivateKey>(privateKey));

    List<int> signedBytes =

        signer.generateSignature(Uint8List.fromList(message)).bytes;

    return SignerResult(signedBytes);

  }

}

 

PrivateKey InitializeRSAPrivateKey() {

  var rsapars = RSAKeyGeneratorParameters(BigInt.from(65537), 2048, 5);

  var secureRandom = FortunaRandom();

  var random = Random.secure();

  var seeds = <int>[];

  for (var i = 0; i < 32; i++) {

    seeds.add(random.nextInt(255));

  }

  secureRandom.seed(KeyParameter(Uint8List.fromList(seeds)));

  var params = ParametersWithRandom(rsapars, secureRandom);

  var keyGenerator = RSAKeyGenerator();

  keyGenerator.init(params);

  return keyGenerator.generateKeyPair().privateKey;

}


Regards,

Surya V



MA Marcio February 23, 2022 04:33 PM UTC

Thanks, Surya


Can you please send an example using the above code? The document that you indicate uses a PFX file with a certificate and I don't have this file and I don't want to create this file? 


Regards




SV Surya Venkatesan Syncfusion Team replied to Marcio February 24, 2022 06:16 PM UTC

Hi Marcio,


In Syncfusion Flutter PDF library, we won’t be able to externally sign a PDF document without valid certificate data. We have also attached a simple sample for externally signing PDF using some generated signed bytes from pointycastle package.


Kindly use the following package to download the sample, https://www.syncfusion.com/downloads/support/directtrac/general/ze/flutter_sample-517615916


Regards,

Surya V



MA Marcio replied to Surya Venkatesan March 15, 2022 04:23 AM UTC

Hi Surya V


Thanks for your reply. I am sorry for the delay but I was busy testing our solution .


Although I managed to sign the PDF Form using our PointCastle as directed by your post The signature file is not shown in the form. Everything works fine, no error, but the field is not shown.


Then I tested your code and it has the same behaviour.


Any Clue!

Best regards



SV Surya Venkatesan Syncfusion Team replied to Marcio March 15, 2022 06:30 PM UTC

Hi Marcio,


We recommend you enable the default set appearance of the form fields. Because few cases Form fields may appear empty in an adobe reader due to the absence of the appearance dictionary. To resolve this, you need to enable the Adobe Reader default appearance by using the setDefaultAppearance method in PdfForm class. Refer to the following UG documentation for more details, https://help.syncfusion.com/flutter/pdf/working-with-forms#troubleshooting and kindly try with the following code snippet and let us know the result,

document.form.setDefaultAppearance(true);


Regards,

Surya V



MA Marcio March 15, 2022 11:36 PM UTC

Hi  Surya

I inserted the code you suggested and I can see that there is a signature in the document. But no matter where a position the signature field it appears in the same location. Also when I show with the SfPdfViewer ​the signature des not appear at all!


myCripto = Cripto();
await myCripto!.fromSecureStorage();
final PdfSignatureField signatureField = await PdfSignatureField(
page, 'Signature',
bounds: Rect.fromLTWH(-65, 50, 200, 100));
final PdfSignature sign = await PdfSignature(
cryptographicStandard: CryptographicStandard.cades,
digestAlgorithm: DigestAlgorithm.sha256);
var extSigner = await PdfExternalSigner();
extSigner.myCripto = myCripto;
final IPdfExternalSigner externalSignature = extSigner;
sign.addExternalSigner(externalSignature,
<List<int>>[base64.decode(this.myCripto!.certbase64!)]);
signatureField.signature = await sign;
await document.form.fields.add(signatureField);


Any ideia ? Thanks! Best regards!





SV Surya Venkatesan Syncfusion Team replied to Marcio March 17, 2022 05:18 PM UTC

Hi Marcio,


At present, our Flutter PDF Viewer doesn’t have support for digital signature. We have a workaround to viewing the existing digital signature in the PDF document, kindly refer to the following link,

https://www.syncfusion.com/downloads/support/directtrac/general/ze/annnotation-578168701.zip


We have logged a feature request for this support in the PDF document library. We do not have any immediate plans to implement these features and we will implement this support in any of our upcoming releases. We usually have an interval of at least three months between releases, at the planning stage for every release cycle, we review all open features. We will let you know when this feature is implemented.


Please find the feedback link to track the implementation of the feature below,

https://www.syncfusion.com/feedback/26234/support-for-digital-signature


Kindly refer to the below link for more information about preserving the existing annotation in Syncfusion Flutter PDFViewer

https://www.syncfusion.com/kb/13014/how-to-preserve-the-existing-annotation-in-flutter-pdf-viewer-sfpdfviewer


Regards,

Surya V



MA Marcio March 22, 2022 04:49 PM UTC

Hi Surya

Thanks for your replay.

The code didn't work for the digital signature in the PDF Viewer. 

However, I can see, in Adobe Pdf Reader, that the signature is in the document but I can position the signature in the right place and the size of the signature shown in the document is truncated whatever the parameters I use in Rect.LTWH.

myCripto = Cripto();
await myCripto!.fromSecureStorage();
final PdfSignatureField signatureField = await PdfSignatureField(
page, 'Signature',
bounds: Rect.fromLTWH(-65, 50, 200, 100));
final PdfSignature sign = await PdfSignature(
cryptographicStandard: CryptographicStandard.cades,
digestAlgorithm: DigestAlgorithm.sha256);
var extSigner = await PdfExternalSigner();
extSigner.myCripto = myCripto;
final IPdfExternalSigner externalSignature = extSigner;
sign.addExternalSigner(externalSignature,
<List<int>>[base64.decode(this.myCripto!.certbase64!)]);
signatureField.signature = await sign;
await document.form.fields.add(signatureField);


Any idea? Thanks! Best regards!







SV Surya Venkatesan Syncfusion Team March 24, 2022 07:09 PM UTC

Hi Marcio,


The code didn't work for the digital signature in the PDF Viewer.

Currently, We are analyzing on the requested sample and will update the further details on March 28, 2022.

 

However, I can see, in Adobe Pdf Reader, that the signature is in the document but I can position the signature in the right place and the size of the signature shown in the document is truncated whatever the parameters I use in Rect.LTWH.

 

myCripto = Cripto();

    await myCripto!.fromSecureStorage();

    final PdfSignatureField signatureField = await PdfSignatureField(

        page, 'Signature',

        bounds: Rect.fromLTWH(-65, 50, 200, 100));

 

We have checked the provided code snippet containing -65 in the left position(x-axis of page position). We recommend you use the positive values in the bounds(if the page and its graphics are in zero degrees) to get a better result.

Eg: bounds: Rect.fromLTWH(65, 50, 200, 100));

 


Regards,

Surya V



MA Marcio March 28, 2022 12:41 PM UTC

Hi Surya, Thanks for your attention!

your suggestion :

"We have checked the provided code snippet containing -65 in the left position(x-axis of page position). We recommend you use the positive values in the bounds(if the page and its graphics are in zero degrees) to get a better result.

Eg: bounds: Rect.fromLTWH(65, 50, 200, 100));"


Does not work! The signature always appears at the same position no matter a change the Rect.fromLTWH's parameters. This seems to have no affect on the final PDF document.

Below some of the relevant code. Sorry I couldn't post the whole file. 


Btw, all other elements appears on the right position.

Best regards



SignerResult sign(List<int> message) {
var eccsassinatura;
if (myCripto != null) {
eccsassinatura = myCripto!.ECSign(Uint8List.fromList(message));
;
} else
throw ("Cripto nao inicializada");
return SignerResult(eccsassinatura);
}
}

class Pdfclass {
// constructor
Cripto? myCripto;
PdfPage? page;
PdfDocument document = PdfDocument();
firebase_storage.FirebaseStorage storage =
firebase_storage.FirebaseStorage.instance;
Pdf() {} //Set the font

// cria PDF do aviso de Saida
Future<void> createAvisodeSaida(
AvisoSaida avisoSaida, String filename, String waterMark) async {
try {
//Set the page size
document.pageSettings.size = PdfPageSize.a4;
//Draw text
page = document.pages.add();
var imageBuffer = await rootBundle.load('imagens/Avisodesaida.jpg');
var byteData = imageBuffer.buffer
.asUint8List(imageBuffer.offsetInBytes, imageBuffer.lengthInBytes);
// var imageBuffer = File('../imagens/Avisodesaida.jpg').readAsBytesSync();
//Draw the image
page!.graphics.drawImage(
PdfBitmap(byteData),
Rect.fromLTWH(
0, 0, page!.getClientSize().width, page!.getClientSize().height));
// Draw Nome da Marina
page!.graphics.drawString(avisoSaida.nomeMarinaIate!,
PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(223, 136, 100, 100));
// Draw Data
page!.graphics.drawString(
avisoSaida.data!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(122, 200, 100, 100));

// Draw Nome do Comandante
page!.graphics.drawString(avisoSaida.nomeComandante!,
PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(117, 220, 400, 100));

// Draw Nome da Embarcacao
page!.graphics.drawString(avisoSaida.nomeEmbarcacao!,
PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(211, 246, 100, 100));

// Draw Nome Tipo
page!.graphics.drawString(
avisoSaida.tipo!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(375, 246, 100, 100));

// Draw Destino
page!.graphics.drawString(
avisoSaida.destino!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(201, 268, 100, 100));

// Draw Previsao de Saida
page!.graphics.drawString(avisoSaida.previsaoSaida!,
PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(205, 292, 100, 100));

// Draw Datade Chegada
page!.graphics.drawString(avisoSaida.previsaoChegada!,
PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(400, 292, 100, 100));

// Draw Numero de Pessoas
page!.graphics.drawString(avisoSaida.numeroPessoas!.toString(),
PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(261, 314, 100, 100));

// Draw Observacoes
page!.graphics.drawString(
avisoSaida.observacoes!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(150, 336, 300, 100));
// Draw Watermark
if (waterMark != "") {
page!.graphics.setTransparency(0.20);
page!.graphics.rotateTransform(-40.0);
page!.graphics.drawString(
waterMark, PdfStandardFont(PdfFontFamily.helvetica, 50),
pen: PdfPens.red,
brush: PdfBrushes.red,
bounds: Rect.fromLTWH(100, 450, page!.getClientSize().width,
page!.getClientSize().height));
}
//Assina e salva documento
await _signPDF();
document.form.setDefaultAppearance(true);
_getAnnotations();
pdfbytes = await document.save();
document.dispose();
//Get external storage directory
Directory directory = (await getApplicationDocumentsDirectory());
//Get directory path
String path = directory.path;
//Create an empty file to write PDF data
var ts = DateFormat('dd-MM-yyyy:HH:mm:ss:ms').format(DateTime.now());
File file = File('$path/avisodesaida1' + ts + '.pdf');
//Write PDF data
await file.writeAsBytes(pdfbytes!, flush: true);
//Open the PDF document in mobile
await OpenFile.open('$path/avisodesaida1' + ts + '.pdf');
;
} catch (exception) {
print("Erro = " + exception.toString());
}
}

Future<void> _signPDF() async {
PdfGraphics graphics = page!.graphics;
myCripto = Cripto();
if (!await myCripto!.fromSecureStorage()) return;
//Sets an image for signature field
var imageBuffer = await rootBundle.load("imagens/navegacaoNovoLogo.png");
var imageBytes = imageBuffer.buffer
.asUint8List(imageBuffer.offsetInBytes, imageBuffer.lengthInBytes);
PdfBitmap signatureImage = new PdfBitmap(imageBytes);

final PdfSignatureField signatureField = await PdfSignatureField(
page!, 'Signature',
bounds: Rect.fromLTWH(200, 550, 200, 200));

final PdfSignature sign = await PdfSignature(
cryptographicStandard: CryptographicStandard.cades,
digestAlgorithm: DigestAlgorithm.sha256,
signedName: "Marcio",
contactInfo: "[email protected]",
reason: "Aviso de Saida",
locationInfo: "rio de janeiro");
var extSigner = await PdfExternalSigner();
//Draws the signature image
extSigner.myCripto = myCripto;
final IPdfExternalSigner externalSignature = extSigner;
sign.addExternalSigner(externalSignature,
<List<int>>[base64.decode(this.myCripto!.certbase64!)]);
signatureField.signature = await sign;
await document.form.fields.add(signatureField);
// graphics.drawImage(signatureImage, Rect.fromLTWH(0, 400, 50, 50));
}




SV Surya Venkatesan Syncfusion Team replied to Marcio March 28, 2022 01:06 PM UTC

Hi Marcio,


We have prepared a sample to add digital signature in a specific coordinate with help of Syncfusion PDF and SfSignaturePad package. The sample can be downloaded from the following link.

https://www.syncfusion.com/downloads/support/directtrac/general/ze/pdfviewer_signature1106623277.zip


We tried to prepare the sample with the provided document, but the signature is not added and flatten while saving the PDFDocument. We are checking on this issue and will update the further details on 30 March 2022.


Regards,

Surya V



MA Marcio March 28, 2022 10:59 PM UTC

Hi Surya

Thanks for your reply!

I tried to run the sample in my computer and It didn't work. The digital signature is not shown. Only the image of the signature collected in the signature pad. I have tried many different approaches but had no success.


Best regards 



DR Deepika Ravi Syncfusion Team March 29, 2022 04:09 PM UTC

Hi Marcio,


We have prepared the sample for adding signature in the existing PDF document(provided) and it can be downloaded from the following link,

https://www.syncfusion.com/downloads/support/directtrac/general/ze/pdfviewer_signature48823757-77338112.zip


We have also checked the reported issue in the workaround sample provided on 28 March, but the provided sample is working fine on our side. For your reference, we have prepared the output screen record of the sample, which can be downloaded from the following link,

https://www.syncfusion.com/downloads/support/directtrac/general/ze/Screenrecord-509618322.zip


Regards,

Deepika Ravi



MA Marcio March 29, 2022 09:11 PM UTC

Hi Deepika !

Thanks for you answer !

You same works with the signature pad. It shows the image of the hand signature. However the fields of the digital signature is not shown in the actual  pdf form.


PdfSignatureField field = PdfSignatureField(page, 'signature',
bounds: const Rect.fromLTRB(300, 500, 550, 700),
signature: PdfSignature(
//Creates a certificate instance from the PFX file with a private key.
certificate: PdfCertificate(certificateBytes, 'password123'),
contactInfo: '[email protected]',
locationInfo: 'Honolulu, Hawaii',
reason: 'I am author of this document.',
digestAlgorithm: DigestAlgorithm.sha256,
cryptographicStandard: CryptographicStandard.cms));

This field is not shown! I am trying to show the parameters of the field like location info, contact info and the image linked to the field.

Any idea why?

Best regards




DR Deepika Ravi Syncfusion Team March 30, 2022 03:51 PM UTC

Hi Marico,


Thank you for your update.


As mentioned earlier, SfPDFViewer doesn't provide support for digital signature. But as a workaround, we have flattened the signature and displayed it in PDFViewer. While flattening, the signature will be preserved as an image, and the signature's properties will be lost so the information like location, the contact won't be available in PDFViewer.


If the PDF document is saved without flattening, then the signature will be available in PDF form which can be viewed using an adobe pdf reader. Please find its code and screenshot.


Code Snippet:


final ByteData docBytes = await rootBundle.load("assets/aviso2.pdf");
 
final Uint8List documentBytes = docBytes.buffer.asUint8List();
 ByteData certBytes =
await rootBundle.load("assets/certificate.cer");
 
final Uint8List certificateBytes = certBytes.buffer.asUint8List();
 PdfDocument document = PdfDocument(inputBytes: documentBytes);
 
//Adds a new page.
 
PdfPage page = document.pages[0];
 
final ByteData privateKey = await rootBundle.load("assets/privatekey.pem");
 
final Uint8List privateKeyBytes = privateKey.buffer.asUint8List();
 
final PdfSignature signature = PdfSignature(
    
//Creates a certificate instance from the PFX file with a private key.
    
certificate: null,
     contactInfo:
'[email protected]',
     locationInfo:
'Honolulu, Hawaii',
     reason:
'I am author of this document.',
     digestAlgorithm: DigestAlgorithm.sha256,
     cryptographicStandard: CryptographicStandard.cms);
 signature.addExternalSigner(
     PdfExternalSigner(privateKeyBytes), [certificateBytes]);
//Creates a digital signature and sets signature information.
 
PdfSignatureField field = PdfSignatureField(page, 'signature',
     bounds:
const Rect.fromLTWH(0, 0, 200, 100), signature: signature);

 
//Gets the signature field appearance graphics.
 
PdfGraphics? graphics = field.appearance.normal.graphics;

 
final ByteData imgBytes = await rootBundle.load("assets/sign.png");
 
final Uint8List imageBytes = imgBytes.buffer.asUint8List();

 
//Draws the signature image.
 
graphics?.drawImage(PdfBitmap(imageBytes),
     Rect.fromLTWH(
0, 0, field.bounds.width, field.bounds.height));
 
//Add a signature field to the form.
 
document.form.fields.add(field);

 
//Save the signed document.
 
final signatureDocument = Uint8List.fromList(document.save());
 document.dispose();

 
//load the existing document.
 
PdfDocument flattenDocument = PdfDocument(inputBytes: signatureDocument);

 
//Flattens the PDF form field annotation
   
flattenDocument.form.flattenAllFields();
 List<int> bytes = flattenDocument.save();
 
//Dispose the document
 
document.dispose();
 AnchorElement(
     rel='nofollow' href:
    
"data:application/octet-stream;charset=utf-16le;base64,${base64.encode(bytes)}")
   ..setAttribute(
"download", "output.pdf")
   ..click();

 


Output Screenshot:

https://www.syncfusion.com/downloads/support/directtrac/general/SC1580~1-1684108337.png


Regards,

Deepika Ravi



MA Marcio April 18, 2022 11:42 AM UTC

Hi Deepika!

Thanks for your post! I have tried every sample you sent me and the signature is not shown. I Flatenned the fields and it shows the signature's image PDFViewer. If I don't flat the fields and try to show the document in Adobe and it also does not show the signature fields. I am stuck in on this. Below my last try:

 

Future<void> _signPDF() async {
PdfGraphics? graphics;
myCripto = Cripto();
if (!await myCripto!.fromSecureStorage()) return;
// cria o adinatura
final PdfSignature sign = await PdfSignature(
cryptographicStandard: CryptographicStandard.cades,
digestAlgorithm: DigestAlgorithm.sha256,
signedName: "Marcio",
contactInfo: "[email protected]",
reason: "Aviso de Saida",
locationInfo: "rio de janeiro");
var extSigner = await PdfExternalSigner();
//Draws the signature image
extSigner.myCripto = myCripto;
final IPdfExternalSigner externalSignature = extSigner;
sign.addExternalSigner(externalSignature,
<List<int>>[base64.decode(this.myCripto!.certbase64!)]);

// cria o Field Signature
final PdfSignatureField signatureField = await PdfSignatureField(
page!, 'Assinado Digitalmente',
bounds: const Rect.fromLTWH(100, 330, 200, 100), signature: await sign);
// carrega a imagem da assinatura
var imageBuffer = await rootBundle.load("imagens/signature.png");
var imageBytes = imageBuffer.buffer
.asUint8List(imageBuffer.offsetInBytes, imageBuffer.lengthInBytes);
PdfBitmap signatureImage = new PdfBitmap(imageBytes);
graphics = signatureField.appearance.normal.graphics;
graphics!.drawImage(signatureImage, Rect.fromLTWH(0, 0, 20, 20));
// adiciona o Filed da assinatura no documento
var result = await document.form.fields.add(signatureField);
print("Resultado = " + result.toString());
}
// Document creation
try {
//Set the page size
document.pageSettings.size = PdfPageSize.a4;
//Draw text
page = document.pages.add();
var imageBuffer = await rootBundle.load('imagens/tie.png');
var byteData = imageBuffer.buffer
.asUint8List(imageBuffer.offsetInBytes, imageBuffer.lengthInBytes);
//Draw the image
print("Width " + page!.getClientSize().width.toString());
print("Height " + page!.getClientSize().height.toString());
page!.graphics.drawImage(
PdfBitmap(byteData),
Rect.fromLTWH(
0, 0, page!.getClientSize().width, page!.getClientSize().height));
// Draw Nome
page!.graphics.drawString(
tie.holderName!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(60, 150, 500, 100));
// Draw Numero de Inscrico
page!.graphics.drawString(
tie.inscricao!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(380, 150, 500, 100));
// Draw Posto
page!.graphics.drawString(
tie.holderName!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(60, 200, 500, 100));

// Draw Data
page!.graphics.drawString(
tie.dateofEnroll!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(60, 250, 100, 500));

// Draw CPF
page!.graphics.drawString(
tie.cpf!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(180, 300, 100, 500));

// Draw Observacoes
page!.graphics.drawString(
tie.observacao!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(170, 570, 500, 100));
// Draw Local de Emissao
page!.graphics.drawString(
tie.placeOfIssuance!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(170, 610, 500, 500));
// Draw Data de Emissao
page!.graphics.drawString(
tie.dateofEnroll!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(260, 610, 400, 500));
// Draw validade
page!.graphics.drawString(
tie.expirationDate!, PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(350, 610, 100, 500));

//Assina e salva documento
await _signPDF();
document.form.setDefaultAppearance(true);
//_getAnnotations();
//Flattens the PDF form field annotation
//document.form.flattenAllFields();
pdfbytes = await document.save();
document.dispose();
//Get external storage directory
Directory directory = (await getApplicationDocumentsDirectory());
//Get directory path
String path = directory.path;
//Create an empty file to write PDF data
var ts = DateFormat('dd-MM-yyyy:HH:mm:ss:ms').format(DateTime.now());
File file = File('$path/tie1' + ts + '.pdf');
//Write PDF data
await file.writeAsBytes(pdfbytes!, flush: true);
//Open the PDF document in mobile
await OpenFile.open('$path/tie1' + ts + '.pdf');
;
} catch (exception) {
print("Erro = " + exception.toString());
}
}




AG Anantha Gokula Raman Jeyaraman Syncfusion Team April 19, 2022 03:12 PM UTC

Hi Marcio,

Thank you for your patience.

As of now, only the signed document appearance will be shown on the mobile reader and the signature details will not be shown, we have confirmed this behavior by signing PDF document using Adobe and ensured that the  signature details  were not shown in the mobile. If you want to show such details like signer, location, and more, you can draw it to the signature fields appearance(as in the below screenshot). Also we have confirmed that signature appearance is preserved properly in Adobe reader with and without flattening.

Adobe viewer mobile view

Adobe viewer desktop view


Kindly use the following sample for reference, https://www.syncfusion.com/downloads/support/directtrac/general/ze/pdfviewer_signature48823757-773381121428891908

Regards,

Anantha Gokula Raman J


Loader.
Up arrow icon