AesculusMaximus
AesculusMaximus

Reputation: 195

How do I use this library

Sorry for the really basic question, but I cant find a straight forward answer.

I have tried importing this library into my android studio project as I want to be able to view pdfs from within the application:

https://github.com/JoanZapata/android-pdfview

by adding the line:

compile 'com.joanzapata.pdfview:android-pdfview:1.0.4@aar'

to my gradle.

The thing is, I haven't got a clue how to use it. I tried to copy the sample, but there are loads of errors. As an example

@ViewById
PDFView pdfView;

The @ViewById comes up saying can not resolve symbol '@ViewById'

I know I'm asking fundamental stuff and will need to research to get a full understanding but can someone point me in the right direction please?

Thanks

Upvotes: 0

Views: 450

Answers (1)

juliusmh
juliusmh

Reputation: 477

You integrate the PDFVIEW into your xml layout:

<com.joanzapata.pdfview.PDFView
    android:id="@+id/pdfview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

From then on you can access the element from code in any method of an activity exposing a layout, e.g.: in your MainActivity.java:

String assetFileName = "about.pdf"; //The name of the asset to open
int pageNumber = 0; //Start at the first page

PDFView pdfView = (PDFView) findViewById(R.id.pdfview); //Fetch the view
pdfView.fromAsset(assetFileName) //Fill it with data
            .defaultPage(pageNumber) //Set default page number
            .onPageChange(null) //PageChangeListener
            .load();
  • assetFileName = the name of the asset you want to open. The PDF-File must be placed in main/assets/ as described here . Make Sure you have an "about.pdf" in your asset folder, otherwise the code example will not work.

  • pageNumber = the page that should be shown at the beginning. You can just set it to 0 if you want the PdfViewer to start at the beginning of the .pdf file.

Upvotes: 1

Related Questions