c#BarTender打印,打印微调
方法一、引用“Interop.BarTender.dll”单个打印
BarTender.Application btApp; BarTender.Format btFormat; btApp = new BarTender.Application(); btFormat = btApp.Formats.Open(tbPath.Text, false, ""); btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; btFormat.PrintSetup.NumberSerializedLabels = 1; btFormat.SetNamedSubStringValue("cm", "AAA"); btFormat.SetNamedSubStringValue("DATE", DateTime.Now.ToString("yyyy-MM-dd")); btFormat.SetNamedSubStringValue("PN", "AAA"); btFormat.SetNamedSubStringValue("R", "AA"); btFormat.SetNamedSubStringValue("V1", "BBB"); btFormat.SetNamedSubStringValue("xl", "CCC"); btFormat.PrintOut(false, false); btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
方法二、引用“Seagull.BarTender.Print.dll”批量打印数据
using Seagull.BarTender.Print; using Seagull.BarTender.Print.Database; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < table.Rows.Count; i++) { stringBuilder.Append(table.Rows[i][0].ToString()); stringBuilder.Append("\t").Append(table.Rows[i][1].ToString()); stringBuilder.AppendLine(); } File.WriteAllText(tbDataPath.Text, stringBuilder.ToString()); Engine engine = new Engine(); engine.Start(); LabelFormatDocument labelFormatDocument = engine.Documents.Open(tbPath.Text); ((TextFile)labelFormatDocument.DatabaseConnections["TextFileDB"]).FileName = tbDataPath.Text;
labelFormatDocument.PrintSetup.IdenticalCopiesOfLabel = 1;//打印一份
labelFormatDocument.PageSetup.MarginTop = (float)nudMarginTop.Value;//上边距
labelFormatDocument.PageSetup.MarginLeft = (float)nudMarginLeft.Value;//左边距
#region 打印预览设置
//engine.Window.VisibleWindows = VisibleWindows.InteractiveDialogs;//开启打印预览
//labelFormatDocument.PrintPreview.ShowPrintDialogOnPrint = true;
//labelFormatDocument.PrintPreview.StatusBarVisible = true;
//labelFormatDocument.PrintPreview.ToolbarVisible = true;
//labelFormatDocument.PrintPreview.StatusBarVisible = true;
//labelFormatDocument.PrintPreview.ShowDialog();
#endregion
labelFormatDocument.PrintSetup.PrinterName = "PrimoPDF";//设置打印机 Cursor.Current = Cursors.WaitCursor; int waitForCompletionTimeout = 10000; Messages messages; Result result = labelFormatDocument.Print(tbPath.Text, waitForCompletionTimeout, out messages);
TXT文件内容
SN01 XX00015
SN02 XX00016
SN03 XX00017
SN04 XX00018
SN05 XX00019
BarTender打印微调
打印布局在以下代码属性中微调
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)