B4A Class Bluetooth ESC/POS Printer Class

emexes

Expert
Licensed User
The problem might not be as obvious to others as it is to you.

I should have added that all of that looks easy to fix.

The hardest is probably handling reporting for shifts / trading periods that straddle midnight, eg a restaurant open from 5pm until 2am.
 

MR Kai

Member
Licensed User
Longtime User
 
Last edited:

MR Kai

Member
Licensed User
Longtime User
I should have added that all of that looks easy to fix.

The hardest is probably handling reporting for shifts / trading periods that straddle midnight, eg a restaurant open from 5pm until 2am.
all of data in this report its garbage data and for test
my question about when print attached first image second one what i get from printer
 

emexes

Expert
Licensed User
all of data in this report its garbage data and for test

I figured it was just sample data, but the calculation and formatting issues remain. Happily, all look minor and easy.


my question about when print attached first image second one what i get from printer

It is nifty that you have that intermediate image to help diagnose what's happening.

I do not have one of those printers, but my first general thoughts are:

- has it previously worked when printing other reports by the same method? (ie via image)
- do older/other apps that used to print ok, still print ok?
- is the problem repeatable, eg after turning the printer off and on and restarting your app?
- what happens for shorter reports? eg receipts
 

MR Kai

Member
Licensed User
Longtime User
thank you for your replay
when print receipt its good and contain image with perfect resolution
this report drawing on clv and panel converted to pdf and from pdf to image and print image


PanelToPdf:
public Sub PanelToPdf(Panel As B4XView, FileName As String)
    Try
        Dim pdf As PdfDocument
        pdf.Initialize
        pdf.StartPage(Panel.Width, Panel.Height)
'        pdf.StartPage(595, 842) 'A4 size
        Dim bmp As B4XBitmap = Panel.Snapshot
        Dim dest As Rect
        dest.Initialize(10, 10, 0, 0)
        dest.Width = bmp.Width / bmp.Scale
        dest.Height = bmp.Height / bmp.Scale      
        pdf.Canvas.DrawBitmap(bmp, Null, dest)
        pdf.FinishPage
        Dim out As OutputStream = File.OpenOutput(provider.SharedFolder, FileName, True)
        pdf.WriteToStream(out)
        out.Close
        pdf.Close
    Catch
        Log(LastException)
    End Try
End Sub




and then call this method


print:
Sub SendToPrinter(Fnamed As String)

    Try  
           
        If CashierPrinter.IsConnected=False Then          
            CashierPrinter.Connect("192.168.1.201",9100,0)
            Sleep(2000)
        End If
                   
        CashierPrinter.Reset              
        Dim IMAGEPanel As Bitmap
        IMAGEPanel.InitializeResize(Mod2.provider.SharedFolder, Fnamed,576, 512, True) 'ignore              
        Dim myimage As AnImage = CashierPrinter.ImageToBWIMage(IMAGEPanel)
        myimage = CashierPrinter.ThresholdImage(myimage, 128)
        myimage= CashierPrinter.PackImage(myimage)
        CashierPrinter.WriteString(CRLF)
        CashierPrinter.PrintImage(myimage)
        CashierPrinter.Feed
        CashierPrinter.FullCut
       
    Catch
        Log(LastException)
    End Try
End Sub
 
Last edited:

emexes

Expert
Licensed User
when print receipt its good and contain image with perfect resolution
this report drawing on clv and panel converted to pdf and from pdf to image and print image

clv → panel capture → pdf → image → print not much opportunity for anything to go awry there

Printing a receipt and printing a report, are they the same process?

What if you trim the length (height?) of the report?

Either by cropping* the image, or by deleting some rows from the top and bottom of the clv.

Maybe there is some limit to the height of images that can be printed. Or to the size of the image, *eg* no more than 65535 or 524287 pixels.

That's another idea - try printing simple boxes or grids, say 3 inches wide, first 1 inch high, then 2 inches, then 3 inches, etc... then see if it falls over when it gets to as long as your report.


* or even resizing, and ignore the squashed look for the time being, we're just trying to make the image and printout match.
 

emexes

Expert
Licensed User
Maybe there is some limit to the height of images that can be printed. Or to the size of the image, *eg* no more than 65535 or 524287 pixels.

I am just a nightshift member of this forum, so yes: you and me here are a classic case of the blind leading the blind.

If we can't nut it out beforehand then, with luck, in ~six hours time @agraham will point out the obvious that we've missed.
 
Last edited:

emexes

Expert
Licensed User
when print receipt its good and contain image with perfect resolution

Another thought is: try printing a receipt that is as long as your report

If big receipt prints ok, then compare the receipt-printing and report-printing process/code side-by-side.

If big receipt doesn't print ok, then we are probably looking for a size - or maybe memory - limit.
 

MR Kai

Member
Licensed User
Longtime User
receipt is ok

but this receipt created line by line
 

Attachments

  • yyyy.jpg
    64.7 KB · Views: 151

aeric

Expert
Licensed User
Longtime User
hi
i have problem with print this report
attached image explain what mean
Seems like a hardware issue. Is it same on another printer that nothing is printed?
Edit: ah, now I get it. You are trying to print this as image and the dimension is very high.
Since all the output are text, why need to convert to image? Alright, maybe you want to store a snapshot copy. There may be memory or buffer limitation in printing images. My idea is to break the whole image into multiple shorter ones and print 1 by 1.
 
Last edited:

aeric

Expert
Licensed User
Longtime User
You should not ask why if you know the forum rules or guideline.

You should post your question in a new thread instead of old thread.
It is benefit for others and you can easily find back your threads. Don't make the thread long or clutter and difficult to read. This is a library thread. This will make future readers having problem to find answer.
 

vecino

Well-Known Member
Licensed User
Longtime User
Hello, PrintImage or PrintImage2?
What is the difference between PrintImage and PrintImage2?
When is it convenient to use one or the other?
Thank you.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…