Android Question try to make Resumable subs to create pdf

hanyelmehy

Active Member
Licensed User
Longtime User
i try to make pdf document from images with this code :
B4X:
For i=1 To 100
        Private CurBmb As Bitmap
        CurBmb.Initialize(File.DirInternal,"pages/pages/" & i  & ".jpg")
        MyPDF.StartPage(CurBmb.Width,CurBmb.Height)
        Dim DestRect As Rect
        DestRect.Initialize(0,0,CurBmb.Width,CurBmb.Height)
        MyPDF.Canvas.DrawBitmap(CurBmb, Null, DestRect)
        MyPDF.FinishPage
    Next
i want to make this process Asynchronous
but when use :
B4X:
For i=1 To 100
        Private CurBmb As Bitmap
        CurBmb.Initialize(File.DirInternal,"pages/pages/" & i  & ".jpg")
        MyPDF.StartPage(CurBmb.Width,CurBmb.Height)
        Dim DestRect As Rect
        DestRect.Initialize(0,0,CurBmb.Width,CurBmb.Height)
        MyPDF.Canvas.DrawBitmap(CurBmb, Null, DestRect)
        MyPDF.FinishPage
Sleep(0)
i get this error :
B4X:
java.lang.IllegalStateException: document is closed!
    at android.graphics.pdf.PdfDocument.throwIfClosed(PdfDocument.java:225)
    at android.graphics.pdf.PdfDocument.startPage(PdfDocument.java:116)
    at anywheresoftware.b4a.objects.PdfDocumentWrapper.StartPage(PdfDocumentWrapper.java:68)
    at com.appsmakers.flipbook.printpdf._addpage(printpdf.java:288)
    at com.appsmakers.flipbook.printpdf$ResumableSub_CreatPDF.resume(printpdf.java:179)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    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 anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.keywords.Common$13.run(Common.java:1690)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5551)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
** Activity (showbook) Pause, UserClosed = false **
Note :first code work fine
 
Top