rkone / sharpzebra

A .net library that simplifies printing to Zebra printers in their native EPL2/ZPL languages without needing to know EPL2 or ZPL.
MIT License
91 stars 34 forks source link

TextAlign #7

Closed Mtime10 closed 6 years ago

Mtime10 commented 6 years ago

I need to print some text on a 4x6 label from far left (0) to 420, and wrap the text below as the string will be longer that that amount of space. I thought TextAlign might be the route for that, but I cannot figure that out.

I have multiple 'boxes' I'm drawing with bar codes and text in the box space. this 'box' is the only piece i cannot figure out without manually splitting the string based on calculating how much one line in the 'box' can hold and then writing a new line below with the remainder of the string?

Any help would be much appreciated!

rkone commented 6 years ago

Here's an example for how you would wrap text to a 2nd line using TextAlign. The box is at 20,20 on the label, with a width of 500.

 res = new List<byte>();
 res.AddRange(ZPLCommands.ClearPrinter(printer.Settings));
 res.AddRange(ZPLCommands.TextAlign(500, Alignment.LEFT, 2, 5, 0, ZPLCommands.TextWrite(20, 20, ElementDrawRotation.NO_ROTATION, 50, TextToWrap)));
 res.AddRange(ZPLCommands.PrintBuffer(1));
 printer.Print(res.ToArray());
Mtime10 commented 6 years ago

Thanks for the reply and for the library as a whole. Was able to completely replicate an SAP label using sharpzebra. Very helpful!