I am trying to read a PDF file but it's throwing a NoSuchFileException
. I have seen some solution for this but nothing seems to work in my case. I want to read the PDF file. Below is my code:
private void requestForResume() {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
Intent chooser = Intent.createChooser(intent, "Upload PDF File");
startActivityForResult(chooser, REQUEST_CODE);
}
Here is how I am converting to file:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE) {
Uri uri = data.getData();
String fileName = uri.getLastPathSegment();
File resumeFile=new File(uri.getPath());
try {
PDDocument pdfResume=PDDocument.load(resumeFile);
PDFTextStripper stripper=new PDFTextStripper();
String resumeText=stripper.getText(pdfResume);
Log.d("location",resumeText);
} catch (IOException e) {
Log.d("location","unable to load pdf"+e.toString());
}
fileEditText.setText(fileName);
}
}
Please help me where I am wrong.