I want to loop through a list of Member
objects and print their names and addresses, like this:
foreach (Member member in members) {
sb.AppendLine();
sb.AppendLine("N");
sb.AppendLine(string.Format("A50,50,0,2,1,1,N,\"{0}\"", member.name));
sb.AppendLine(string.Format("A50,50,0,2,1,1,N,\"{0}\"", member.address));
sb.AppendLine("P1");
RawPrinterHelper.SendStringToPrinter(printerName, sb.ToString());
}
But surely there must be an easier way to pass multiple labels to the printer? Sending it once and letting the printer loop through a set of variables?
Finally solved this. Here's a bit more information to extend the answers from OTisley
and Brad Chrisite
.
I used this page to download fonts to the printer: Converting and Downloading Fonts.
And this code to loop through the members:
StringBuilder sb = new StringBuilder();
foreach (Member member in members) {
sb.AppendLine();
sb.AppendLine("N");
sb.AppendLine(string.Format("A10,10,0,b,1,1,N,\"{0}\"", member.name));
sb.AppendLine(string.Format("A10,45,0,b,1,1,N,\"{0}\"", member.address));
sb.AppendLine("P1,1");
}
string sendThisToPrinter = sb.ToString();
Explanation of the format sent to printer:
A10 = offset left in dots
10 = offset top in dots
0 = Rotation of the text
b = The font name you set when you downloaded the fonts to the printer.
1 = Expand the text horizontally x number of times.
1 = Expand the text vertically x number of times.
N = N ormal or R eversed text.
\"{0}\" = The text to print.