'How to get the information of pdf file on storage in android device and display it on to the screen?

I am trying to get the information about the pdf files on my android 11 device and display it on my screen How can I do that? and also we could open the pdf file after clicking on it...

Like this

enter image description here



Solution 1:[1]

In order to get pdf file content you can make use of itext library.

implementation 'com.itextpdf:itextg:5.5.10'

This library will help you to fetch the content of any pdf document. Please follow the below code for reference

try {
      String text="";
      PdfReader reader = new PdfReader("pdf file path");
      int n = reader.getNumberOfPages();
      for (int i = 0; i <n ; i++) {
           text= text+PdfTextExtractor.getTextFromPage(reader, i+1).trim()+"\n"; 
      }
      System.out.println(text);
      reader.close();
   } catch (Exception e) {
      System.out.println(e);
}

at the end you will get pdf content as text and you can show it on screen.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Apps Maven