Invalidpdfexception PDF header signature not found

I have code that reads pdf files. The code does not work on the line:

iTextSharp.text.pdf.PRTokeniser.CheckPdfHeader() at iTextSharp.text.pdf.PdfReader.ReadPdf() 

I know from other entries that this problem occurs due to incorrect formatting in pdf. However, I cannot tell my users to repeat their pdf files. Is there any other way to solve this problem that may allow reading PDF despite this problem?

+4
source share
1 answer

If the file does not start with% PDF, then nothing can be fixed: the file is not a PDF file.

However, another problem may arise: you may be trying to access a file with a zero length due to some problem while creating an InputStream. Another context in which I saw this is a PDF file downloaded from the server, where the server returned the 404 message in HTML instead of the PDF file; -)

Whenever this exception occurs, you have to store bytes somewhere and study them. Without these bytes, no one can give you useful advice.

+8
source

Source: https://habr.com/ru/post/1433435/


All Articles