I need a clear solution of how to get the number of pages from a PDF file in android. Assuming the person has selected the file then on the onActivityResult(), I want to know how many pages the PDF file is. I would love a solution that will work for minSdkVersion 19 and would not need me paying for any PDF manipulation software, because I have checked round the net and there is no clear solution. Please it will be well appreciated because I really need the solution. I am using it with Firebase and want to upload the number of pages of the PDF as I also upload the file.
Here is a sample code, I used PDF Box: The error I keep getting is 08-10 21:07:57.533 20514-20514/com.example.android.firebaseupload E/file: Error: End-of-File, expected line I had to put in the file path manually before now and it has been the same error even after typing the file path manually. How do I load a pdf file from a path into the PDDocument.load()??
try {
PDDocument doc = PDDocument.load("file:///storage/emulated/0/Boom%20Player/cache/c2#.pdf".getBytes());
Toast.makeText(MainActivity.this,"Number of pages: "+doc.getNumberOfPages(),Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Log.e("file",e.getMessage().toString());
}