-1

I have following code which sends data to printer and prints page. I want somehow to tell th printer the top margin of the page. Is there anyway i could do that with current code? The printer is Zebra and uses ZPL-II.

Dim data As String = "path to file"
Dim client As New TcpClient()
client.Connect(IPadressDrukarki, 8569)
Dim stream As NetworkStream = client.GetStream()
Dim sendBytes As Byte() = IO.File.ReadAllBytes(data)
stream.Write(sendBytes, 0, sendBytes.Length)
stream.Close(9000)
client.Close()

EDIT: Will this print out top margin of 100 dots?

Dim data As String = "^XA^LH0,100^XZ some text"
Arie
  • 3,041
  • 7
  • 32
  • 63

1 Answers1

2

^LHx,y (Label Home) allows defining the upper-left corner of the label format. It is best to include it in the label definition (typically right after the ^XA), but it can also be sent separately. For example, if you want to move the printing down 100 dots, you could send ^XA^LH0,100^XZ to the printer prior to sending the actual label format.

Additional response to questions asked by the OP.

Your code is a little confusing because you appear to be using the term some text to mean an actual file path(?). And IO.File.ReadAllBytes(data) then reads in the file, which we must assume is a ZPL label format.

So to answer your question then yes, just insert ^XA^LH0,100^XZ before the file contents of some text when sending to the printer.

Mark Warren
  • 1,321
  • 1
  • 7
  • 4
  • so based on my example if I want to make top margin 100 dots should I set my string as I shown in main post's edit section? – Arie Jun 03 '22 at 22:16
  • 1
    It depends. Is the _some text_ the actual label format with its own `^XA` and `^XZ` delimiters? A typical label format starts with `^XA` and ends with `^XZ` and between those are all the formatting and data commands. You can simply add `^LH0,100` right after the `^XA` if you want to include the offset in the format. Or you can send `^XA^LH0,100^XZ` before sending the actual label format. – Mark Warren Jun 03 '22 at 23:09
  • But the way i show in main post? Can u take a Look? If not how then should I do that in my currently code? – Arie Jun 04 '22 at 15:20
  • I have updated my response. Can you please confirm that `some text` is actually a file path? – Mark Warren Jun 05 '22 at 02:17
  • yes, my bad its path to file. So simply speaking in the file content at the beginning just add ^XA^LH0,100^XZ and then space and rest content? – Arie Jun 05 '22 at 10:20
  • This is great if you don't want to widen the margins. `^LH` doesn't support negative values. – TheMet4lGod Aug 16 '23 at 13:45