Android Question PDFium Library and Content Chooser pdf

mike1967

Member
Licensed User
hello, i have this code
B4X:
Sub btnDocumentazione_Click
    Dim CC2 As ContentChooser
    CC2.Initialize("CC2")
    CC2.Show("application/pdf", "Choose file")
    'CC.Show("image/*", "Choose image")
    'CC.Show("audio/*", "Choose audio file")
End Sub
Sub CC2_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        'imgView.Bitmap=LoadBitmapSample(Dir,FileName,800,600)
        Dim cfg As Configurator = PDFView1.FROMURI(Dir,FileName)
        cfg.autoSpacing(True).enableSwipe(True).pageSnap(True).swipeHorizontal(False).addOnErrorListener.addOnLoadCompleteListener.addOnPageChangeListener.addOnPageErrorListener.addOnTapListener.load

        Log(Dir)
        Log(FileName)
    End If
End Sub

But the pdf is not showed. Can someon help me ? I try pfview1.frombytes,pfview1.fromfile. etc withouth results. Thanks in advance
 

DonManfred

Expert
Licensed User
copy the file to dirinternal an open it from there

Or use
fromFile (path As String, filename As String)
instead of fromuri.
 
Upvote 0

mike1967

Member
Licensed User
copy the file to dirinternal an open it from there

Or use instead of fromuri.
B4X:
Sub CC2_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        'imgView.Bitmap=LoadBitmapSample(Dir,FileName,800,600)
        File.Copy(Dir, FileName, File.DirInternal, "temp.pdf")
        Dim cfg As Configurator = PDFView1.fromFile(File.DirInternal,"temp.pdf")
        cfg.autoSpacing(True).enableSwipe(True).pageSnap(True).swipeHorizontal(False).addOnErrorListener.addOnLoadCompleteListener.addOnPageChangeListener.addOnPageErrorListener.addOnTapListener.load
        PDFView1.BringToFront
        Log(Dir)
        Log(FileName)
    End If
End Sub

Error:

ContentDir
content://com.android.providers.downloads.documents/document/33
** Activity (main) Resume **
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.BA.raiseEventFromDifferentThread(java.lang.Object, java.lang.Object, int, java.lang.String, boolean, java.lang.Object[])' on a null object reference
    at de.donmanfred.Configuratorwrapper$3.loadComplete(Configuratorwrapper.java:89)
    at com.github.barteksc.pdfviewer.listener.Callbacks.callOnLoadComplete(Callbacks.java:83)
    at com.github.barteksc.pdfviewer.PDFView.loadComplete(PDFView.java:738)
    at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:69)
    at com.github.barteksc.pdfviewer.DecodingAsyncTask.onPostExecute(DecodingAsyncTask.java:25)
    at android.os.AsyncTask.finish(AsyncTask.java:695)
    at android.os.AsyncTask.access$600(AsyncTask.java:180)
    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Can help Me ?
 
Upvote 0

mike1967

Member
Licensed User
Made, no such file or directory error
B4X:
Sub CC2_Result (Success As Boolean, Dir As String, FileName As String)
    If Success Then
        'imgView.Bitmap=LoadBitmapSample(Dir,FileName,800,600)
        Dim cfg As Configurator = PDFView1.fromUri(Dir,FileName)
        cfg.autoSpacing(True).enableSwipe(True).pageSnap(True).swipeHorizontal(False).addOnErrorListener.addOnLoadCompleteListener.addOnPageChangeListener.addOnPageErrorListener.addOnTapListener.load
        PDFView1.BringToFront
        Log(Dir)
        Log(FileName)
    End If
End Sub


Error:

ContentDir
content://com.android.providers.downloads.documents/document/33
** Activity (main) Resume **
onError()
java.io.FileNotFoundException: open failed: ENOENT (No such file or directory)
    at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:313)
    at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:211)
    at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1290)
    at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1148)
    at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1102)
    at com.github.barteksc.pdfviewer.source.UriSource.createDocument(UriSource.java:37)
    at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:49)
    at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:25)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:764)

Same error

Can help Me ? Thanks in advance
 
Upvote 0
Top