Android Question Still struggling with printer.printpdf()

MitchBu

Well-Known Member
Licensed User
Longtime User
My check app is coming along fine, thanks to B4A, but I am facing a show stopper with both laser printers HP and Brother.

First time around, I get a preview, and the printer prints nicely.

Second time I try to print, I get a preview, then printer error. No detail available. I cannot release the app with such an issue.

I suspect the first printing data is hanging around somehow, instead of being flushed. So there is no more room for the subsequent printing data.

Is there any way precisely to flush the printer queue ?
 

MitchBu

Well-Known Member
Licensed User
Longtime User
OK. Initializing before printing does not help.

I still need to cancel all documents in Windows to be able to print once again.

If only there was a way to analyze what sequence Windows sends the printer when cancelling all documents, we would have the solution.

I agree that the adapters are probably at fault for not cleaning up after printing.

It happens the same for HP and Brother.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If only there was a way to analyze what sequence Windows sends the printer when cancelling all documents, we would have the solution.
Not really. Your app is not communicating with the printer directly. It is the printer adapter app that does it. So you can't send commands directly to the printer.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
Then there must be some undocumented command to the adapter we do not know about, which makes Chrome able to print flawlessly to the same adapter.

I suppose the printing library applies what is described here :
https://developer.android.com/training/printing/custom-docs.html

It does not seem there any provision to reset the printer.
 
Last edited:
Upvote 0

OliverA

Expert
Licensed User
Longtime User
1) Link: https://h30434.www3.hp.com/t5/HP-Co...om-android/m-p/6862543/highlight/true#M120447
2)
Turn off any other print service plugins, if necessary.
Same thread
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
Thank you OliverA. I have already gone through all these motions, adding and removing the printer, monitoring the spooler.

I cannot, in all reason, require buyers of my app to go through such a song and dance. Especially since, even with that manipulation, the printer keep erring the second time around.

For the moment, the only reliable way to print is to do it through Cloud Print.

I am considering releasing the app as a cloud print only solution. I have verified that the printing class works flawlessly to print PDF with cloud ready printers, as well as not cloud ready printers.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
I post this here, because after much trial and error, I finally started to work with other adapters in the Play Store.

While both the Brother and HP adapters seem incapable of printing more than once on a local wireless printer, the app PrinterShare does that very nicely, with apparently all printers.

It seems also to optimize the code, and prints much, much faster.

I am going to test further, but at least, I now am able to offer my app with a working solution
 
Last edited:
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I am not completely clear how sending jobs to the printer from an Android device shows up on your windows print system (seems like it shouldn't).

Normally I make a PDF (as you did) and then call the default PDF Viewer and let it print the PDF (never had a problem this way)
B4X:
                       File.Copy(File.DirRootExternal, mPrintingFileName, Starter.gSharedLocation, FileName)
                   
                       Dim ViewIntent As Intent
                       
                       ViewIntent.Initialize(ViewIntent.ACTION_VIEW, CreateFileProviderUri(Starter.gSharedLocation, FileName))
                       ViewIntent.Flags    = 1
                       ViewIntent.SetType("application/pdf")

                       Try
                           StartActivity(ViewIntent)
                       Catch
                           cGenFuncs.MessageBoxAlert("There is NO PDF Viewer" &CRLF &CRLF &TAB &"Go to GooglePlay and download a PDF Viewer", "No PDF Viewer")
                       End Try

But if you don't want to do that you could try sending an Esc E to the printer as your first command (Escape E is the sequence to reset the printer - should work on all printers) and see if that clears the errors and let's you print a second time

BobVal
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User

Precisely, as explained by Erel, on Android, you don't have access to the printer, only to the adapter. So there is no way to send Esc-E.

What I was doing was simply to use the PC print queue as a way to send that reset command. Not to manage the Android print queue. Sorry if that was not clear enough :/
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…