Multiple Labels On A Sheet Of A4
Hi,
I'm trying to print 2 labels on a sheet of A4 with different data. I haven't found a way to accomplish this.
I end up getting one label on a sheet of A4.
Below is my code in C#. Thank you.
using (Engine btEngine = new Engine(true))
{
// 3 seconds
int waitForCompletionTimeout = 3000;
//Start Engine. Prep Document
btEngine.Start();
LabelFormatDocument btFormat = btEngine.Documents.Open(@"\\FileServer\Templates\A4 Side Mark.btw");
//Set Rows
btFormat.PageSetup.LabelRows = 2;
//Loop through DataTable
for (int i = 0; i < PrintDT.Rows.Count; i++)
{
//Set Label Substrings
btFormat.SubStrings["Part-No"].Value = PrintDT.Rows[i]["PartNo"].ToString();
btFormat.SubStrings["PartNo"].Value = PrintDT.Rows[i]["PartNo"].ToString().Replace("-", "");
btFormat.SubStrings["PartVersion"].Value = PrintDT.Rows[i]["PartVersion"].ToString();
btFormat.SubStrings["OrderID"].Value = PrintDT.Rows[i]["OrderCode"].ToString();
btFormat.SubStrings["PartDesc"].Value = PrintDT.Rows[i]["PartDesc"].ToString();
btFormat.SubStrings["QTY"].Value = PrintDT.Rows[i]["BoxQty"].ToString();
btFormat.SubStrings["PalletNo"].Value = "TT" + Convert.ToInt32(PrintDT.Rows[i]["PalletNo"]).ToString("D3");
btFormat.SubStrings["BoxNo"].Value = "TT" + Convert.ToInt32(PrintDT.Rows[i]["BoxNo"]).ToString("D4");
btFormat.SubStrings["Date"].Value = Convert.ToDateTime(PrintDT.Rows[i]["ShipDate"]).ToShortDateString();
btFormat.SubStrings["NW"].Value = (Convert.ToDouble(PrintDT.Rows[i]["NetWeight"]) / 1000).ToString();
btFormat.SubStrings["GW"].Value = ((Convert.ToDouble(PrintDT.Rows[i]["NetWeight"]) / 1000) + Convert.ToDouble(PrintDT.Rows[i]["BoxWeight"])).ToString();
btFormat.SubStrings["2D"].Value = PrintDT.Rows[i]["PartNo"].ToString() + ";"
+ PrintDT.Rows[i]["PartVersion"].ToString() + ";"
+ PrintDT.Rows[i]["OrderCode"].ToString() + ";"
+ PrintDT.Rows[i]["BoxQty"].ToString() + ";"
+ "TT" + Convert.ToInt32(PrintDT.Rows[i]["PalletNo"]).ToString("D3") + ";"
+ "TT" + Convert.ToInt32(PrintDT.Rows[i]["BoxNo"]).ToString("D4") + ";"
+ Convert.ToDateTime(PrintDT.Rows[i]["ShipDate"]).ToShortDateString() + ";";
//Print Label and get result
result = btFormat.Print("Print Labels", waitForCompletionTimeout, out msgs);
}
string messageString = "\n\nMsg:";
//Prep Message
foreach (Seagull.BarTender.Print.Message message in msgs)
{
messageString += "\n\n" + message.Text;
}
//If Print failed
if (result == Result.Failure)
{
MessageBox.Show(this, "Print Failed!" + messageString, "Print Labels");
}
btEngine.Stop();
}
-
Each time you call Print() a new print job will be sent to the printer, and as a result, the page will feed out of the A4 printer. If you're wishing to print different data for a multi-label based page / A4 sheet, you will need to have BT connect to a text database file instead, where 1 row means one label to be printed. You would first fill this file with variable data, and then have BarTender print it. Attached is an example of how this can be done:
using
Seagull.BarTender.Print.Database;// Application Code
// ...
Engine btEngine = new Engine();
// Start a BarTender print engine
btEngine.Start();
// Open a label format
LabelFormatDocument btFormat =
btEngine.Documents.Open(@"c:\MyLabel.btw");// Set the TextFile database connection
file name((TextFile)btFormat.DatabaseConnections["TextFileDB"]).FileName = @"c:\NutritionInformationEurope.txt";
// Print the label format document
btFormat.Print();
// Stop the engine
btEngine.Stop();
0 -
I don't know why I'm resistant of outputing to a text file and send the file to Bartender for printing.
But I guess it's either this way or setting up the .BTW to accept two sets of data, which doesn't sound like a good idea.
Thank you for your response.
0
请先登录再写评论。
评论
2 条评论