View PDF on android

Asked

Viewed 2,389 times

1

I need to insert a pdf into my application; how could I do that ? Is there a pdf view? The pdf will be inside the application itself in the Assets folder. Thank you.

1 answer

2

Just a tip on Java and android, there is no way to put applications inside ./assets and runs them, what you do is use a Intent to access another application installed on Android or else you put a library (.java or .jar) in your project that gives the ability of your application to read Pdfs.

To view the PDF with the standard reader of the device you can use the code quoted in this reply on Soen:

File file = new File("CAMINHO DO SEU PDF/example.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);

If there might be a possibility that there might not be an app for reading, maybe you want to use a library like ieee8023/Pdfviewer, in this case you will also need to use a Intent, is well updated but requires documentation.

Alternatively you can view this repository https://github.com/JoanZapata/android-pdfview, to use it do something like:

pdfView.fromAsset("CAMINHO DO SEU PDF/example.pdf")
    .pages(0, 2, 1, 3, 3, 3)
    .defaultPage(1)
    .showMinimap(false)
    .enableSwipe(true)
    .onDraw(onDrawListener)
    .onLoad(onLoadCompleteListener)
    .onPageChange(onPageChangeListener)
    .load();
  • friend , but in this case it would migrate to another correct application ? I wanted it open in a kind of view within the app itself

  • Augusto I think not, the first example just calls, it is long since not working with Android, but the second example pdfView.fromAsset I’m pretty sure it opens inside your app :)

  • 1

    Okay thanks, I’ll take a look

Browser other questions tagged

You are not signed in. Login or sign up in order to post.