1

I have seen many question about accessing files in assets folder but can't seem to get a solid answer. I'm working on a application that would extract a text from PDF file thus I'm using iText Library to do that but my problem here is the file pathing of PDF.

I have tried using assetManager and assetManager opens that file but i think iText needs the file path so it can open the file by itself, i am not sure but that is my theory.

PdfReader reader = new PdfReader(<String PDF-file>);

then How do I access the file under assets folder using iText? if it is not possible is there a way to do that?

Christian Eric Paran
  • 980
  • 6
  • 27
  • 49

3 Answers3

2

Here is sample code to get asset directory for file and use it for pdfreader.

code:

File f = FileUtils.fileFromAsset(this, "filename.pdf");

PdfReader pdfReader = new PdfReader(f.getPath());
PMerlet
  • 2,568
  • 4
  • 23
  • 39
Rick
  • 21
  • 2
1

You can get an InputStream object like this

AssetManager am = activity.getAssets();
InputStream is = am.open("test.txt");

and then use this constructor

public PdfReader(InputStream is)
          throws IOException

http://api.itextpdf.com/itext/com/itextpdf/text/pdf/PdfReader.html#PdfReader(java.io.InputStream)

Korniltsev Anatoly
  • 3,676
  • 2
  • 26
  • 37
0

I have solved my problem my using this:

reader = new PdfReader(getResources().openRawResource(R.raw.resume));

Christian Eric Paran
  • 980
  • 6
  • 27
  • 49