Android Question Still struggling with printer.printpdf()

Discussion in 'Android Questions' started by MitchBu, Jun 16, 2019.

Tags:
  1. MitchBu

    MitchBu Active Member Licensed 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 ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Use USB debug mode and check the unfiltered logs. It will allow you to see errors (if there are any) from the printer driver.
     
  3. MitchBu

    MitchBu Active Member Licensed User

    Thank you. How do I get the unfiltered logs ?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Uncheck the 'filter' check box in the Logs tab. Again, make sure to use USB debug mode and not B4A-Bridge. It will allow you to read the logs of other apps.
     
  5. MitchBu

    MitchBu Active Member Licensed User

    So basically, I should use the USB cord, right ?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Johan Hormaza likes this.
  7. MitchBu

    MitchBu Active Member Licensed 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.
     
  8. MitchBu

    MitchBu Active Member Licensed 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 ?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Does it only happen with PrintPdf? Make a test and print with PrintBitmap
     
  10. MitchBu

    MitchBu Active Member Licensed 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.
     
  11. OliverA

    OliverA Expert Licensed 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?
     
  12. MitchBu

    MitchBu Active Member Licensed 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.
     
  13. OliverA

    OliverA Expert Licensed User

    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.
     
  14. MitchBu

    MitchBu Active Member Licensed 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.
     
  15. OliverA

    OliverA Expert Licensed User

    Can you produce a stripped down application that has the same show stopping result/error and post it here?
     
  16. MitchBu

    MitchBu Active Member Licensed User

  17. MitchBu

    MitchBu Active Member Licensed User

    Here is a sample project that does the same thing as my app : it prints once, and the second time, the printer falls in error.

    If I go into Windows, double click on the printer and select "cancel all documents", after removing the error from the Android spooler, it prints again fine.

    http://fontmenu.com/B4A/PrintTest.zip
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    Tip: the timer is not needed. If you want to add a short delay then use Sleep:
    Code:
    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.
     
  19. MitchBu

    MitchBu Active Member Licensed 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.
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    I'm trying to find where does the problem come from. I suggested to use PrintBitmap to verify that the problem is not in the B4A Printer library. My guess is that the problem in the printer adapter apps, though it is just a guess.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice