Android Question Index PdfReader error.

WebQuest

Active Member
Licensed User
I'm getting an error when scrolling through the pages of pdf files. the last error page of (INDEX). Has anyone had the same problem? How to solve?

B4X:
Sub Process_Globals

    Dim Chooser As ContentChooser
    Dim pdf As PDFRenderer

End Sub
B4X:
Sub Globals
    Private ImageViewResult As ImageView
 
    Private BTprev As Button
    Private BtNext As Button
    Private LPage As Label
    Private LPages As Label
 
 Dim FilePdf As String

End Sub
B4X:
Sub Activity_Create(FirstTime As Boolean)
 
    Activity.LoadLayout("PDF")

LPage.Text=1
LPage.Tag=1



End Sub
B4X:
Sub ImageViewAggPDF_Click

    Chooser.Initialize("Chooser")
    Chooser.Show("application/pdf","Select an Pdf")

    ToastMessageShow("Select PDF",True)

End Sub

Sub chooser_Result ( Success As Boolean, Dir As String, FileName As String)
 
    If Success Then
        File.Copy(Dir,FileName,File.DirInternalCache,"PdfFile.pdf")
        pdf.Initialize("",File.DirInternalCache,"PdfFile.pdf")
        LPages.Text=pdf.PageCount
        LPages.Tag=pdf.PageCount
        LPage.Text=1
        LPage.Tag=1
        For i =0 To pdf.PageCount -1
        ImageViewResult.Bitmap = pdf.renderPageforDisplay(i)
        Next
    Else
        ToastMessageShow("No PDF SELECT",True)
    End If

B4X:
Sub BTprev_Click
    Dim p As Int = LPage.Tag
 
If p < 1 Then
     
    Else
    If p > 1 Then
    p = p-1
    LPage.Text = p
    LPage.Tag = p
 
    ImageViewResult.Bitmap = pdf.renderPageforDisplay(p)
 
    End If
End If
End Sub
The problem comes when I click the button Next page Ex. The pdf is 10 pages arrived on page 9 the next generates the error.
B4X:
Sub BtNext_Click

    Dim p As Int = LPage.Tag
    Dim p2 As Int = LPages.Tag
 
 If p <> LPages.Text  Then
      If p < p2 Then
            p = p +1
            LPage.Text = p
            LPage.Tag = p
     
            ImageViewResult.Bitmap = pdf.renderPageforDisplay(p)
 
     End If
 End If

End Sub
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
aren´t the pages starting from 0?
So when you have 10 Pages you should go through 0 to 9.
 
Upvote 0

WebQuest

Active Member
Licensed User
I solved that:
B4X:
Sub BTprev_Click
    Dim p As Int = LPage.Tag
    If p > 0 Then
            p = p-1
            LPage.Text = p+1
            LPage.Tag = p
 
            ImageViewResult.Bitmap = pdf.renderPageforDisplay(p)
 
        End If
    
End Sub

Sub BtNext_Click
    Dim p As Int = LPage.Tag
    Dim p2 As Int = LPages.Tag
 
    If LPages.Text=LPage.Text Then
        Else
    
        If p-1 < p2-1 Then
            p = p +1
            LPage.Text = p+1
            If LPage.Tag>LPages.Tag Then
                Else
            LPage.Tag = p
            End If
        End If
    
            ImageViewResult.Bitmap = pdf.renderPageforDisplay(p)
 
        End If

End Sub
 
Upvote 0

Similar Threads

Top