Android Question Index PdfReader error.

WebQuest

Active Member
Licensed User
Longtime 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?

Code: Copy
Sub Process_Globals

    Dim Chooser As ContentChooser
    Dim pdf As PDFRenderer

End Sub
Code: Copy
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
Code: Copy
Sub Activity_Create(FirstTime As Boolean)
 
    Activity.LoadLayout("PDF")

LPage.Text=1
LPage.Tag=1



End Sub
Code: Copy
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

Code: Copy
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.
Code: Copy
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:
aren´t the pages starting from 0?
So when you have 10 Pages you should go through 0 to 9.
 
Upvote 0
I solved that:
Code: Copy
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

Replies
3
Views
3K
  • Article Article
Android Code Snippet [B4X] Open PDF
Replies
2
Views
4K
Replies
0
Views
2K
Replies
22
Views
42K
Back
Top