Determine if a byte[] is a pdf file

前端 未结 5 2083

Is there any way of checking if a byte[] is a pdf without opening?

I have some code to display a list of byte[] as pdf thumbnails. I previously knew all the byte[] w

5条回答
  •  醉酒成梦
    2020-12-05 03:30

    While the marked answer and the other answers are correct, they will not be successful 100% of the time. The problem is the PDF spec says the %PDF-1.x only needs to be in the first 1024 bytes and not the first 4. Some programs will add information before %PDF and still be valid.

    I would recommend seeing the answer for the following Stack Overflow question: How to detect if a file is PDF or TIFF?

提交回复
热议问题