Reputation: 79
I want to select the path of my pdf
file in
private static final int DIALOG_LOAD_FILE = 1000;
I have two buttons,one to get the path of the pdf file and the other to extraxt the text:
Button b1 = (Button) x.findViewById(R.id.buttonStripText);
Button button = (Button) x.findViewById(R.id.pick);
button.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent,DIALOG_LOAD_FILE);
}
});
b1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
stripText(v);
}
});
And the other two functions are
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
switch(requestCode){
case DIALOG_LOAD_FILE:
if(resultCode==RESULT_OK){
fileName = data.getData().getPath();
System.out.println("Your File Name is:::"+fileName);
}
break;
}
}
private void setup() {
PDFBoxResourceLoader.init(getActivity().getApplicationContext());
root = android.os.Environment.getExternalStorageDirectory();
assetManager = getActivity().getAssets();
}
public void stripText(View v) {
String parsedText = null;
try {
PDDocument document = PDDocument.load(assetManager.open("cover_letter.pdf"));
PDFTextStripper pdfStripper = new PDFTextStripper();
pdfStripper.setStartPage(0);
pdfStripper.setEndPage(1);
parsedText = "Parsed text: " + pdfStripper.getText(document);
if (document != null) document.close();
} catch (Exception e) {
e.printStackTrace();
}
tv.setText(parsedText);
}
I doesn't throw any error but also it doesn't get the extracted text.
This kind of Dialog_Load_File
opens google drive,if possible to show me how to open internal storage!
Any Help would be appreciated!
Upvotes: 0
Views: 89
Reputation: 11224
PDDocument document = PDDocument.load(assetManager.open("cover_letter.pdf"));
PDDocument document = PDDocument.load(... from any input stream .... );
So if you can open an inputstream from assets or raw or from file or from uri you are done.
For instance if you get an uri in onActivityResult
InputStream is = getContentResolver().openInputStream(data.getData());
PDDocument document = PDDocument.load( is );
Upvotes: 1