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)