Android Question PDFium Library - Minimalist Example - Fixed


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

#AdditionalJar: android-pdf-viewer.aar
#AdditionalJar: Pdfium.aar

Sub Globals

    Private pdf As PdfiumCore
    Private PDFView1 As PDFView        'from the designer

End Sub

Sub Activity_Create(FirstTime As Boolean)



End Sub

Sub ShowThePDF

    Dim cfg As Configurator = PDFView1.fromUri(File.DirInternal,"sample.pdf")
    '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:


Active Member
Licensed User
In the absence of any other input I have continued by trial & error so for anyone else having problems with this library here is what I learnt......

We are very used to B4A looking after us when it comes to syntax errors but the cause of several issues was not flagged by the IDE.

This: cfg.autoSpacing(True).enableSwipe(True).pageSnap(True)

Should have been: cfg.autoSpacing(True).enableSwipe(True).pageSnap(True).load

I have corrected the code above. Once that had been changed the exceptions of missing event routines went away and the pdf was correctly displayed. If you are in doubt.... The Configurator code is required and a blank page will be displayed without any error (unhelpfully) if the pdf is loaded from File.DirAssets. It must be copied to File.DirInternal and referenced from there.

The PDFview still loads as visible, regardless of the property set in the designer.
Upvote 0