Android Question BBCodeView & TextEngine add snapshot image to PDFWriter

mike1967

Member
Licensed User
Hello I Have this code :
Code:
Form.TextEngine=TextEngine

        Form.Text= _

        $"[img FileName=header.png width=380/]"$ & $"[TextSize=10]    Il Sottoscritto  "$ & currentuser & $" in servizio presso codesto Istituto, richiede "$ & str.Left(data.Get("gg"),str.At(data.Get("gg"),".")) & $" GG di "$ & data.get("tipo_gg") & Ascol & $" Dal: "$ & DateTime.Date(data.Get("data_start")) & $" Al: "$ & DateTime.Date(data.Get("data_end")) & mot & $"[Vertical=150][img dir="${File.DirInternal}" FileName="signature.png" width=150/][/Vertical]"$

        Dim imgmodulo As Bitmap

        Dim PDFWriter1 As PDFWriter

        Dim PaperSize As PDFPaperSizes

        PDFWriter1.Initialize("PDFWriter1",PaperSize.A4_WIDTH, PaperSize.A4_HEIGHT)

        PDFWriter1.addImage(10,10,imgmodulo)

        PDFWriter1.outputToFile(File.Dirinternal,"richiesta.pdf","","ISO-8859-1")

It should do make a screen shot of BBCodeview and then add it as image to pdfWriter in order to obtain a pdf .
But when i run it return me:

Error:
Error occurred on line: 163 (B4XMainPage)
java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:102)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetBitmap(B4XViewWrapper.java:381)
    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 anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1770)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:236)
    at android.app.ActivityThread.main(ActivityThread.java:7864)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Line 163:
imgmodulo.Initialize3(Form.ForegroundImageView.GetBitmap)

Where i wrong ?
Thanks in advance
 

mike1967

Member
Licensed User
Hello I Have this code :
Code:
Form.TextEngine=TextEngine

        Form.Text= _

        $"[img FileName=header.png width=380/]"$ & $"[TextSize=10]    Il Sottoscritto  "$ & currentuser & $" in servizio presso codesto Istituto, richiede "$ & str.Left(data.Get("gg"),str.At(data.Get("gg"),".")) & $" GG di "$ & data.get("tipo_gg") & Ascol & $" Dal: "$ & DateTime.Date(data.Get("data_start")) & $" Al: "$ & DateTime.Date(data.Get("data_end")) & mot & $"[Vertical=150][img dir="${File.DirInternal}" FileName="signature.png" width=150/][/Vertical]"$

        Dim imgmodulo As Bitmap

        Dim PDFWriter1 As PDFWriter

        Dim PaperSize As PDFPaperSizes

        PDFWriter1.Initialize("PDFWriter1",PaperSize.A4_WIDTH, PaperSize.A4_HEIGHT)

        PDFWriter1.addImage(10,10,imgmodulo)

        PDFWriter1.outputToFile(File.Dirinternal,"richiesta.pdf","","ISO-8859-1")

It should do make a screen shot of BBCodeview and then add it as image to pdfWriter in order to obtain a pdf .
But when i run it return me:

Error:
Error occurred on line: 163 (B4XMainPage)
java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:102)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetBitmap(B4XViewWrapper.java:381)
    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 anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1770)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:236)
    at android.app.ActivityThread.main(ActivityThread.java:7864)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Line 163:
imgmodulo.Initialize3(Form.ForegroundImageView.GetBitmap)

Where i wrong ?
Thanks in advance
Solved with :
Code:
TextEngine.Initialize(Root)
        Form.TextEngine=TextEngine
        Form.Text= _
        $"[img FileName=header.png width=380/]"$ & $"[TextSize=10]    Il Sottoscritto  "$ & currentuser & $" in servizio presso codesto Istituto, richiede "$ & str.Left(data.Get("gg"),str.At(data.Get("gg"),".")) & $" GG di "$ & data.get("tipo_gg") & Ascol & $" Dal: "$ & DateTime.Date(data.Get("data_start")) & $" Al: "$ & DateTime.Date(data.Get("data_end")) & mot & $"[Vertical=150][img dir="${File.DirInternal}" FileName="signature.png" width=150/][/Vertical]"$
        Dim imgmodulo As Bitmap
        imgmodulo.Initialize3(Form.mBase.Snapshot)
        Dim PDFWriter1 As PDFWriter
        Dim PaperSize As PDFPaperSizes
        PDFWriter1.Initialize("PDFWriter1",PaperSize.A4_WIDTH, PaperSize.A4_HEIGHT)
        PDFWriter1.addImage(10,10,imgmodulo)
        PDFWriter1.outputToFile(File.Dirinternal,"richiesta.pdf","","ISO-8859-1")
        Dim smtp As SMTP
        smtp.Initialize("smtp.gmail.com",587,"email","password","smtp")
        smtp.StartTLSMode=True
        smtp.To.Add("email")
        smtp.Subject="Richiesta da " & currentuser
        smtp.Body="In allegato la Richiesta"
        smtp.AddAttachment(File.DirInternal,"richiesta.pdf")
        smtp.Send

Now the pdf is corrupted . Can some one help me ?
 
Upvote 0
Top