Android Question Error? in Printing and Pdf creation

wildfandango

Member
Licensed User
Longtime User
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
    1.jpg
    9.2 KB · Views: 365
  • 2.jpg
    2.jpg
    21.5 KB · Views: 302
  • 3.jpg
    3.jpg
    10.6 KB · Views: 338
Last edited:

wildfandango

Member
Licensed User
Longtime User
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:

B4X:
sub printDOC
    Dim prnLIB As Printer

    prnLIB.Initialize("")
    prnLIB.PrintPdf(docNAME,docDIR,docFILE)
End Sub

Modified with the try/catch

B4X:
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:
Upvote 0

wildfandango

Member
Licensed User
Longtime User
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

wildfandango

Member
Licensed User
Longtime User
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
Top