Android Question How to get Current PageNo in PdfViewer When Changing the PageNo

junaidahmed

Well-Known Member
Licensed User
Longtime User
I am using Pdfviewer control.I would like to know how to get "Current pageNo" when changing the page.I have used below code but its not working...Please check below code and advise how to solve this problem...

B4X:
Sub LoadPdfVile(StrFile As String)
        
    pdfv.init
    Panel1.AddView(pdfv,5,1,Panel1.Width - 10,Panel1.Height -5)
    pdfv.getpdf(StrFile)
    If pdfv.isValid Then
        pdfv.scrollToPage(0)
        pdfv.zoom(1.0)
        
    Else
        Msgbox("Error pdf file!","Error")
        Activity.Finish
        Return
    End If
    
End Sub

Sub pdfv_onPageChanged(page As Int, pageCount As Int)
    
    Activity.Title = page & " - " & pageCount
    
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Sub pdfv_onPageChanged(page As Int, pageCount As Int)

Activity.Title = page & " - " & pageCount

End Sub

pdfviewer does not have Events!

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim pdf As PDFViewer
  Dim activepage,totalpages As Int=0
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Log("CopyFile()")
    If Not(File.Exists(File.DirRootExternal, "hm.pdf")) Then
        Log("test.pdf does not exist at DirRootExternal")
       
        File.Copy(File.DirAssets, "hm.pdf", File.DirRootExternal, "hm.pdf")
        Log("hm.pdf copied")
    End If
    pdf.init
  Activity.AddView(pdf,0,0,-1,-1)

    pdf.getpdf2(File.Combine(File.DirRootExternal,"hm.pdf"),"")

  If pdf.isValid Then
      Log("pagecount:"&pdf.GetPageCount)
    pdf.scrollToPage(0)
        totalpages=pdf.GetPageCount
        pdf.zoom(1.0)
        Sleep(0)
        pdf.scrollToPage(4)
        activepage = 4
        Activity.Title = activepage & " - " & totalpages
        'pdf.zoom(19.0)
   End If
   
End Sub
Does work as expected.
 
Last edited:
Upvote 0

junaidahmed

Well-Known Member
Licensed User
Longtime User
No,

Actually the above code works only when opening file on first time,but I would like to get active pageNo when I change the Page.
 
Upvote 0
Top