Skip to main content
Participant
August 14, 2019
Question

iTextsharp modify a signed file

  • August 14, 2019
  • 1 reply
  • 442 views

I am developer and I have a problem with PDF signed. I received a PDF file, created with Life Cycle (I don´t know if it is xfa or hybrid, because the form come from the Federal Tax Agency) that already contain two digital signing over some acroFields. I have to put a couple of data over other acrofields, and I´m using iTextsharp code.:The problem is the new file has the two previous signing broken. I don´t know what is wrong. Thanks in advance

My code is:

PdfReader pdfReader = null;
  
PdfStamper stamper = null;
  string filePDF
= @"C:\Visual Studio Solutions\Visual Windows\cpce Certificaciones\prueba_xfa.pdf";
  string outPDF
= @"C:\Visual Studio Solutions\Visual Windows\cpce Certificaciones\prueba_xfa_out.pdf";
  
try
  
{
  using
(var inStream = new FileStream(filePDF, FileMode.Open))
  
{
  pdfReader
= new PdfReader(inStream);
  
}

  using
(var outStream = new FileStream(outPDF, FileMode.Create))
  
{
  stamper
= new PdfStamper(pdfReader, outStream, '\0', true);

  var form
= stamper.AcroFields;

  form
.SetField("FORMULARIO[0].SUBFORMULARIO[0].ConsejoSubForm[0].OBLEA[0]", "probando");

  stamper
.Close();
  pdfReader
.Close();

  
}
  
}
  
catch (Exception ex)
  
{
  
throw new Exception("error: " + ex.Message);
  
}

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
January 5, 2020

This is how it should work. You can't edit a signed file without invalidating the signature.