Assinatura Digital

Olá pessoal,
estou tentando adicionar duas assinaturas digitais em um único arquivo PDF utilizando a biblioteca Aspose.PDF, porém estou enfrentando dificuldades.

Consegui inserir a primeira assinatura sem problemas, mas ao tentar adicionar a segunda, o PDF resultante fica corrompido ou a segunda assinatura substitui a primeira. Já tentei criar novos campos de assinatura e também assinar incrementalmente, mas não funcionou como esperado.

Alguém já conseguiu inserir múltiplas assinaturas digitais em um PDF usando Aspose.PDF?
Qual é o procedimento correto ou um exemplo funcional em C#/Java para criar dois campos de assinatura e assiná-los separadamente?

Agradeço qualquer ajuda!

@RogerioLimaDeveloper

Summary
Aspose.PDF can add more than one digital signature to the same PDF, but each signature must be placed in its own signature field and the document has to be saved incrementally (append mode) after each signing operation. A full rewrite of the PDF overwrites earlier signatures and can corrupt the file.

Why it happens

  • In a PDF each digital signature is stored as a separate object. When the file is saved with a full rewrite the existing signature objects are replaced, so a later signing operation removes the previous one.
  • The default Save operation in Aspose.PDF writes a new file. To preserve earlier signatures you need to use incremental (append) saving and give each signature field a unique name.

What to do next

  1. Open the original PDF and add a signature field (e.g., Signature1).
  2. Sign that field using a PdfSignature (or equivalent) object.
  3. Save the PDF with incremental/append mode enabled.
  4. Reload the newly saved PDF, add a second signature field (e.g., Signature2).
  5. Sign the second field and again save with incremental/append mode.

Checklist

  • Ensure each signature field has a distinct name.
  • Verify that the save operation is performed in append (incremental) mode for both signing steps.
  • After the final save, open the PDF in a viewer such as Adobe Acrobat/Reader and confirm that both signatures appear in the signature panel.

If you encounter issues, consult the Aspose.PDF documentation for the exact property/method to enable incremental saving (e.g., AppendMode in .NET or setAppendMode(true) in Java) and for examples of creating signature fields.

Note: The answer is based on general PDF signing principles and typical Aspose.PDF usage patterns; please verify the exact API names and options in the version of Aspose.PDF you are using.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

1 Like

Eu preciso do código pronto para me ajudar, por que se der certo irei comprar a dll.

@RogerioLimaDeveloper

Poderia, por gentileza, compartilhar seu arquivo PDF de exemplo e o trecho de código que você tem utilizado? Testaremos o cenário em nosso ambiente e o abordaremos adequadamente.

public void AssinarPDF()
{
string diretorio = @“c:\temp";
string inputPath = diretorio + @“XXXXX.pdf”;
string outputPath = diretorio + @”\documento_assinado.pdf";
string pfx_diretorio_01 = “”;
string pfx_senha_01 = “”;
string pfx_diretorio_02 = “”;
string pfx_senha_02 = “”;

        using (var pdfSign = new Aspose.Pdf.Facades.PdfFileSignature(inputPath, outputPath))
        {
            var pkcs1 = new Aspose.Pdf.Forms.PKCS7(pfx_diretorio_01, pfx_senha_01);

            System.Drawing.Rectangle rect1 = new System.Drawing.Rectangle(50, 200, 250, 100);

            pdfSign.Sign(1, "Assinatura da Alice", "Contato Alice", "Local A", true, rect1, pkcs1);
            pdfSign.Save(); 
        }

        inputPath  = diretorio + "documento_assinado.pdf";
        outputPath = diretorio + "documento_final.pdf";

        using (var pdfSign2 = new Aspose.Pdf.Facades.PdfFileSignature(inputPath, outputPath))
        {
            var pkcs2 = new Aspose.Pdf.Forms.PKCS7(pfx_diretorio_02, pfx_senha_02);

            System.Drawing.Rectangle rect2 = new System.Drawing.Rectangle(350, 200, 250, 100);

            pdfSign2.Sign(1, "Assinatura do Joao", "Contato Joao", "Local B", true, rect2, pkcs2);
            pdfSign2.Save();
        }
    }

@RogerioLimaDeveloper

Obrigado por compartilhar o trecho de código de exemplo. Você poderia, por favor, compartilhar arquivos PDF e PFX de exemplo para nossa referência também?

não posso compartilhar, pois são confidenciais.

@RogerioLimaDeveloper

Você pode compartilhar arquivos confidenciais em uma mensagem privada, onde apenas a equipe da Aspose tem acesso. Garantimos que utilizamos os arquivos apenas para fins de teste e, assim que a investigação for concluída, os removemos do nosso sistema.

Você pode enviar uma mensagem privada clicando no nome de usuário e pressionando o botão azul de mensagem.