#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
#AdditionalJar: android-pdf-viewer.aar
#AdditionalJar: com.android.support:support-v4
#AdditionalJar: Pdfium.aar
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
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 PdfiumCore
Private PDFView1 As PDFView
Private btnFirst As Button
Private btnPrev As Button
Private lblPages As Label
Private btnNext As Button
Private btnLast As Button
Private glPages As Int
Private imgPDF As ImageView
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")
pdf.Initialize("PDFium")
File.Copy(File.DirAssets,"sample.pdf",File.DirInternal,"sample.pdf")
Dim cfg As Configurator = PDFView1.fromUri(File.DirInternal,"sample.pdf")
cfg.SetEventname("PDFium")
cfg.autoSpacing(True).enableSwipe(True).pageSnap(True).swipeHorizontal(False).addOnErrorListener.addOnLoadCompleteListener.addOnPageChangeListener.addOnPageErrorListener.addOnTapListener.load
'***** FOR RENDERING ************************
RenderPDFThumbnail("sample.pdf",3) '3 = page 3
'************************************************
End Sub
Sub PDFium_loadComplete(pages As Int)
Log($"PDFium_loadComplete(${pages})"$)
glPages = pages
lblPages.Text = $"${glPages}"$
End Sub
Sub PDFium_onInitiallyRendered(page As Int)
Log($"PDFium_onInitiallyRendered(${page})"$)
End Sub
Sub PDFium_onPageChanged(page As Int, TotalPages As Int)
Log($"PDFium_onPageChanged(${page},${TotalPages})"$)
lblPages.Text = $"${page-1}/${glPages}"$
End Sub
Sub PDFium_PageNum(page As Int)
Log($"PDFium_PageNum(${page})"$)
End Sub
Sub PDFium_Show()
Log($"PDFium_Show()"$)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnFirst_Click
PDFView1.jumpTo2(0,False)
End Sub
Sub btnPrev_Click
PDFView1.jumpTo2(PDFView1.CurrentPage-1,False)
End Sub
Sub lblPages_Click
End Sub
Sub btnNext_Click
PDFView1.jumpTo2(PDFView1.CurrentPage+1,False)
End Sub
Sub btnLast_Click
PDFView1.jumpTo2(glPages-1,False)
End Sub
'***** FOR RENDERING *************************************************************************************
Sub RenderPDFThumbnail(TheFilename As String, page As Int)
Dim NewBitmap As Bitmap
Dim bmp As Bitmap
Dim glDoc As Object
glDoc = pdf.newDocument(File.DirInternal,TheFilename, 268435456,"")
bmp.InitializeMutable(600dip,600dip)
pdf.openPage(glDoc,page)
pdf.renderPageBitmap(glDoc,bmp,page,0,0,600dip,600dip)
Dim out As OutputStream = File.OpenOutput(File.DirInternal, "Out.jpg", False)
bmp.WriteToStream(out, 80, "JPEG")
out.Close
NewBitmap = LoadBitmap(File.DirInternal, "Out.jpg")
imgPDF.Bitmap = NewBitmap
End Sub