Receipt Printer Raw Data

@Aurelian_N
I used your code right now to print on Windows 10 to a HP 1320n Printer and worked fine

I’m using Xojo 2023R2

On Windows, it just works. No need to use raw codes, just the Graphics object.

I’m skeptical of your (5, 5) x/y coordinates. Try something like (20, 20) or (50, 50). Also, make sure you’re setting the margins and paper size correctly in your page setup dialog.

Is there a way to write in the code the printer name ?

I did added the printer on the Mac using cups interface and it does work if i use lpr -P printer file.txt but so far I cannot make it to add the printer in the printer list, I guess the cups version has a bug .

So far I did not managed to make it work on windows, I will try tomorrow another pc .

You can’t set the printer name in code, but you could probably do it from the command line on Windows the same as you’re doing on Mac.

maybe, but the idea was to use XOJO for that, in that case I don’t need XOJO , just to run a command, and so far it does work with text but no idea how to draw graphics, I guess I need to dig little bit into the lpr part . The need for commands or raw data sending was just to be able to send the cut command in order to cut the paper, as you cannot do that , at least not on Mac. On Windows you set it within the driver .

Any other ideas please ?

Nothing seems to work with XOJO, I did tried the examples, I did tried some code that I found on the forum, once lass called directPrint which does not seem to do anything , it just crashes on

mb.ptr(8)= mb3

declare function StartDocPrinterA lib "winspool.drv" (phandle as integer, level as integer, _
d as ptr) as integer

job= StartDocPrinterA(handle, 1, mb)

I did put mb.ptr(4) instead of 8 as it was throwing OutOfBounds error and then It crashes on the StartDocPrinterA part, it simply dies without any warning .

So far as said if you do anything in Excel and just press print and choose the printer it just prints without any issues, while on XOJO it simply does not work.

I did set the paper size and all the details to be proper and still not even blinking.

I did tried MBS part but that one seems to print weird data and nothing related to what I put in the data side so that is no go for me either.

I just wonder how Excel, notepad, terminal, work and not here , what is done wrong that does not even want to initiate the printer.

Thanks

ho boy , that PageSetup dialog is quite annoying , why do we need all those steps ?

So I Select Page Setup , then I print in pdf then I print again, and select the proper printer and print and it works

No idea what to do,

Can this Page Setup be set once, saved as data and then called every time is needed ? so we can just show the printer and done ? or even the printer can we save it once and skip showing it and print it each time on same printer ?

Apparently printer works fine if I use the graphics directly but it seems that I need to do all those steps , I almost wasted another 200 E for another printer just because of this.

Yup. On the PrinterSetup object, there’s a string property called Settings. It’s in binary, so you’ll want to either hex or base64 encode it for storage, but the next time you want to use it, just load it from prefs and set it instead of showing the dialog.

Hi Tim,

I looked on some old project and it seems that i used the sample code you had here but apparently now fails on windows11, for no idea what reason when it reaches to mb3(8) it simply fails with out of bounds the code seems to stop in StartDoc method on the line

mb.ptr(8)= mb3

If TargetWindows Then
  dim job as integer
  
  dim mb as new memoryblock(12)
  dim mb1 as MemoryBlock
  dim mb2 as MemoryBlock
  dim mb3 as MemoryBlock
  
  mb1= new MemoryBlock(jobname.len+1)
  mb2= new MemoryBlock(4)
  mb3= new MemoryBlock(4)
  
  mb1.CString(0)= jobname
  mb2.Cstring(0)= ""
  mb3.CString(0)= "RAW"
  System.DebugLog("mbSize : " + mb.Size.ToString)
  System.DebugLog("mb3.Size : " + mb3.Size.ToString)
  mb.ptr(0)= mb1
  mb.ptr(4)= mb2
  mb.ptr(8)= mb3
  
  declare function StartDocPrinterA lib "winspool.drv" (phandle as integer, level as integer, _
  d as ptr) as integer
  
  job= StartDocPrinterA(handle, 1, mb)
  
  Return job
End If

Any idea why ? i don’t seem to get it, so far the mb is defined as 12 , mb3 has 4 so 8 + 4 = 12 but this throws error

Thanks

Problem solved , it was fixed here for anyone who is interested