I am working on a zebra label, but the label is printing a little bit to the right, I was told to create a textbox to hold the offset value given by the user in a cookies. Is there any way to auto calibrate the zebra printer and label position? I read the ZPL guide and found out that ^FO and ^FT both could help me achieve this. So one thing I can do is read my zpllabel.txt and try to find ^FO value and add the desired value from the textbox and then send it to the printer, but if anyone has had this issue and has come up with an easier way to auto calibrate a Zebra printer please help me out:
here is the label I am working on:
^XA^MCY^PRD,D,D^MMT,N^XZ
^XA
^DFCASENEW^FS
^LH0,0
^FO33,45^A0N,90,98^FN01^FS^FX Company^FS
^FO879,28^A0N,263,214^FN02^FS^FX Product^FS
^FO30,159^A0N,90,58^FN03^FS^FX Description^FS
^FO42,321^A0N,65,68^FN04^FS^FX NumberIn^FS
^FO100,436^A0N,75,66^FN05^FS^FX SelectCode^FS
^BY6,,230^FO260,252^BCN,,N,N,N,N^FN06^FS^FX RotationProduct^FS
^FO660,503^A0N,32,98^FN07^FS^FX RotationProduct^FS
^BY4,3.0,204^FO60,518^B2N,,N,N,N^FN08^FS^FX UPCCode^FS
^FO170,732^A0N,24,47^FN09^FS^FX UPCCode^FS
^FO32,516^GB590,0,10^FS
^FO32,717^GB590,0,10^FS
^FO640,573^A0N,226,212^FN10^FS^FX Rotation^FS
^FO1362,546^A0N,90,66^FDBest Before^FS
^FO1235,628^A0N,134,140^FN11^FS^FX BestBefore^FS
^FO55,391^A0N,43,77^FDSEL^FS
^FO30,267^A0N,54,100^FDQTY^FS
^XZ
^XA^XFCASENEW
^FN01^FDCompany^FS
^FN02^FDProduct^FS
^FN03^FDDescription^FS
^FN04^FDNumberIn^FS
^FN05^FDSelectCode^FS
^FN06^FDRotationProduct^FS
^FN07^FD^FS
^FN08^FDUPCCode^FS
^FN09^FD^FS
^FN10^FDRotation^FS
^FN11^FDBestBefore^FS
^PQ1,0,1,Y
^XZ
^XA^ID*.*^XZ
If I have to find all the ^FO's in my textfile and add to the value how can i achieve this?
try
{
byte[] file = File.ReadAllBytes("C:\\Users\\something\\Documents\\Visual Studio 2013\\Projects\\zplTest\\zplTest\\zpllabel3.txt");
using (MemoryStream memory = new MemoryStream(file))
{
using (TextReader reader = new StreamReader(memory))
{
string input = reader.ReadToEnd();
// for (int i = 0; 1 < file.Length; i++)
{
using (MemoryStream writermemory = new MemoryStream())
using (StreamWriter writer = new StreamWriter(writermemory))
{
Dictionary<string, string> replacementcollections =
new Dictionary<string, string>();
replacementcollections.Add
("^FN01^FDCompany^FS", compname);
replacementcollections.Add
("^FN02^FDProduct^FS", stlabel23);
replacementcollections.Add
("^FN03^FDDescription^FS", stlabel24);
replacementcollections.Add
("^FN04^FDNumberIn^FS", stlabel25);
replacementcollections.Add
("^FN05^FDSelectCode^FS", stlabel26);
replacementcollections.Add
("^FN06^FDRotationProduct^FS", stlabel27);
replacementcollections.Add
("^FN07^FD^FS", stlabel28);
replacementcollections.Add
("^FN08^FDUPCCode^FS", stlabel29.TrimEnd());
replacementcollections.Add
("^FN09^FD^FS", stlabel30.TrimEnd());
replacementcollections.Add
("^FN10^FDRotation^FS", "^FN10^FD" + TxtRotcode.Text.Trim() + "^FS");
replacementcollections.Add
("^FN11^FDBestBefore^FS", "^FN11^FD" + TxtBestBefore.Text.Trim() + "^FS");
replacementcollections.Add
("^PQ1,0,1,Y", "PQ" + TxtQty.Text.Trim() + ",0,1,Y");
string output = input;
foreach (KeyValuePair<string, string>
replacement in replacementcollections)
{ output = output.Replace(replacement.Key, replacement.Value); }
Label256.Visible = true;
zplcode.Text = output;
zplcode.Visible = true;
writer.Close();
ZplPreview();
}
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace.ToString());
Console.WriteLine(ex.Message.ToString());
}
The Label Home ^LH
command allows you to give an x,y offset adjustment for the entire label - effectively a margin. Unfortunately I've realised it doesn't support negative values, so it won't allow you to shift the label contents left in this case. But you could always give it a go?
Is there a reason you can't adjust the code that generates the file to adjust the X-coords? I.e. avoid the find replace by adjusting them before they are written. That's how I do it.
It looks like you already have a text file template for the label which you're replacing text variables in. You could simply add more variables for the FO values and handle them in replacementcollections
the same as the other vars.
Or you could read your file line by line, looping over each line whilst searching for IndexOf()
`^FO', parsing the syntax and replacing the FO co-ords there.