Extracting digital signature visualization from PDF

Hi,

I am working on converting digitally signed PDFs to PDF/A. To that end, I need to remove the digital signature from PDF, and add only its visualization back to the new document I am creating. I tried to do this with the ExtractImage() method, like so:

foreach (Aspose.Pdf.Forms.Field field in inputPDF.Form)
{
var sf = field as Aspose.Pdf.Forms.SignatureField;
if (sf != null)
{
using (Stream imageStream = sf.ExtractImage())
{
if (imageStream != null)
{
using (System.Drawing.Image image = Bitmap.FromStream(imageStream))
{
image.Save(outFile, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
}
}

But my digital signature contains an image together with some text, and the ExtractImage method only returns the background image. Is there any way I can get the signature visualization image together with text from the PDF?

Thanks in advance for your help.

Hi Eva,


Thanks for contacting support.

Can you please share a sample PDF file which can help us in understanding the requirement. We are sorry for this inconvenience.

Nayyer,

please find attached an example of a signed PDF such as I use. You can see the digital signature in the upper right corner of the first page.

The code snippet I posted earlier (for extracting the signature image) only returns the grey background. What I would like to have it return is the logo image (in the upper left corner of the grey rectangle), the text and the grey background image.

Thank you for your help.

I am replying to myself because I have discovered something interesting: if I convert the attached PDF to PDF/A like this:

var pdfaConvert = new Aspose.Pdf.Document(dataStream);
pdfaConvert.Convert(new MemoryStream(), PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);

digital signatures are stripped from the resulting PDF/A, but their images (visualizations) remain, regardless of whether they are image, text or a combination thereof.

Is this expected behaviour? If not, please don’t fix it since it’s very useful.

Eva_M:
Nayyer,

please find attached an example of a signed PDF such as I use. You can see the digital signature in the upper right corner of the first page.

The code snippet I posted earlier (for extracting the signature image) only returns the grey background. What I would like to have it return is the logo image (in the upper left corner of the grey rectangle), the text and the grey background image.

Thank you for your help.
Hi Eva,

Thanks for using our API's.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNET-41158 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.
Eva_M:
I am replying to myself because I have discovered something interesting: if I convert the attached PDF to PDF/A like this:

var pdfaConvert = new Aspose.Pdf.Document(dataStream);
pdfaConvert.Convert(new MemoryStream(), PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);

digital signatures are stripped from the resulting PDF/A, but their images (visualizations) remain, regardless of whether they are image, text or a combination thereof.

Is this expected behaviour? If not, please don't fix it since it's very useful.
Hi Eva,

Thanks for sharing the details.

I have tested the scenario and have managed to notice the same behavior and its the intended behavior. The purpose of Digital Signature is to ensure that PDF file contents are not changed and in case any modification is performed, the signature is removed.