I am converting an app from B4i where the user can view a number of reference assets. Those assets are .htm .jpg .png and .pdf files. In B4i the native WebView will happily handle all of those but the Android WebView will not accept .pdf files so I am looking for an alternative view just to handle the .pdf. It appears the choices are limited so I have arrived at the PDFium library but I am having problems getting it to work..... I have some questions..
- I notice from the example PDFiumEx that the pdf is differently loaded from File.DirAssets and File.DirInternal for the View and the Configurator. Is that required, or can it be opened directly form File.DirAssets?
- Is the Configurator code required to facilitate simple navigation gestures, or can it be omitted?
- If you set PDFview1.Visible = False in the designer, after loading it appears to become visible by default. Is this intentional?
- I don't need any of the event functionality but the absence of a PDFium_loadComplete event throws an exception every time. Are the empty events required in code?
- Using the minimal code below I get nothing but an empty white container every time.... The code PDFiumEx.b4a bundled with the lib shows admirably the entire functionality but I am looking for a minimalist example simply to display a 1-3 page pdf.
- I notice from the example PDFiumEx that the pdf is differently loaded from File.DirAssets and File.DirInternal for the View and the Configurator. Is that required, or can it be opened directly form File.DirAssets?
- Is the Configurator code required to facilitate simple navigation gestures, or can it be omitted?
- If you set PDFview1.Visible = False in the designer, after loading it appears to become visible by default. Is this intentional?
- I don't need any of the event functionality but the absence of a PDFium_loadComplete event throws an exception every time. Are the empty events required in code?
- Using the minimal code below I get nothing but an empty white container every time.... The code PDFiumEx.b4a bundled with the lib shows admirably the entire functionality but I am looking for a minimalist example simply to display a 1-3 page pdf.
B4X:
#AdditionalJar: android-pdf-viewer.aar
#AdditionalJar: com.android.support:support-v4
#AdditionalJar: Pdfium.aar
Sub Globals
Private pdf As PdfiumCore
Private PDFView1 As PDFView 'from the designer
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1")
pdf.Initialize("PDFium")
ShowThePDF
End Sub
Sub ShowThePDF
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) 'this was the error
cfg.autoSpacing(True).enableSwipe(True).pageSnap(True).true 'corrected syntax
End Sub
Last edited: