網(wǎng)站首頁 編程語言 正文
一、引用BarcodeStandard.dll
#region BarcodeStandard.dll
/*
*
* 使用說明
需要通過NuGet進(jìn)行安裝BarcodeLib.dll,必不可少
*/
string inputString;
/// <summary>
/// 獲取所以打印機(jī)驅(qū)動名稱
/// </summary>
private void getPrintDocumentlist()
{
PrintDocument print = new PrintDocument();
string sDefault = print.PrinterSettings.PrinterName;//默認(rèn)打印機(jī)名
comboBox_drive.Items.Add(sDefault);
comboBox_drive.Text = sDefault;//顯示默認(rèn)驅(qū)動名稱
foreach (string sPrint in PrinterSettings.InstalledPrinters)//獲取所有打印機(jī)名稱
{
if (sPrint != sDefault)
{
comboBox_drive.Items.Add(sPrint);
}
}
}
/// <summary>
/// 打印繪制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Font titleFont = new Font("宋體", 9, FontStyle.Bold);//標(biāo)題字體
Font fntTxt = new Font("宋體", 9, FontStyle.Regular);//正文文字
Brush brush = new SolidBrush(Color.Black);//畫刷
Pen pen = new Pen(Color.Black); //線條顏色
Point po = new Point(10, 10);
try
{
//畫String
e.Graphics.DrawString(GetPrintSW().ToString(), titleFont, brush, po);//打印內(nèi)容
//畫橫線
//Point[] point = { new Point(20, 50), new Point(200, 50) };//縱坐標(biāo)不變
//e.Graphics.DrawLines(pen, point);
//畫豎線
//Point[] points1 = { new Point(60, 70), new Point(60, 70 + 40) };//橫坐標(biāo)不變
//e.Graphics.DrawLines(pen, points1);
//畫矩形
//e.Graphics.DrawRectangle(pen, 20, 70, 90, 90);
}
catch (Exception ex)
{
MessageBox.Show(this, "打印出錯!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
/// <summary>
/// 獲取打印內(nèi)容
/// </summary>
/// <returns></returns>
public StringBuilder GetPrintSW()
{
StringBuilder sb = new StringBuilder();
string tou = "XXXXXX科技有限公司";
string address = "安徽省合肥市瑤海區(qū)";
string saleID = "100010000001"; //單號
string item = "項(xiàng)目";
decimal price = 25.00M;
int count = 5;
decimal total = 0.00M;
decimal fukuan = 500.00M;
sb.AppendLine(" " + tou + " \n");
sb.AppendLine("-----------------------------------------");
sb.AppendLine("日期:" + DateTime.Now.ToShortDateString() + " " + "單號:" + saleID);
sb.AppendLine("-----------------------------------------");
sb.AppendLine("項(xiàng)目" + " " + "數(shù)量" + " " + "單價(jià)" + " " + "小計(jì)");
for (int i = 0; i < count; i++)
{
decimal xiaoji = (i + 1) * price;
sb.AppendLine(item + (i + 1) + " " + (i + 1) + " " + price + " " + xiaoji);
total += xiaoji;
}
sb.AppendLine("-----------------------------------------");
sb.AppendLine("數(shù)量:" + count + " 合計(jì): " + total);
sb.AppendLine("付款:" + fukuan);
sb.AppendLine("現(xiàn)金找零:" + (fukuan - total));
sb.AppendLine("-----------------------------------------");
sb.AppendLine("地址:" + address + "");
sb.AppendLine("電話:130000000000");
sb.AppendLine("謝謝惠顧歡迎下次光臨!");
sb.AppendLine("-----------------------------------------");
return sb;
}
/// <summary>
/// 生成條形碼
/// </summary>
/// <param name="content">內(nèi)容</param>
/// <returns></returns>
public static Image GenerateBarCodeBitmap(string content)
{
using (var barcode = new Barcode()
{
IncludeLabel = true,
Alignment = AlignmentPositions.CENTER,
Width = 250,
Height = 100,
RotateFlipType = RotateFlipType.RotateNoneFlipNone,
BackColor = Color.White,
ForeColor = Color.Black,
})
{
return barcode.Encode(TYPE.CODE128B, content);
}
}
#endregion
二、引用Seagull.BarTender.Print.dll
#region Seagull.BarTender.Print.dll
/// <summary>
/// 打印測試
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void printbt_Click(object sender, EventArgs e)
{
string qd = comboBox_drive.Text;//下拉列表選擇的驅(qū)動名稱
var printDocument = new PrintDocument();
//指定打印機(jī)
printDocument.PrinterSettings.PrinterName = qd;//驅(qū)動名稱
printDocument.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
try
{
//打印預(yù)覽
//PrintPreviewDialog ppd = new PrintPreviewDialog();
//ppd.Document = printDocument;
//ppd.ShowDialog();
//打印
printDocument.Print();
}
catch (InvalidPrinterException)
{
}
finally
{
printDocument.Dispose();
}
}
/// <summary>
/// BarTender打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BarTender_Click(object sender, EventArgs e)
{
try
{
//程序中寫入引用 using Seagull.BarTender.Print.dll,必不可少;
//安裝Bartender后,在安裝的根目錄或者system32下課可找到對應(yīng)的dll
#region
Engine btEngine = new Engine();
btEngine.Start();
string lj = AppDomain.CurrentDomain.BaseDirectory + "test.btw"; //test.btw是BT的模板
LabelFormatDocument btFormat = btEngine.Documents.Open(lj);
//對BTW模版相應(yīng)字段進(jìn)行賦值
btFormat.SubStrings["name"].Value ="Liming";
btFormat.SubStrings["code"].Value = "1234567890";
//指定打印機(jī)名
btFormat.PrintSetup.PrinterName = "WPS 虛擬打印機(jī)";
//改變標(biāo)簽打印數(shù)份連載
btFormat.PrintSetup.NumberOfSerializedLabels = 1;
//打印份數(shù)
btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
Messages messages;
int waitout = 10000; // 10秒 超時(shí)
Result nResult1 = btFormat.Print("標(biāo)簽打印軟件", waitout, out messages);
btFormat.PrintSetup.Cache.FlushInterval = CacheFlushInterval.PerSession;
//不保存對打開模板的修改
btFormat.Close(Seagull.BarTender.Print.SaveOptions.DoNotSaveChanges);
//結(jié)束打印引擎
btEngine.Stop();
#endregion
}
catch (Exception ex)
{
MessageBox.Show("錯誤信息: " + ex.Message);
return;
}
}
#endregion
三、引用 Interop.LabelManager2.dll
#region Interop.LabelManager2.dll
/// <summary>
/// 打印功能 CodeSoft
/// </summary>
/// <param name="PrintParam1">打印模板參數(shù)值1</param>
/// <param name="PrintParam2">打印模板參數(shù)值2</param>
/// <param name="PrintParam3">打印模板參數(shù)值3</param>
/// <param name="PrintParam4">打印模板參數(shù)值4</param>
/// <returns></returns>
public bool SoftCodePrint(string PrintParam1 = "", string PrintParam2 = "", string PrintParam3 = "", string PrintParam4 = "")
{
bool result = false;
int printNum = 2;//打印份數(shù)
try
{
string text = string.Empty;
ApplicationClass labApp = null;
Document doc = null;
string labFileName = AppDomain.CurrentDomain.BaseDirectory + "Template\\" + "Test.Lab";//模板地址
if (!File.Exists(labFileName))
{
throw new Exception("沒有找到標(biāo)簽?zāi)0?);
}
for (int i = 0; i < printNum; i++)
{
labApp = new ApplicationClass();
labApp.Documents.Open(labFileName, false);// 調(diào)用設(shè)計(jì)好的label文件
doc = labApp.ActiveDocument;
//可通過配置檔進(jìn)行配置打印信息
doc.Variables.FreeVariables.Item("模板變量名稱1").Value = PrintParam1;
doc.Variables.FreeVariables.Item("模板變量名稱2").Value = PrintParam2;
doc.Variables.FreeVariables.Item("模板變量名稱3").Value = PrintParam3;
doc.Variables.FreeVariables.Item("模板變量名稱4").Value = PrintParam4;
doc.PrintDocument(1);
}
labApp.Quit();
result = true;
}
catch (Exception ex)
{
}
return result;
}
#endregion
dll下載地址
原文鏈接:https://www.cnblogs.com/wml-it/p/15982300.html
相關(guān)推薦
- 2022-12-08 C++?float轉(zhuǎn)std::string?小數(shù)位數(shù)控制問題_C 語言
- 2022-09-02 selenium動態(tài)數(shù)據(jù)獲取的方法實(shí)現(xiàn)_python
- 2022-11-26 React?DnD如何處理拖拽詳解_React
- 2022-12-03 高并發(fā)技巧之Redis和本地緩存使用技巧分享_Redis
- 2022-12-12 C語言解讀數(shù)組循環(huán)右移問題_C 語言
- 2022-05-13 error hawk@0.10.2: The engine “node“ is incompatib
- 2022-09-15 C++中的幾個特殊符號說明_C 語言
- 2023-04-20 npm ERR! 400 Bad Request - PUT xxx - Cannot publis
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支