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.
source share