Android Question Scroll Page not working in Pdf File

junaidahmed

Well-Known Member
Licensed User
Longtime User
I have an Pdf file with four page.I would like to scroll last page when I open pdf file in "pdfviewer".I have tried below code but its not working.Please check below code and attached file for your reference.

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

Attachments

  • H&M_PO_310379-6955_2018[1].pdf
    226.6 KB · Views: 144

DonManfred

Expert
Licensed User
Longtime User
Try to add a
B4X:
Sleep(0)
before the ScrollToPage

I first set the zoom, then scroll.

In my case i am using

B4X:
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)
        pc=pdf.GetPageCount
        pdf.zoom(1.0)
        Sleep(0)
        pdf.scrollToPage(4)
   End If
    
End Sub
And it successfully scrolls to the last page
 
Upvote 0
Top