Android Question HTML to Bitmap to PDF Question

GEoffT

Member
Licensed User
Longtime User
I have a document stored in an HTML file which I wish to add to a PDF.

I am reading the HTML into a string.
Loading it to a webview
Using Webview.CAptureBitmap
then using pdf.canvas.drawbitmap

But I get the error "java.lang.IllegalArgumentException: width and height must be > 0"

on the webview1.capturebitmap line

B4X:
    Dim     pdf As PdfDocument
    Dim webview1 As WebView
    Dim Bitmap1 As Bitmap
    Dim htmlFileString As String
    Dim Out As OutputStream

    Dim DestRect As Rect
    webview1.Initialize("")
    htmlFileString = File.ReadString(File.DirDefaultExternal, GlobFileName)
    pdf.Initialize
    pdf.StartPage(595, 842) 'A4 size

    webview1.LoadHtml(htmlFileString)
    webview1.Visible=True
    Out = File.OpenOutput(File.DirDefaultExternal, "Scorecard.png", False)
    webview1.CaptureBitmap.WriteToStream(Out, 100, "PNG")
    Out.Close
    Bitmap1.Initialize(File.DirDefaultExternal, "Scorecard.png")
    DestRect.Initialize(5,5,580,450)
    pdf.Canvas.DrawBitmap(Bitmap1,Null,DestRect)

Thanks in advance Geoff
 

GEoffT

Member
Licensed User
Longtime User
Erel, Here is the full error message and line 1513 is this one

B4X:
    webview1.CaptureBitmap.WriteToStream(Out, 100, "PNG")

Error occurred on line: 1513 (ScoringX10)
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:933)
at android.graphics.Bitmap.createBitmap(Bitmap.java:912)
at android.graphics.Bitmap.createBitmap(Bitmap.java:879)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeMutable(CanvasWrapper.java:654)
at anywheresoftware.b4a.objects.WebViewWrapper.CaptureBitmap(WebViewWrapper.java:131)
at net.tittensor.ToxToolbox.scoringx10._btnemailrecordsofficer_click(scoringx10.java:3292)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:360)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:5197)
at android.view.View$PerformClick.run(View.java:20926)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
** Activity (scoringx10) Pause, UserClosed = true **
** Service (starter) Destroy (ignored)**
 
Upvote 0

GEoffT

Member
Licensed User
Longtime User
Thanks for that Erel. The behaviour has changed....The error message has disappeared, but the app now sits forever on the wait statement.

regards Geoff
 
Upvote 0

GEoffT

Member
Licensed User
Longtime User
THis small app does the same....it never gets to the "Log ("got here") statement

Thanks in adavnce. Geoff

P.s. I used the same HTML file, but moved it to the files folder since it is normally generated in code.
 

Attachments

  • pdfHTML.zip
    9.2 KB · Views: 217
Last edited:
Upvote 0

GEoffT

Member
Licensed User
Longtime User
Thanks Erel...Should have know that!!!

Changed it and now back to the original error (in the sample program) i.e


Error occurred on line: 62 (Main)
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:933)
etc


line 62 is the "webview1.CaptureBitmap.WriteToStream..."
 
Upvote 0

GEoffT

Member
Licensed User
Longtime User
I was wrong I still have a problem. with Error occurred on line: 62 (Main)
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:933

 

Attachments

  • pdftoHTML.zip
    9.8 KB · Views: 221
Upvote 0
Top