How to get the current page number of a PDF in Android -
i have implement custom pdf viewer in android application, have implemented this:
https://github.com/barteksc/androidpdfviewer
to open pdf used function:
/* load pdf in activity */ private void openpdf(){ file file = new file(environment.getexternalstoragedirectory().getabsolutepath() +"/download/verbale.pdf"); pdfview pdfview = (pdfview) findviewbyid(r.id.pdfview); pdfview.fromfile(file) .defaultpage(0) .enableannotationrendering(true) .onload(this) .onpagechange(this) .scrollhandle(new defaultscrollhandle(this)) .load(); }
the pdf correctly rendered need page number of page during scroll.
how can ?
i have tried use this:
pdfview.getcurrentpage() pdfview.getpagecount()
but not doesn't work...
solution
@override public void loadcomplete(int nbpages) { totalpages = nbpages; } @override public void onpagechanged(int page, int pagecount) { //page contains che current page }
you can take @ official example of androidpdfviewer: link
take @ 2 snippets example:
1) create pdfview:
pdfview.fromasset(sample_file) .defaultpage(pagenumber) .onpagechange(this) .enableannotationrendering(true) .onload(this) .scrollhandle(new defaultscrollhandle(this)) .load();
2) , implement onpagechanged(..):
@override public void onpagechanged(int page, int pagecount) { pagenumber = page; //do want pagenumber }
also don't forget implement onpagechangelistener
Comments
Post a Comment