We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Getting "key does not exist" error when saving a PDF

Hi,

We are using the Syncfusion PDF component to assemble externally-source PDF documents into a single document. With some documents, when attempting to save, we are getting this exception:

{"Key does not exist.\r"}
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146893811
    HelpLink: null
    InnerException: null
    Message: "Key does not exist.\r"
    Source: "System.Security"
    StackTrace: "   at System.Security.Cryptography.Pkcs.SignedCms.ComputeSignature(CmsSigner signer, Boolean silent)\r   at Syncfusion.Pdf.Security.PdfSignatureDictionary.SignCertificate(Byte[] message, X509Certificate2 cert, Boolean detached)\r   at Syncfusion.Pdf.Security.PdfSignatureDictionary.GetStoreCertificate()\r   at Syncfusion.Pdf.Security.PdfSignatureDictionary.DocumentSaved(Object sender, DocumentSavedEventArgs e)\r   at Syncfusion.Pdf.PdfDocumentBase.OnDocumentSaved(DocumentSavedEventArgs args)\r   at Syncfusion.Pdf.Parsing.PdfLoadedDocument.Save(Stream stream)\r  "
    TargetSite: {Void ComputeSignature(System.Security.Cryptography.Pkcs.CmsSigner, Boolean)}

Can you explain what this is and how to avoid it?



2 Replies

CS Charles Southey February 8, 2019 12:27 PM UTC

UPDATE: I have established that the cause is an invalid signature in the document, and have added a workaround to remove all signature fields as follows:

                                        var loadedSignatures = nextPDF?.Form?.Fields?.OfType<PdfLoadedSignatureField>().ToList() ?? new List<PdfLoadedSignatureField>();
                                        foreach (var loadedSignatureField in loadedSignatures)
                                        {
                                            nextPDF.Form.Fields.Remove(loadedSignatureField);
                                        }

However that's quite draconian - it would be better if it failed more gracefully and let us save the document without having to remove the field. Adobe reader identifies the invalid signature but still allows the file to be read etc.


SK Surya Kumar Syncfusion Team February 11, 2019 09:27 AM UTC

Hi Charles, 

Greetings from Syncfusion. 

We suspect that the issue which you have mentioned is specific to the document so could you please provide us the PDF in which this issue is reproduced. So that it will be helpful for us to analyze and provide you a solution. 


Regards, 
Surya Kumar 


Loader.
Live Chat Icon For mobile
Up arrow icon