1

Been stuck on this all day overall Im trying to get a pdf from local files via intent chooser to use with pdf reader and extract text from it but keep getting exceptions such as:

/external/file/24425: open failed: ENOENT (No such file or directory)

from using a file input stream or using a file name like so:

val name = DocumentFile.fromSingleUri(requireContext(), data.data!!)?.name?.toUri()?.path

and adding it to itext Pdfreader. Whats the correct way of getting a pdf file for pdf reader.

Intent Chooser

val pdfIntent = Intent(Intent.ACTION_GET_CONTENT, null)
    pdfIntent.type = "application/pdf"
    val chooser = Intent(Intent.ACTION_CHOOSER)
    chooser.putExtra(Intent.EXTRA_INTENT, pdfIntent)
    this.startActivityForResult(chooser, requestCodePDF)

OnActivityResult (handling the pdf)

val uri = data.data!!.path
                        val file = File(uri)
                        val fileInputStream = FileInputStream(file)
                        val pdfReader = PdfReader(name)
                        val pdfParser = PdfReaderContentParser(pdfReader)
                        val stringConverter = StringWriter()
                        val stretegy = pdfParser.processContent(
                            0,
                            SimpleTextExtractionStrategy()
                        )
                        stringConverter.write(stretegy.resultantText)
Jalen Paul
  • 25
  • 1
  • 6
  • Does this answer your question? [Android- Get text from PDF](https://stackoverflow.com/questions/29763405/android-get-text-from-pdf) – Ayodele Kayode Oct 24 '20 at 00:37
  • @AyodeleKayode sort of, my problem now is retrieving a pdf from files to use for pdf reader; Its giving me an incorrect file path. – Jalen Paul Oct 24 '20 at 00:42
  • Use the uri obtained in onActivityResult directly. There is no file path here. Dont use data.path (as it is no file system payh) but have a look at data.string to see a nice content scheme. – blackapps Oct 24 '20 at 06:51

0 Answers0