Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know if a File type is PDF?

Tags:

java

pdf

  • This answer How can I determine if a file is a PDF file? recommends to download another library, but my requirement is that I just need to check if a file is directory is of type PDF or not

  • Using complete library for this use looks like overkill

  • Are there any ways to know that a Java File is of type PDF?
like image 661
daydreamer Avatar asked Nov 08 '12 20:11

daydreamer


1 Answers

Well, according to wikipedia PDF files start with magic numbers: "%PDF" (hex 25 50 44 46) so maybe you should check the InputStream from the file and check that.

like image 137
ElderMael Avatar answered Oct 04 '22 15:10

ElderMael