B4A Library PDFium - Pdfview2

This is a wrap for a PDF-View which is based on PDFium.
It is based on these two Github-Projects: Pdfium and Android PDF-View
The PDF-View is based on Pdfium 1.9

The Library, resp. the Natives inside, are 64bit Compliant btw.

It supports Horizontal and Vertical scrolling, Pagesnap.

PDFium

Author: Bartosz Schiller (Pdfium), DonManfred(wrap)
Version: 1.0
  • Configurator
    • Events:
      • loadComplete (pages As Int)
      • onInitiallyRendered (page As Int)
      • onPageChanged (oldPage As Int, newPage As Int)
      • PageNum (page As Int)
      • Show()
    • Functions:
      • addLinkHandler As Configurator
      • addOnDrawListener As Configurator
      • addOnErrorListener As Configurator
      • addOnLoadCompleteListener As Configurator
      • addOnPageChangeListener As Configurator
      • addOnPageErrorListener As Configurator
      • addOnPageScrollListener As Configurator
      • addOnRenderListener As Configurator
      • addOnTapListener As Configurator
      • addScrollHandle As Configurator
      • autoSpacing (autoSpacing As Boolean) As Configurator
      • defaultPage (defaultPage As Int) As Configurator
      • enableAnnotationRendering (annotationRendering As Boolean) As Configurator
      • enableAntialiasing (antialiasing As Boolean) As Configurator
      • enableDoubletap (enableDoubletap As Boolean) As Configurator
      • enableSwipe (enableSwipe As Boolean) As Configurator
      • IsInitialized As Boolean
      • load As Configurator
      • nightMode (nightMode As Boolean) As Configurator
      • pageFitPolicy (pageFitPolicy As com.github.barteksc.pdfviewer.util.FitPolicy) As Configurator
      • pageFling (pageFling As Boolean) As Configurator
      • pages (pageNumbers As Int) As Configurator
      • pageSnap (pageSnap As Boolean) As Configurator
      • password (password As String) As Configurator
      • SetEventname (EventName As String)
      • spacing (spacing As Int) As Configurator
      • swipeHorizontal (swipeHorizontal As Boolean) As Configurator
  • PDFView
    • Functions:
      • BringToFront
      • DesignerCreateView (base As Panel, lw As Label, props As Map)
      • doAutoSpacing As Boolean
      • doPageFling As Boolean
      • doPageSnap As Boolean
      • doRenderDuringScale As Boolean
      • enableAnnotationRendering (annotationRendering As Boolean)
      • enableAntialiasing (enableAntialiasing As Boolean)
      • enableRenderDuringScale (renderDuringScale As Boolean)
      • fitToWidth (page As Int)
      • fromAsset (assetName As String) As com.github.barteksc.pdfviewer.PDFView.Configurator
        Use an asset file as the pdf source
      • fromBytes (bytes As Byte()) As com.github.barteksc.pdfviewer.PDFView.Configurator
        Use bytearray as the pdf source, documents is not saved
      • fromFile (path As String, filename As String) As com.github.barteksc.pdfviewer.PDFView.Configurator
        Use a file as the pdf source
        path:
        filename:
      • fromSource (docSource As com.github.barteksc.pdfviewer.source.DocumentSource) As com.github.barteksc.pdfviewer.PDFView.Configurator
        Use custom source as pdf source
      • fromStream (stream As java.io.InputStream) As com.github.barteksc.pdfviewer.PDFView.Configurator
        Use stream as the pdf source. Stream will be written to bytearray, because native code does not support Java Streams
      • fromUri (path As String, filename As String) As com.github.barteksc.pdfviewer.PDFView.Configurator
        Use URI as the pdf source, for use with content providers
      • getLinks (page As Int) As java.util.List
        Will be empty until document is loaded
      • getPageAtPositionOffset (positionOffset As Float) As Int
        Get page number at given offset
        positionOffset: scroll offset between 0 and 1
        Return type: @return:page number at given offset, starting from 0
      • getPageSize (pageIndex As Int) As com.shockwave.pdfium.util.SizeF
      • Initialize (EventName As String)
      • Invalidate
      • Invalidate2 (arg0 As android.graphics.Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • jumpTo (page As Int)
      • jumpTo2 (page As Int, withAnimation As Boolean)
        Go to the given page.
        page: Page index.
      • loadPages
        Load all the parts around the center of the screen,
        taking into account X and Y offsets, zoom level, and
        the current page displayed
      • moveRelativeTo (dx As Float, dy As Float)
        Move relatively to the current position.
        dx: The X difference you want to apply.
        dy: The Y difference you want to apply.
      • moveTo (offsetX As Float, offsetY As Float)
      • moveTo2 (offsetX As Float, offsetY As Float, moveHandle As Boolean)
        Move to the given X and Y offsets, but check them ahead of time
        to be sure not to go outside the the big strip.
        offsetX: The big strip X offset to use as the left border of the screen.
        offsetY: The big strip Y offset to use as the right border of the screen.
        moveHandle: whether to move scroll handle or not
      • onBitmapRendered (part As com.github.barteksc.pdfviewer.model.PagePart)
        Called when a rendering task is over and
        a PagePart has been freshly created.
        part: The created PagePart.
      • performPageSnap
        Animate to the nearest snapping position for the current SnapPolicy
      • recycle
      • RemoveView
      • RequestFocus As Boolean
      • resetZoom
      • resetZoomWithAnimation
      • SendToBack
      • SetBackgroundImage (arg0 As android.graphics.Bitmap) As BitmapDrawable
      • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
      • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
      • setPositionOffset2 (progress As Float, moveHandle As Boolean)

        progress: must be between 0 and 1
        moveHandle: whether to move scroll handle
      • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
      • stopFling
      • toCurrentScale (size As Float) As Float
      • toRealScale (size As Float) As Float
      • useBestQuality (bestQuality As Boolean)
      • zoomCenteredRelativeTo (dzoom As Float, pivot As android.graphics.PointF)
      • zoomCenteredTo (zoom As Float, pivot As android.graphics.PointF)
        Change the zoom level, relatively to a pivot point.
        It will call moveTo() to make sure the given point stays
        in the middle of the screen.
        zoom: The zoom level.
        pivot: The point on the screen that should stays.
      • zoomTo (zoom As Float)
        Change the zoom level
      • zoomWithAnimation (scale As Float)
      • zoomWithAnimation2 (centerX As Float, centerY As Float, scale As Float)
    • Properties:
      • AnnotationRendering As Boolean [read only]
      • Antialiasing As Boolean [read only]
      • Background As android.graphics.drawable.Drawable
      • BestQuality As Boolean [read only]
      • Color As Int [write only]
      • CurrentPage As Int [read only]
      • CurrentXOffset As Float [read only]
      • CurrentYOffset As Float [read only]
      • documentFitsView As Boolean [read only]
        Checks if whole document can be displayed on screen, doesn't include zoom
      • DocumentMeta As com.shockwave.pdfium.PdfDocument.Meta [read only]
        Returns null if document is not loaded
      • Enabled As Boolean
      • Height As Int
      • Left As Int
      • MaxZoom As Float
      • MidZoom As Float
      • MinZoom As Float
      • NightMode As Boolean [write only]
      • Padding As Int()
      • PageCount As Int [read only]
      • pageFillsScreen As Boolean [read only]
      • PageFitPolicy As com.github.barteksc.pdfviewer.util.FitPolicy [read only]
      • PageFling As Boolean [write only]
      • PageSnap As Boolean [write only]
      • Parent As Object [read only]
      • PositionOffset As Float
        Get current position as ratio of document length to visible area.
        0 means that document start is visible, 1 that document end is visible
      • Recycled As Boolean [read only]
      • SpacingPx As Int [read only]
      • SwipeEnabled As Boolean
      • SwipeVertical As Boolean [read only]
      • TableOfContents As java.util.List [read only]
        Will be empty until document is loaded
      • Tag As Object
      • Top As Int
      • Visible As Boolean
      • Width As Int
      • Zoom As Float [read only]
      • Zooming As Boolean [read only]
  • PdfDocument
    • Functions:
      • hasPage (index As Int) As Boolean
      • Initialize (doc As com.shockwave.pdfium.PdfDocument)
      • IsInitialized As Boolean
  • PdfDocumentMeta
    • Functions:
      • IsInitialized As Boolean
    • Properties:
      • CreationDate As String [read only]
      • Creator As String [read only]
      • Keywords As String [read only]
      • ModDate As String [read only]
      • Producer As String [read only]
      • Subject As String [read only]
      • Title As String [read only]
  • PdfSize
    • Functions:
      • equals (obj As Object) As Boolean
      • Initialize (width As Int, height As Int)
      • IsInitialized As Boolean
    • Properties:
      • Height As Int [read only]
      • Width As Int [read only]
  • PdfiumCore
    • Functions:
      • closeDocument (doc As com.shockwave.pdfium.PdfDocument)
        Release native resources and opened file
      • getDocumentMeta (doc As com.shockwave.pdfium.PdfDocument) As com.shockwave.pdfium.PdfDocument.Meta
        Get metadata for given document
      • getNumFd (fdObj As android.os.ParcelFileDescriptor) As Int
      • getPageCount (doc As com.shockwave.pdfium.PdfDocument) As Int
        Get total numer of pages in document
      • getPageHeight (doc As com.shockwave.pdfium.PdfDocument, index As Int) As Int
        Get page height in pixels. <br>
        This method requires page to be opened.
      • getPageHeightPoint (doc As com.shockwave.pdfium.PdfDocument, index As Int) As Int
        Get page height in PostScript points (1/72th of an inch).<br>
        This method requires page to be opened.
      • getPageLinks (doc As com.shockwave.pdfium.PdfDocument, pageIndex As Int) As java.util.List
        Get all links from given page
      • getPageSize (doc As com.shockwave.pdfium.PdfDocument, index As Int) As com.shockwave.pdfium.util.Size
        Get size of page in pixels.<br>
        This method does not require given page to be opened.
      • getPageWidth (doc As com.shockwave.pdfium.PdfDocument, index As Int) As Int
        Get page width in pixels. <br>
        This method requires page to be opened.
      • getPageWidthPoint (doc As com.shockwave.pdfium.PdfDocument, index As Int) As Int
        Get page width in PostScript points (1/72th of an inch).<br>
        This method requires page to be opened.
      • getTableOfContents (doc As com.shockwave.pdfium.PdfDocument) As java.util.List
        Get table of contents (bookmarks) for given document
      • Initialize (EventName As String)
      • loadComplete (arg0 As Int)
      • mapPageCoordsToDevice (doc As com.shockwave.pdfium.PdfDocument, pageIndex As Int, startX As Int, startY As Int, sizeX As Int, sizeY As Int, rotate As Int, pageX As Double, pageY As Double) As android.graphics.Point
        Map page coordinates to device screen coordinates
        doc: pdf document
        pageIndex: index of page
        startX: left pixel position of the display area in device coordinates
        startY: top pixel position of the display area in device coordinates
        sizeX: horizontal size (in pixels) for displaying the page
        sizeY: vertical size (in pixels) for displaying the page
        rotate: page orientation: 0 (normal), 1 (rotated 90 degrees clockwise),
        2 (rotated 180 degrees), 3 (rotated 90 degrees counter-clockwise)
        pageX: X value in page coordinates
        pageY: Y value in page coordinate
        Return type: @return:mapped coordinates
      • mapRectToDevice (doc As com.shockwave.pdfium.PdfDocument, pageIndex As Int, startX As Int, startY As Int, sizeX As Int, sizeY As Int, rotate As Int, coords As android.graphics.RectF) As android.graphics.RectF

        Return type: @return:mapped coordinates
      • onPageChanged (arg0 As Int, arg1 As Int)
      • onPageError (arg0 As Int, arg1 As Throwable)
      • openPage (doc As com.shockwave.pdfium.PdfDocument, pageIndex As Int) As Long
        Open page and store native pointer in {@link PdfDocument}
      • renderPage (doc As com.shockwave.pdfium.PdfDocument, surface As android.view.Surface, pageIndex As Int, startX As Int, startY As Int, drawSizeX As Int, drawSizeY As Int)
        Render page fragment on {@link Surface}.<br>
        Page must be opened before rendering.
      • renderPage2 (doc As com.shockwave.pdfium.PdfDocument, surface As android.view.Surface, pageIndex As Int, startX As Int, startY As Int, drawSizeX As Int, drawSizeY As Int, renderAnnot As Boolean)
        Render page fragment on {@link Surface}. This method allows to render annotations.<br>
        Page must be opened before rendering.
      • renderPageBitmap (doc As com.shockwave.pdfium.PdfDocument, bitmap As android.graphics.Bitmap, pageIndex As Int, startX As Int, startY As Int, drawSizeX As Int, drawSizeY As Int)
        Render page fragment on {@link Bitmap}.<br>
        Page must be opened before rendering.
        <p>
        Supported bitmap configurations:
        <ul>
        <li>ARGB_8888 - best quality, high memory usage, higher possibility of OutOfMemoryError
        <li>RGB_565 - little worse quality, twice less memory usage
        </ul>
      • renderPageBitmap2 (doc As com.shockwave.pdfium.PdfDocument, bitmap As android.graphics.Bitmap, pageIndex As Int, startX As Int, startY As Int, drawSizeX As Int, drawSizeY As Int, renderAnnot As Boolean)
        Render page fragment on {@link Bitmap}. This method allows to render annotations.<br>
        Page must be opened before rendering.
        <p>
        For more info see {@link PdfiumCore#renderPageBitmap(PdfDocument, Bitmap, int, int, int, int, int)}

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private btnFirst As Button
    Private btnPrev As Button
    Private lblPages As Label
    Private btnNext As Button
    Private btnLast As Button
    Private glPages As Int
    Dim pdf As PdfiumCore
    Private PDFView1 As PDFView
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
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)


Due to the Size of the native .so Files the library is big (18mb) and can be downloaded from my Dropbox.
The Example is to big (2mb) too so it is available on Dropbox too.

Copyright 2017 Bartosz Schiller

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Please respect License if you want to use it in your project.

Linked Tutorials:
- Access to the PDF Pages and create a Bitmap containing a specific Page.
 
Last edited:

hayk

Member
Not with this Library.
Can you please suggest me PDF viewer library with search function and with possibility to open password protected PDF files.
The only library ,witch I found has required functions, was PDFViewer (by Icefairy333) - reworked by DonManfred, but it's pretty old, I couldn't make it work properly.
Here is
LOG:
Logger connected to:  Xiaomi Redmi Note 7
--------- beginning of system
--------- beginning of crash
--------- beginning of main
java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/user/0/b4a.example/files/libpdfview2.so" not found
    at java.lang.Runtime.load0(Runtime.java:938)
    at java.lang.System.load(System.java:1631)
    at ice.pdfviewer.pdfviewerwrapper.init(pdfviewerwrapper.java:109)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at b4a.example.main._load_pdf(main.java:429)
    at b4a.example.main._activity_create(main.java:416)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Error occurred on line: 72 (Main)
java.lang.RuntimeException: Object should first be initialized (PDFViewer).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Error occurred on line: 82 (Main)
java.lang.Exception: array not expected...
** Activity (main) Create, isFirst = true **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (main) Create, isFirst = true **
copy lib
java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/user/0/b4a.example/files/libpdfview2.so" not found
    at java.lang.Runtime.load0(Runtime.java:938)
    at java.lang.System.load(System.java:1631)
    at ice.pdfviewer.pdfviewerwrapper.init(pdfviewerwrapper.java:109)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at b4a.example.main._load_pdf(main.java:429)
    at b4a.example.main._activity_create(main.java:416)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Error occurred on line: 72 (Main)
java.lang.RuntimeException: Object should first be initialized (PDFViewer).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Error occurred on line: 82 (Main)
java.lang.Exception: array not expected...
** Activity (main) Create, isFirst = true **
copy lib
java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/user/0/b4a.example/files/libpdfview2.so" not found
    at java.lang.Runtime.load0(Runtime.java:938)
    at java.lang.System.load(System.java:1631)
    at ice.pdfviewer.pdfviewerwrapper.init(pdfviewerwrapper.java:109)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
** Activity (main) Resume **
Error occurred on line: 72 (Main)
java.lang.RuntimeException: Object should first be initialized (PDFViewer).
Did you forget to call Activity.LoadLayout?
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at b4a.example.main.afterFirstLayout(main.java:111)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Error occurred on line: 82 (Main)
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')
** Activity (main) Create, isFirst = true **
copy lib
java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/user/0/b4a.example/files/libpdfview2.so" not found
    at java.lang.Runtime.load0(Runtime.java:938)
    at java.lang.System.load(System.java:1631)
    at ice.pdfviewer.pdfviewerwrapper.init(pdfviewerwrapper.java:109)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:105)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
** Activity (main) Resume **
Error occurred on line: 72 (Main)
java.lang.RuntimeException: Object should first be initialized (PDFViewer).
Did you forget to call Activity.LoadLayout?
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at b4a.example.main.afterFirstLayout(main.java:111)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7590)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Error occurred on line: 82 (Main)
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.lang.Boolean (java.lang.String and java.lang.Boolean are in module java.base of loader 'bootstrap')

And thanks for respond!
 

DonManfred

Expert
Licensed User
Longtime User

stevenindon

Active Member
Licensed User
Hi all,

How can i clear a loaded pdf in PDFview? I tried PDFView1.RemoveView but seems that it removes the view panel... I have search through the forum but couldn't find a solution for this.
 

hayk

Member
Could someone help our community, to add "search" ability to "pdfium" library or help to wrap and share new PDF viewer library, which will able to open password protected files, will be able to search text in PDF document, will be free licensed and . Required library will be useful for all our community.

Here are Top 5 Android PDF Library/SDK according Google
PDFTron Mobile PDF SDK. Great PDF rendering on Android: Rendered PDFs are accurate, optimized, high quality and robust. ...
  • PDF Toolkit - PDF SDK for Android. ...
  • PDF JET. ...
  • FOXIT Embedded PDF SDK for Android. ...
  • Apache PDFBox.
Ready to support developer by ? DONATION!
 

DonManfred

Expert
Licensed User
Longtime User
ere are Top 5 Android PDF Library/SDK according Google
PDFTron Mobile PDF SDK. Great PDF rendering on Android: Rendered PDFs are accurate, optimized, high quality and robust. ...
  • PDF Toolkit - PDF SDK for Android. ...
  • PDF JET. ...
  • FOXIT Embedded PDF SDK for Android. ...
  • Apache PDFBox.
Unfortunately only one of them is free, PDFBox.
I wrote a wrapper for PDFBox for B4J already.

Based on this Github-Project i am actually doing a Android wrap for PDFBox.
 

hayk

Member

hayk

Member
I'm offering 200$ for B4A PDFBox library, which will be able to open password protected pdf files & will have search function. And will be happy to share it with B4X community.
Offer is valid for 2 months after this post
I wrote a wrapper for PDFBox for B4J already.
Based on this Github-Project i am actually doing a Android wrap for PDFBox.
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
I'm offering 200$ for B4A PDFBox library, which will be able to open password protected pdf files & will have search function. And will be happy to share it with B4X community.
do you have example PDFs which you want to search into and/or which are password-protected?
Can you provide them?
 

hayk

Member
Thank you very much for your support! :)
PDF example file you can download from here, it is just a regular PDF file with preview password protection. password is "123".

1.jpg

- "Search" like in Adobe PDF android app, text matches are getting highlighted & using arrows possible jump to pages with other matches. like in upper image.
- Password must be possible to inject trough code, like in PDFium library .

PDFium library is also not bad, adding search text capabilities to this library will be good enough.
 

hayk

Member
do you have example PDFs which you want to search into and/or which are password-protected?
Can you provide them?
Thank you very much for your respond. :)
PDF file example you can find here. It's just an preview password protected PDF file. The password is "123".

Features like in Adobe PDF Android app (see attached "1.jpg") will be great. Matched texts are getting highlighted and possible jump to next match. Two directional ( using arrows "<" & ">" like in adobe pdf app) match highlighting would be great. Also events like "on_load_Complete" , "on_Tap" , "on_Page_Changed" , "on_Error" would be great too.

PDFium library is also not bad, adding search text capabilities to this library will be good enough.
 

Attachments

  • 1.jpg
    1.jpg
    232.9 KB · Views: 185

hayk

Member
This will not happen with PDFium!
I can build a searchmethod (if the pdf is searchable at all. It will not work with PDFs based on Images. The content must be TEXT) but i am not able to change pdfium at all.
searchmethod as a function or library? It gonna work with 3rd party pdf viewer? Or a wrap pdfbox for B4A?
 

hayk

Member
This will not happen with PDFium!
I can build a searchmethod (if the pdf is searchable at all. It will not work with PDFs based on Images. The content must be TEXT) but i am not able to change pdfium at all.
My friend, if you are taking the job, I can pay you 20% in advance.
 

DonManfred

Expert
Licensed User
Longtime User
My friend, if you are taking the job, I can pay you 20% in advance.
that´s not the problem. Problem with the newest Github-project for pdfbox-android is that there are Resources inside the aar which not get found when using the aar in B4A.

In Android Studio it gets implemented in another way. Internal the library is using an AndroidAsset Manager which works in an AS-Projects.
But i can´t get it working in B4A as of now...

Still investigating what needs to be done :-(
 

hayk

Member
that´s not the problem. Problem with the newest Github-project for pdfbox-android is that there are Resources inside the aar which not get found when using the aar in B4A.

In Android Studio it gets implemented in another way. Internal the library is using an AndroidAsset Manager which works in an AS-Projects.
But i can´t get it working in B4A as of now...

Still investigating what needs to be done :-(
Ok, I'll wait. Thank you.
 

DonManfred

Expert
Licensed User
Longtime User
Top