Android Question Printing PDF File

Dennis Glowack

Member
Licensed User
I hope I am doing this correctly. I am new to B4A and might be in the wrong area; but here it goes. I've been looking at the creation of PDF's and printing the same. I've been able to create and view a PDF file on my device. Next, I wanted to print it. It seemed straight forward, but I get this error every time I try to initialize the printer (My Main Module code appears afterward):

I've searched and searched for an answer and am stuck. Version 1.11 of the Printing Library is installed and Android SDK seems to be current.

Logger connected to: asus P01Z
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/print/PrintHelper;
at anywheresoftware.b4a.objects.PdfDocumentWrapper$Printer.Initialize(PdfDocumentWrapper.java:119)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
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:180)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:4757)
at android.view.View$PerformClick.run(View.java:19766)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5255)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.print.PrintHelper" on path: DexPathList[[zip file "/data/app/b4a.example-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 22 more
Suppressed: java.lang.ClassNotFoundException: android.support.v4.print.PrintHelper
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 23 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

MAIN MODULE CODE:

#Region Project Attributes
#ApplicationLabel: PrintTest
#VersionCode: 3
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub

Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.

Dim btnPrint As Button
Dim DBFilepath As String
Dim rp As RuntimePermissions

End Sub

Sub Activity_Create(FirstTime As Boolean)

'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
CreatePDF
End Sub


Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub CreatePDF

Dim pdf As PdfDocument
Dim output As OutputStream

'See if I can write to SD Card
DBFilepath = rp.GetSafeDirDefaultExternal("")

pdf.Initialize

pdf.StartPage(595, 842) 'A4 size
pdf.Canvas.DrawText("Tipzza Summary Report", 100, 50, Typeface.DEFAULT_BOLD, 30 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.Canvas.DrawText("Period From: 2019-12-25 Thru: 2019-25", 100, 100, Typeface.DEFAULT, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.Canvas.DrawText("Number of Deliveries: 7", 100, 150, Typeface.DEFAULT, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.Canvas.DrawText("Total Cash Tips: $45.00", 100, 200, Typeface.DEFAULT, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.Canvas.DrawText(" Total Credit Tips: $23.99", 100, 250, Typeface.DEFAULT, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.Canvas.DrawText("TOTAL TIPS: $500.00", 100, 300, Typeface.DEFAULT_BOLD, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.Canvas.DrawText(" Average Tips: $22.00", 100, 350, Typeface.DEFAULT, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.Canvas.DrawText("Number of Tips: 67", 100, 400, Typeface.DEFAULT, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.Canvas.DrawText("Number of Stiffs: 5", 100, 450, Typeface.DEFAULT, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.Canvas.DrawText(" Tip Percentage: 89%", 100, 500, Typeface.DEFAULT, 20 / GetDeviceLayoutValues.Scale , Colors.Black, "LEFT")
pdf.FinishPage
output = File.OpenOutput(DBFilepath, "tipzza.pdf", False)
pdf.WriteToStream(output)
output.Close
pdf.Close

End Sub

Sub btnPrint_click
Dim printer1 As Printer

printer1.Initialize("") 'ERROR HERE

printer1.PrintPdf("Tipzza", DBFilepath, "tipzza.pdf")
End Sub
 
Top