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 ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
I could not see anything in the logs. I also verified all PDF files are valid.

But I have empirical evidence.

I suspected the printer's buffer was full, which explained why the printer went into error.

If I go into the printer on my PC and cancel all documents, I can then print from the Android app just fine. The second time around, I get an error.

If I go again on the PC and cancel all documents, I can then print just fine from the Android app.

It seems canceling all documents from the PC does flush the jobs hanging around, allowing the Android app to print again.

I verified that with the Brother HL-L3210CW color printer, and the HP Laserjet MFP M227fdw black and white printer I have at my disposal.

Now, would it be possible to instruct the printer to forget about the current printer job after printing ? I tried to google, without any real solid result.

It is critical that printing be reliable, so I can release the app.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
Pursuing experiments...

It appears there is definitely something missing in the current printing class...

I can print as many times as I want from Chrome/Share/Print without any error.

Why is it with the printing class I can only print once, and then the printer falls into error ?
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
I cannot print bitmap at more than 100 dpi full page (8.5 x 11) on the Brother HL-L3210CW, and 150 dpi on the HP Laserjet MFP M227fdw.

I see exactly the same, meaning after printing once, the printer systematically falls into error, until I go under Windows and cancel all documents. After cancelling all documents under Windows, I can again print bitmap once.

I did that several times to make sure, it is reproducible.

It looks as if the printers hold the B4A printing in memory, which prevents subsequent printing.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
How are you seeing the print jobs in Windows? I've just printed to my wireless printer via the phone and windows does not show the print job. Both windows and phone are wireless (printer is neither hooked to windows nor shared via windows). Are you printing directly to the printer with your phone or via a windows share?
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
I am printing wirelessly directly through the printing class. In Windows, no job is showing when I double click on the printer in the Devices and printers control panel.

What seems to happen is that the B4A printing job somehow hangs in the printer memory, and canceling all documents in Windows seems to wipe that out, enabling again the printer to receive a new job from B4A.

I have done the manipulation several times.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
and canceling all documents in Windows seems to wipe that out
I just printed a multi-page PDF file and from the phone and tried to cancel it via Windows w/o luck. I repetitively cancelled, but the printer merrily printed all pages (25). What version of Windows (mine: Win10 Pro 1903)? I know the steps seem to work for you, just seems strange that Windows sends a cancel print job to the printer w/o having any print jobs in it's own queue, or that one Windows machine is willy-nilly allowed to cancel someone else's print job on a printer that is not connected/shared from one's own computer.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
You don't understand. I don't believe Windows is able to cancel jobs coming from a phone. It would not make any sense.

What I see here is that when I print from any standard Android application, I can print several times over one page (not 25 pages) without error.

If I try to print one page several times over with the printing class, the second time over, and subsequent, the printer gets into error.

At that point, if I cancel all documents in the printer spooler in Windows, it seems to reset the printing system, and I can again print once one page from B4A with the printing class. PDF or bitmap.

I can only suppose Windows is sending some command that flushes the printer internal memory.

Once again, my concern is that I cannot release an app that prints only once. Quite rightly, buyers will object that Chrome, for instance, prints quite reliably.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Can you produce a stripped down application that has the same show stopping result/error and post it here?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip: the timer is not needed. If you want to add a short delay then use Sleep:
B4X:
Sub Button1_Click
   createPDF
   Sleep(200) 'same result as using a timer but simpler.
   printer.PrintPdf("Print Test", File.DirInternal, "1.pdf")
End Sub

I've asked about PrintBitmap because it is based on a simpler method: https://developer.android.com/refer...rintBitmap(java.lang.String, android.net.Uri)
PrinterHelper is part of the SDK and you are just expected to create a PrintHelper object and call printBitmap. This is different than the other printing methods which are more complicated.
If PrintBitmap fails then it is probably an OS or driver issue.
You should make more tests with PrintBitmap.
Try to initialize the Printer object each time before you print and see whether it makes any difference.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
I appreciate the suggestion to use sleep(200) instead of the timer. It is indeed much simpler.

All experiments I conducted with bitmap show I cannot reliably print at more than 200 dpi full A4, because the printers get in error past that. I do need minimum 600 dpi for the MICR line at the bottom of checks to conform to standard.

PDF is the only way I can get full printer resolution.

I will try to initialize the printer before printing. If it solves the issue, that will be great.

It seems the issue is not quite unknown, though:
https://duckduckgo.com/?q=which+codes+send+the+printer+to+empty+jobs+in+memory&ia=web

I worked on laser printers drivers back in the eighties, and remember seeing ESC sequence commands to flush the printer memory of remaining jobs. I will continue digging to find the exact sequence to send the printer.

Thank you Erel.
 
Upvote 0
Top