0

I would like to use PdfRenderer to display the myDoc.pdf within the application:

File file = new File("/sdcard/Download/myDoc.pdf");
PdfRenderer renderer 
= new PdfRenderer(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY));
...

The problem is, I want to include the myDoc.pdf in the application rather then assuming it's under /sdcard/Download/ or on some website.

How can I include the myDoc.pdf in the application and how the path to it should looks like in the code?

I use Android Studio and I assume the /res should be somehow associated with such files.

PolGraphic
  • 3,233
  • 11
  • 51
  • 108

1 Answers1

0

Hi friend you need to store your pdf file in assets folder.

Please check the stackoverflow question regarding this

Read a pdf file from assets folder

If you still have problem let me know

Community
  • 1
  • 1
Arun Antoney
  • 4,292
  • 2
  • 20
  • 26
  • Hi. I've added the `myDoc.pdf` under the `assets` folder (that I had to create under `/src/main`). I can access the `myDoc.pdf` from Android Studio and file explorer, but the application cannot load it :/ What do I wrong or what do I miss? – PolGraphic Jan 29 '15 at 10:11
  • assets folder is default folder if it is not there right click your project->new-> folder->assets folder and the path you given is wrong try to correct it – Arun Antoney Jan 29 '15 at 10:19
  • Should it be on the same level as `app`, `build` etc. then? Or inside `app`? Should I also change the `` from `app.iml`? It has been generated automatically and that's why I assumed it's the place to put my `assets` folder. – PolGraphic Jan 29 '15 at 10:30
  • no need to edit any thing in app.iml file just copy paste your file assets folder just like you copy paste images into drawable folder – Arun Antoney Jan 29 '15 at 10:37
  • No luck so far, I've tried every single subfolder as a parent for my `assets`, including project directory, `src` directory etc. I also upload the needed .pdf file into it (and I see it in Android Studio under my `assets` folder). – PolGraphic Jan 29 '15 at 10:55
  • how ur creating folder?? – Arun Antoney Jan 29 '15 at 11:12
  • RMB on project (or any subfolder I want to be a parent) -> new -> directory -> <> -> ok. I can see it being created. – PolGraphic Jan 29 '15 at 11:14
  • sorry i dont know how much you know about asset manager ,it is finding difficult to clear you you cant create assets folder as sub folder in android app its name path everything is predefined,if you need to access a file you have to provide all correctly.so first try how to create and add a file in asset folder in android – Arun Antoney Jan 29 '15 at 11:36
  • look this question too http://stackoverflow.com/questions/18302603/where-to-place-assets-folder-in-android-studio – Arun Antoney Jan 29 '15 at 11:38