wildfandango Member Licensed User Longtime User Apr 20, 2018 #1 https://www.b4x.com/android/forum/threads/printing-and-pdf-creation.76712/ First of all I want to thank you Erel I'm using it in a real project and it has saved me many hours of development... Unfortunately in certain circumstances it sends out an error message that I think could be due to a bug in the library. I describe the circumstances to you EXACTLY. I have a BROTHER PJ-763 printer I install the BROTHER control software https://play.google.com/store/apps/details?id=com.brother.printservice&hl=en The printer switches to the default printer, although I have another PDF printer When I print with the library and the default printer is on, everything is fine. But if I print with the printer turned off (picture 1), AND then try to select the PDF printer (picture 2), my application closes with the following error message (picture 3) java.lang.RuntimeException: Cannot print a malformed PDF file at android.print.PrintManager$PrintDocumentAdapterDelegate$MyHandler.handleMessage(PrintManager.java:1095) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6809) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) B4A 8 OnePlus 5t Android 8.0.0 Attachments 1.jpg 9.2 KB · Views: 752 2.jpg 21.5 KB · Views: 656 3.jpg 10.6 KB · Views: 704 Last edited: Apr 21, 2018
https://www.b4x.com/android/forum/threads/printing-and-pdf-creation.76712/ First of all I want to thank you Erel I'm using it in a real project and it has saved me many hours of development... Unfortunately in certain circumstances it sends out an error message that I think could be due to a bug in the library. I describe the circumstances to you EXACTLY. I have a BROTHER PJ-763 printer I install the BROTHER control software https://play.google.com/store/apps/details?id=com.brother.printservice&hl=en The printer switches to the default printer, although I have another PDF printer When I print with the library and the default printer is on, everything is fine. But if I print with the printer turned off (picture 1), AND then try to select the PDF printer (picture 2), my application closes with the following error message (picture 3) java.lang.RuntimeException: Cannot print a malformed PDF file at android.print.PrintManager$PrintDocumentAdapterDelegate$MyHandler.handleMessage(PrintManager.java:1095) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6809) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) B4A 8 OnePlus 5t Android 8.0.0
Peter Simpson Expert Licensed User Longtime User Apr 20, 2018 #2 Use try catch to catch the exception, then reinitialize the printer and select the PDF printer. You should be able to then print to the PDF printer without causing the app to throw a wobbly... Upvote 0
Use try catch to catch the exception, then reinitialize the printer and select the PDF printer. You should be able to then print to the PDF printer without causing the app to throw a wobbly...
wildfandango Member Licensed User Longtime User Apr 21, 2018 #3 Hello, I have modified my code (which is very simple) by adding a try/catch and the error still occurs. My original code is very simple: Code: Copy sub printDOC Dim prnLIB As Printer prnLIB.Initialize("") prnLIB.PrintPdf(docNAME,docDIR,docFILE) End Sub Modified with the try/catch Code: Copy sub printDOC Dim prnLIB As Printer prnLIB.Initialize("") Try prnLIB.PrintPdf(docNAME,docDIR,docFILE) Catch ToastMessageShow("ERROR",True) End Try End Sub I still think it must be a mistake of the lib. Last edited: Apr 21, 2018 Upvote 0
Hello, I have modified my code (which is very simple) by adding a try/catch and the error still occurs. My original code is very simple: Code: Copy sub printDOC Dim prnLIB As Printer prnLIB.Initialize("") prnLIB.PrintPdf(docNAME,docDIR,docFILE) End Sub Modified with the try/catch Code: Copy sub printDOC Dim prnLIB As Printer prnLIB.Initialize("") Try prnLIB.PrintPdf(docNAME,docDIR,docFILE) Catch ToastMessageShow("ERROR",True) End Try End Sub I still think it must be a mistake of the lib.
Erel B4X founder Staff member Licensed User Longtime User Apr 21, 2018 #4 Moved to the questions forum. Upvote 0
KMatle Expert Licensed User Longtime User Apr 21, 2018 #5 Are you using runtime permissions? (Sdk >= 23) Maybe the lib can't access the file. Upvote 0
wildfandango Member Licensed User Longtime User Apr 21, 2018 #6 If the printer is connected, it is possible to run and print the document without any problems, the error will only occur if the default printer is switched off. Do you think it could be a permit problem? You would set them at the Manifest level? Could you give me an example? Upvote 0
If the printer is connected, it is possible to run and print the document without any problems, the error will only occur if the default printer is switched off. Do you think it could be a permit problem? You would set them at the Manifest level? Could you give me an example?
KMatle Expert Licensed User Longtime User Apr 21, 2018 #7 Search for runtime permissions. There is a example from Erel: https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/ I have figured several "problems" due to missing permissions. Just an idea... Upvote 0
Search for runtime permissions. There is a example from Erel: https://www.b4x.com/android/forum/threads/runtime-permissions-android-6-0-permissions.67689/ I have figured several "problems" due to missing permissions. Just an idea...
wildfandango Member Licensed User Longtime User Apr 23, 2018 #8 I'll check it out because it seems that the only possible explanation is the one you're talking about, an issue of permissions. Thank you Upvote 0
I'll check it out because it seems that the only possible explanation is the one you're talking about, an issue of permissions. Thank you