Hi guys, I'm creating an app to create a PDF file, the pdf file is created with PDFwriter, and have many images inside.
I use the garbage Collector for images with the reflector lib.
Tested in 3 Devices, and in the Device I really need run it, not work!!!
Finally I run a Test on my phone and work fine with 10 or more pages.
In Tablet test 1: (The real device client want to use this App)
Total Pages Generate: 10
Total Images used: 28
Tablet: Lenovo Ideatab A3000 (IdeaTabA3000-H)
CPU: MTk 8389/8125 Quad Core de 1,2 GHz
RAM: 1GB
Android version: 4.2
Crash!
In Phone Test 2:
Total Pages Generate: 14
Total Images used: 52
Phone: Amazon FirePhone
CPU: Snapdragon 800 2.2GHz Quad-core
RAM: 2GB
Android version: FireOS 4.6.1 (Kitkat 4.4)
Work Very Faster
In Tablet Test 3
Total Pages Generate: 14
Total Images used: 52
Tablet: Lenovo Yoga 8" B6000-F
CPU: MediaTek MT8125 Quad Core de 1,2 GHz
RAM: 1GB
Android version: 4.4.2
Work Fine
I add the code from Infoxmatrix to see the max memory, FreeMemory and TotalMemory from here
And Here this part on the crash:
PDF Convert
max Memory 134217728
FreeMemory 7611936
totalMemory 37351424
Memoria Disponible :102029.53125
PDF Writer
max Memory 134217728
FreeMemory 28835040
totalMemory 114974720
Memoria Disponible :46951.21875
I have in the manifest:
SetApplicationAttribute(android:largeHeap,"true")
To Insert Images I use this:
To Create PDF Page I use someting like this:
How can I solve to create more pages in the PDF in devices with low RAM?
How can I create a Page then excute garbage Collector for everything have inside this page?
I see this code in the forum.
Installing file.
PackageAdded: package:createpdf.forms
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (generar_borrador) Create, isFirst = true **
PDF Convert
PDF Writer
generar_borrador_crear_pdf (B4A line: 111)
PDFContent = PDFWriter1.outputToScreen
java.lang.OutOfMemoryError
at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)
at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)
at java.lang.StringBuilder.append(StringBuilder.java:216)
at com.rootsoft.pdfwriter.PDFDocument.toPDFString(PDFDocument.java:57)
at com.rootsoft.pdfwriter.PDFWriter.asString(PDFWriter.java:113)
at com.rootsoft.pdfwriter.myPDFWriter.outputToScreen(myPDFWriter.java:95)
at createpdf.forms.generar_borrador._crear_pdf(generar_borrador.java:742)
at createpdf.forms.generar_borrador._activity_create(generar_borrador.java:495)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at createpdf.forms.generar_borrador.afterFirstLayout(generar_borrador.java:100)
at createpdf.forms.generar_borrador.access$100(generar_borrador.java:17)
at createpdf.forms.generar_borrador$WaitForLayout.run(generar_borrador.java:78)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
I use the garbage Collector for images with the reflector lib.
Tested in 3 Devices, and in the Device I really need run it, not work!!!
Finally I run a Test on my phone and work fine with 10 or more pages.
In Tablet test 1: (The real device client want to use this App)
Total Pages Generate: 10
Total Images used: 28
Tablet: Lenovo Ideatab A3000 (IdeaTabA3000-H)
CPU: MTk 8389/8125 Quad Core de 1,2 GHz
RAM: 1GB
Android version: 4.2
Crash!
In Phone Test 2:
Total Pages Generate: 14
Total Images used: 52
Phone: Amazon FirePhone
CPU: Snapdragon 800 2.2GHz Quad-core
RAM: 2GB
Android version: FireOS 4.6.1 (Kitkat 4.4)
Work Very Faster
In Tablet Test 3
Total Pages Generate: 14
Total Images used: 52
Tablet: Lenovo Yoga 8" B6000-F
CPU: MediaTek MT8125 Quad Core de 1,2 GHz
RAM: 1GB
Android version: 4.4.2
Work Fine
I add the code from Infoxmatrix to see the max memory, FreeMemory and TotalMemory from here
And Here this part on the crash:
PDF Convert
max Memory 134217728
FreeMemory 7611936
totalMemory 37351424
Memoria Disponible :102029.53125
PDF Writer
max Memory 134217728
FreeMemory 28835040
totalMemory 114974720
Memoria Disponible :46951.21875
I have in the manifest:
SetApplicationAttribute(android:largeHeap,"true")
To Insert Images I use this:
B4X:
Sub insertar_imagen2 (nombre_imagen As String, izquierda As Double, arriba As Double)
img_Logo=LoadBitmapSample("", nombre_imagen,310, 120)
img_Logo=CreateScaledBitmap(img_Logo, 239, 180,True)
PDFWriter1.addImage(mm2Points(izquierda),mm2Points(arriba), img_Logo)
Dim Obj1,obj2 As Reflector
Obj1.Target = img_Logo
Obj1.RunMethod("recycle")
End Sub
To Create PDF Page I use someting like this:
B4X:
Sub Hoja1
page_counter=page_counter+1
PDFWriter1.newPage()
PDFWriter1.setFont(fonts.SUBTYPE, fonts.TIMES_ROMAN)
PDFWriter1.setFont2(fonts.SUBTYPE, fonts.TIMES_ROMAN, fonts.WIN_ANSI_ENCODING)
SOME CODE LINES, RECTANGLES, TEXT ETC
insertar_imagen2("Image1", left, horizontal_position)
end sub
How can I solve to create more pages in the PDF in devices with low RAM?
How can I create a Page then excute garbage Collector for everything have inside this page?
I see this code in the forum.
B4X:
Dim r As Reflector
r.RunStaticMethod("java.lang.System", "gc", Null, Null)
Installing file.
PackageAdded: package:createpdf.forms
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (generar_borrador) Create, isFirst = true **
PDF Convert
PDF Writer
generar_borrador_crear_pdf (B4A line: 111)
PDFContent = PDFWriter1.outputToScreen
java.lang.OutOfMemoryError
at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)
at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)
at java.lang.StringBuilder.append(StringBuilder.java:216)
at com.rootsoft.pdfwriter.PDFDocument.toPDFString(PDFDocument.java:57)
at com.rootsoft.pdfwriter.PDFWriter.asString(PDFWriter.java:113)
at com.rootsoft.pdfwriter.myPDFWriter.outputToScreen(myPDFWriter.java:95)
at createpdf.forms.generar_borrador._crear_pdf(generar_borrador.java:742)
at createpdf.forms.generar_borrador._activity_create(generar_borrador.java:495)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at createpdf.forms.generar_borrador.afterFirstLayout(generar_borrador.java:100)
at createpdf.forms.generar_borrador.access$100(generar_borrador.java:17)
at createpdf.forms.generar_borrador$WaitForLayout.run(generar_borrador.java:78)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Last edited: