What is cause of "PDF Load Failed --> Syncfusion.Pdf.PdfException: Could not find valid signature (%PDF)"

Hi,
We have a customer who from time to time, encounters an error loading a PDF document, and our app logs the following:


PDF Load Failed --> Syncfusion.Pdf.PdfException: Could not find valid signature (%PDF)

Unfortunately, we do not have access (and will not get acces) to the offending files.  We attempted to create the issue by creating a signed PDF with local CA and opening it on a device that did not have access to the CA, but that did not recreate the error.

I could not find a mention of this exception/error in the documentation.

Could you give me an idea of the conditions that will cause this exception to be thrown so that we can attempt to recreate it?  The more detail you provide, the better.

Thank you,

John

13 Replies 1 reply marked as answer

AV Ashokkumar Viswanathan Syncfusion Team July 13, 2020 12:22 PM UTC

Hi John, 
 
Thank you for contacting Syncfusion support, 
 
We have tried to reproduce the issue by loading the digitally signed PDF document, but its working as expected without any crash. 
 
Please find the sample in the below link, which we have tried to replicate the issue, 
  
Kindly share the following details to analyze more on this issue and assist you with the better solution    
  1. PDF document.
  2. Complete stack trace of the exception.
  3. SfPdfViewer version.
  4. Device specification.
  5. Replication video to reproduce the issue
 
Regards, 
Ashok Kumar Viswanathan. 



JB John Barrett July 14, 2020 07:41 PM UTC

Hi Ashok,

Thanks for your reply.  Unfortunately, our customer will not share the offending PDF documents.  We will not be able to get a replication video.  However, I have asked for the complete stack trace and will forward when I get them.

We are using version 18.1460.0.56 of the SfPdfViewer (UWP)

Thanks,
John





AV Ashokkumar Viswanathan Syncfusion Team July 15, 2020 09:28 AM UTC

Hi John,  
 
Thank you for your information, 
 
We have also tried to reproduce the issue with product version v18.1.0.56, but its working as expected, 
 
Please find the sample in the below link, 
 
However, we will wait to hear from you regarding the complete stack trace of the application crash while loading signed PDF document. 
 
Regards, 
Ashok Kumar Viswanathan. 


Marked as answer

GR Grzegorz October 2, 2020 03:42 PM UTC

i have same problem:

Syncfusion.Pdf.PdfException: Could not find valid signature (%PDF-).
   at Syncfusion.Pdf.Parsing.PdfLoadedDocument.LoadDocument(Stream file)
   at Syncfusion.Pdf.Parsing.PdfLoadedDocument..ctor(Stream file)


AV Ashokkumar Viswanathan Syncfusion Team October 5, 2020 11:38 AM UTC

Hi John,    
 
Thank you for the update. However, we could not proceed further with the information provided in your last update. Kindly share the following details to analyze more on this issue and assist you with the better solution     
   
  1. PDF document with which you have to reproduce the issue.
  2. Complete stack trace of the application crash while loading signed PDF document
  
Regards,  
Ashok Kumar Viswanathan.  



HS HSPR October 24, 2020 07:48 AM UTC

Hi Ashok,

I am not sure if John and/or Grzegorz hae the same cause of this exception, but here is one way to reproduce.

When you open a file with the file picker, convert it to stream, that stream works with pdfDocument.OpenAsync(stream).  However, when you convert that stream to a byteArray (byte[]) and try to fire pdfDocument.OpenAsync(byteArray), it throws "Could not find valid signature (%PDF-)." exception.

I am attaching a zip file with the code that you can call from any button's click event and a sample pdf file that I used.

Hope this helps to identify the issue.  FYI - Dev env: Win 10 on i3 machine with 6GB RAM. The project is UWP.

Thanks & regards
HSPR


Attachment: InvalidSignatureIssue_ad5b1c4f.zip


AV Ashokkumar Viswanathan Syncfusion Team October 26, 2020 07:00 AM UTC

Hi John, 
 
Thank you for providing requested details, 
 
We were able to reproduce the issue, “Application crashes with, ‘Could not find valid signature’ exception while a particular PDF document”. Currently, we are validating the issue and we will update the further details on October 28th , 2020.  
 
Regards,  
Ashok Kumar Viswanathan. 



AV Ashokkumar Viswanathan Syncfusion Team October 28, 2020 10:30 AM UTC

Hi John, 
 
The issue, “Application crashes with, ‘Could not find valid signature’ exception while a particular PDF document” is not an issue with SfPdfViewer control. The issue occurs due to the sample level changes where byte array values are not properly read from the existing stream. So kindly please set stream.Position = 0 before the byte array conversion to resolve the issue. 
 
Please refer the below modified the sample where the provided PDF document is loaded properly, 
 
Please let us know whether above provided solution resolved your issue. 
 
Regards, 
Ashok Kumar Viswanathan. 



HS HSPR October 28, 2020 05:34 PM UTC

Hi Ashok,

Thank you for your timely response.  

Not sure about John's issue.  I provided the code and sample.  Your modified sample works as expected.  However, once the stream converted to bytes and bytes saved to SQL Server and retrieved back,, the same bytes become a readonly form in PDFViewer, can't fill-in the form anymore.  Is any special handling required in this situation?  Is there a workaround? Maybe opening the file with write access and working with that stream might help. I will work on this and will provide update, if any.  

Will Document?.Save(stream) make it readonly?  

EDIT-2:  I verified.  If I get the stream from Document with "Document.Save(stream)" call, that stream is readonly.  SO saving the PDF bytes from the original stream works.

So, setting stream.Position = 0 and saving that stream as bytes to database instead of bytes from the Document.Save(stream), solves my problem.  

I would still be interested to know if Document.Save(stream) gives readonly stream or maybe flattened stream.

Once again thank you for your help.  

Thanks
Harshad



AV Ashokkumar Viswanathan Syncfusion Team October 29, 2020 12:23 PM UTC

Hi Harshad, 
 
Thank you for your update, 
 
We are here to confirm that saving the PDF document into the stream using ‘pdfLoadedDocument.Save(stream)’ does not flatten the form filling unless the Form property of the  PdfloadedDocument instance is changed before saving.    
   
Could you please share the details of how you are using the PdfLodedDocument instance and saving it as a stream along with your implementation of retrieving the bytes array from the SQL server, to proceed further on this. 
 
Regards, 
Ashok Kumar Viswanathan. 



HS HSPR October 30, 2020 10:50 AM UTC

Hi Ashok,

Thanks for your answer.  Un/Fortunately, I cannot reproduce the "ReadOnly" issue.  There might be something wrong on my part.  I made quite a few changes and not sure what has fixed it.

BTW, when I do the the following, does workingDoc get a reference to LoadedDocument or its clone?  It looks like its a clone. (I know it is a readonly)
   PdfLoadedDocument workingDoc = pdfViewer.LoadedDocument;

Thank you for your help.
Harshad


SP Satheesh Palanisamy Syncfusion Team November 2, 2020 02:17 PM UTC

Hi Harshad, 

Thanks for your answer.  Un/Fortunately, I cannot reproduce the "ReadOnly" issue.  There might be something wrong on my part.  I made quite a few changes and not sure what has fixed it. 
 
We were glad to hear from you that the issue is fixed on your side. 
BTW, when I do the the following, does workingDoc get a reference to LoadedDocument or its clone?  It looks like its a clone. (I know it is a readonly) 
   PdfLoadedDocument workingDoc = pdfViewer.LoadedDocument; 

It is the not working document that is loaded into the PDF Viewer and it is the clone of the document loaded in the PDF Viewer and changing the ‘LoadedDocument’ property does not reflect to the PDFViewer. 
 

Regards,
Satheesh Palanisamy. 



HS HSPR November 3, 2020 02:08 PM UTC

Thanks

Loader.
Up arrow icon