using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;//This is about DllImport. namespace VCsharp_2005
{
public partial class Form1 : Form
{
const uint IMAGE_BITMAP = 0;
const uint LR_LOADFROMFILE = 16;
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType,
int cxDesired, int cyDesired, uint fuLoad);
[DllImport("Gdi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int DeleteObject(IntPtr ho);
const string szSavePath = "C:\\Argox";
const string szSaveFile = "C:\\Argox\\PPLB_Example.Prn";
const string sznop1 = "nop_front\r\n";
const string sznop2 = "nop_middle\r\n";
[DllImport("Winpplb.dll")]
private static extern int B_Bar2d_Maxi(int x, int y, int cl, int cc, int pc, string data);
[DllImport("Winpplb.dll")]
private static extern int B_Bar2d_PDF417(int x, int y, int w, int v, int s, int c, int px,
int py, int r, int l, int t, int o, string data);
[DllImport("Winpplb.dll")]
private static extern int B_Bar2d_PDF417_N(int x, int y, int w, string para, string data);
[DllImport("Winpplb.dll")]
private static extern void B_ClosePrn();
[DllImport("Winpplb.dll")]
private static extern int B_CreatePrn(int selection, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Del_Form(string formname);
[DllImport("Winpplb.dll")]
private static extern int B_Del_Pcx(string pcxname);
[DllImport("Winpplb.dll")]
private static extern int B_Draw_Box(int x, int y, int thickness, int hor_dots,
int ver_dots);
[DllImport("Winpplb.dll")]
private static extern int B_Draw_Line(char mode, int x, int y, int hor_dots, int ver_dots);
[DllImport("Winpplb.dll")]
private static extern int B_Error_Reporting(char option);
[DllImport("Winpplb.dll")]
private static extern IntPtr B_Get_DLL_Version(int nShowMessage);
[DllImport("Winpplb.dll")]
private static extern int B_Get_DLL_VersionA(int nShowMessage);
[DllImport("Winpplb.dll")]
private static extern int B_Get_Graphic_ColorBMP(int x, int y, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Get_Graphic_ColorBMPEx(int x, int y, int nWidth, int nHeight,
int rotate, string id_name, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Get_Graphic_ColorBMP_HBitmap(int x, int y, int nWidth, int nHeight,
int rotate, string id_name, IntPtr hbm);
[DllImport("Winpplb.dll")]
private static extern int B_Get_Pcx(int x, int y, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Initial_Setting(int Type, string Source);
[DllImport("Winpplb.dll")]
private static extern int B_WriteData(int IsImmediate, byte[] pbuf, int length);
[DllImport("Winpplb.dll")]
private static extern int B_ReadData(byte[] pbuf, int length, int dwTimeoutms);
[DllImport("Winpplb.dll")]
private static extern int B_Load_Pcx(int x, int y, string pcxname);
[DllImport("Winpplb.dll")]
private static extern int B_Open_ChineseFont(string path);
[DllImport("Winpplb.dll")]
private static extern int B_Print_Form(int labset, int copies, string form_out, string var);
[DllImport("Winpplb.dll")]
private static extern int B_Print_MCopy(int labset, int copies);
[DllImport("Winpplb.dll")]
private static extern int B_Print_Out(int labset);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Barcode(int x, int y, int ori, string type, int narrow,
int width, int height, char human, string data);
[DllImport("Winpplb.dll")]
private static extern void B_Prn_Configuration();
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text(int x, int y, int ori, int font, int hor_factor,
int ver_factor, char mode, string data);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_Chinese(int x, int y, int fonttype, string id_name,
string data);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_TrueType(int x, int y, int FSize, string FType,
int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, string id_name,
string data);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_TrueType_W(int x, int y, int FHeight, int FWidth,
string FType, int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut,
string id_name, string data);
[DllImport("Winpplb.dll")]
private static extern int B_Select_Option(int option);
[DllImport("Winpplb.dll")]
private static extern int B_Select_Option2(int option, int p);
[DllImport("Winpplb.dll")]
private static extern int B_Select_Symbol(int num_bit, int symbol, int country);
[DllImport("Winpplb.dll")]
private static extern int B_Select_Symbol2(int num_bit, string csymbol, int country);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Backfeed(char option);
[DllImport("Winpplb.dll")]
private static extern int B_Set_BMPSave(int nSave, string strBMPFName);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Darkness(int darkness);
[DllImport("Winpplb.dll")]
private static extern int B_Set_DebugDialog(int nEnable);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Direction(char direction);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Form(string formfile);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Labgap(int lablength, int gaplength);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Labwidth(int labwidth);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Originpoint(int hor, int ver);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Prncomport(int baud, char parity, int data, int stop);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Prncomport_PC(int nBaudRate, int nByteSize, int nParity,
int nStopBits, int nDsr, int nCts, int nXonXoff);
[DllImport("Winpplb.dll")]
private static extern int B_Set_Speed(int speed);
[DllImport("Winpplb.dll")]
private static extern int B_Set_ProcessDlg(int nShow);
[DllImport("Winpplb.dll")]
private static extern int B_GetUSBBufferLen();
[DllImport("Winpplb.dll")]
private static extern int B_EnumUSB(byte[] buf);
[DllImport("Winpplb.dll")]
private static extern int B_CreateUSBPort(int nPort);
[DllImport("Winpplb.dll")]
private static extern int B_ResetPrinter();
[DllImport("Winpplb.dll")]
private static extern int B_GetPrinterResponse(byte[] buf, int nMax);
[DllImport("Winpplb.dll")]
private static extern int B_TFeedMode(int nMode);
[DllImport("Winpplb.dll")]
private static extern int B_TFeedTest();
[DllImport("Winpplb.dll")]
private static extern int B_CreatePort(int nPortType, int nPort, string filename);
[DllImport("Winpplb.dll")]
private static extern int B_Execute_Form(string form_out, string var);
[DllImport("Winpplb.dll")]
private static extern int B_Bar2d_QR(int x, int y, int model, int scl, char error,
char dinput, int c, int d, int p, string data);
[DllImport("Winpplb.dll")]
private static extern int B_GetNetPrinterBufferLen();
[DllImport("Winpplb.dll")]
private static extern int B_EnumNetPrinter(byte[] buf);
[DllImport("Winpplb.dll")]
private static extern int B_CreateNetPort(int nPort);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_TrueType_Uni(int x, int y, int FSize, string FType,
int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, string id_name,
byte[] data, int format);
[DllImport("Winpplb.dll")]
private static extern int B_Prn_Text_TrueType_UniB(int x, int y, int FSize, string FType,
int Fspin, int FWeight, int FItalic, int FUnline, int FStrikeOut, string id_name,
byte[] data, int format);
[DllImport("Winpplb.dll")]
private static extern int B_GetUSBDeviceInfo(int nPort, byte[] pDeviceName,
out int pDeviceNameLen, byte[] pDevicePath, out int pDevicePathLen);
[DllImport("Winpplb.dll")]
private static extern int B_Set_EncryptionKey(string encryptionKey);
[DllImport("Winpplb.dll")]
private static extern int B_Check_EncryptionKey(string decodeKey, string encryptionKey,
int dwTimeoutms); public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
//Test code start
// open port.
int nLen, ret, sw;
byte[] pbuf = new byte[128];
string strmsg;
IntPtr ver;
System.Text.Encoding encAscII = System.Text.Encoding.ASCII;
System.Text.Encoding encUnicode = System.Text.Encoding.Unicode; // dll version.
ver = B_Get_DLL_Version(0); // search port.
nLen = B_GetUSBBufferLen() + 1;
strmsg = "DLL ";
strmsg += Marshal.PtrToStringAnsi(ver);
strmsg += "\r\n";
if (nLen > 1)
{
byte[] buf1, buf2;
int len1 = 128, len2 = 128;
buf1 = new byte[len1];
buf2 = new byte[len2];
B_EnumUSB(pbuf);
B_GetUSBDeviceInfo(1, buf1, out len1, buf2, out len2);
sw = 1;
if (1 == sw)
{
ret = B_CreatePrn(12, encAscII.GetString(buf2, 0, len2));// open usb.
}
else
{
ret = B_CreateUSBPort(1);// must call B_GetUSBBufferLen() function fisrt.
}
if (0 != ret) {
strmsg += "Open USB fail!";
}
else {
strmsg += "Open USB:\r\nDevice name: ";
strmsg += encAscII.GetString(buf1, 0, len1);
strmsg += "\r\nDevice path: ";
strmsg += encAscII.GetString(buf2, 0, len2);
//sw = 2;
if (2 == sw)
{
//Immediate Error Report.
B_WriteData(1, encAscII.GetBytes("^ee\r\n"), 5);//^ee
ret = B_ReadData(pbuf, 4, 1000);
}
}
}
else
{
System.IO.Directory.CreateDirectory(szSavePath);
ret = B_CreatePrn(0, szSaveFile);// open file.
strmsg += "Open ";
strmsg += szSaveFile;
if (0 != ret) {
strmsg += " file fail!";
}
else {
strmsg += " file succeed!";
}
}
MessageBox.Show(strmsg);
if (0 != ret)
return; // sample setting.
B_Set_DebugDialog(1);
B_Set_Originpoint(0,0);
B_Select_Option(2);
B_Set_Darkness(8);
B_Del_Pcx("*");// delete all picture.
B_WriteData(0, encAscII.GetBytes(sznop2), sznop2.Length);
B_WriteData(1, encAscII.GetBytes(sznop1), sznop1.Length); //draw box.
B_Draw_Box(20, 20, 4, 760, 560);
B_Draw_Line('O', 400, 20, 4, 540); //print text, true type text.
B_Prn_Text(30, 40, 0, 2, 1, 1, 'N', "PPLB Lib Example");
B_Prn_Text_TrueType(30,100,30,"Arial",1,400,0,0,0,"AA","TrueType Font");//save in printer.
B_Prn_Text_TrueType_W(30,160,20,20,"Times New Roman",1,400,0,0,0,"AB","TT_W: 多字元測試");
B_Prn_Text_TrueType_Uni(30,220,30,"Times New Roman",1,400,0,0,0,"AC",Encoding.Unicode.GetBytes("TT_Uni: 多字元測試"),1);//UTF-16
encUnicode.GetBytes("\xFEFF", 0, 1, pbuf, 0);//UTF-16.//pbuf[0]=0xFF,pbuf[1]=0xFE;
encUnicode.GetBytes("TT_UniB: 多字元測試", 0, 14, pbuf, 2);//copy mutil byte.
encUnicode.GetBytes("\x0000", 0, 1, pbuf, 30);//null.//pbuf[30]=0x00,pbuf[31]=0x00;
B_Prn_Text_TrueType_UniB(30,280,30,"Times New Roman",1,400,0,0,0,"AD",pbuf,0);//Byte Order Mark. //barcode.
B_Prn_Barcode(420, 100, 0, "3", 2, 3, 40, 'B', "1234<+1>");//have a counter
B_Bar2d_QR(420, 200, 1, 3, 'M', 'A', 0, 0, 0, "QR CODE"); //picture.
B_Get_Graphic_ColorBMP(420, 280, "bb.bmp");// Color bmp file.
B_Get_Graphic_ColorBMPEx(420, 320, 200, 150, 2, "bb1", "bb.bmp");//180 angle.
IntPtr himage = LoadImage(IntPtr.Zero, "bb.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
B_Get_Graphic_ColorBMP_HBitmap(630, 280, 250, 80, 1, "bb2", himage);//90 angle.
if (IntPtr.Zero != himage)
DeleteObject(himage); // output.
B_Print_Out(2);// copy 2. // close port.
B_ClosePrn();
} private void button2_Click(object sender, EventArgs e)
{
//PPLBDLL Test code start
//B_CreatePrn(0, null); /*
int B_CreatePrn(int selection, LPCTSTR filename);
參數:
selection;
選擇輸出埠或檔案。
0 -> print to file.
1 -> lpt1, 2 -> lpt2, 3 -> lpt3
4 -> com1, 5 -> com2, 6 -> com3
10 -> pipe, 11 -> USBXXX, 12 -> USB
13 -> LAN Client(TCP/IP)
filename;
當 selection 是 0 時,資料則輸出至檔案,filename 為檔案名稱,可含路徑。
當 selection 是 10 時,filename 為輸出路徑或機碼(裝置路徑)。
當 selection 是 11 時,filename 指的是想開啟的USB之index, index由1開始;
當 selection 是 12 時,filename 指的是想開啟的USB機碼(裝置路徑),
和nPort = 10的使用方法一樣
當 selection 內容是 13 時, filename 指的是想開啟的IP Address, 使用TCP/IP去開啟;
預設的port值為9100, 若要指定port值, 如80, 則在IPAddress後加上字串":80".
*
int B_CreateUSBPort(int nPort);
參數:
nPort;
USB 傳輸埠 ; nPort由1開始.
*/
// USB Port Open
int nUSBDataLen;
byte[] pbuf;
nUSBDataLen = B_GetUSBBufferLen()+1;
pbuf = new byte[nUSBDataLen];
B_EnumUSB(pbuf);
B_CreateUSBPort(1); // Open com3
//B_CreatePort(1, 3, null);
//B_Set_Darkness(8);
//B_Select_Option(1);
//B_Set_Labgap(50,24);
//B_Set_Labwidth(816);
//B_Set_Speed(2);
//B_Error_Reporting('S'); B_Prn_Text(100, 200, 0, 3, 1, 1, 'N', "FONT 3"); //Get a text string.
// B_Prn_Text(200,10,1,3,1,1,'N',"Text 3<+1>");
B_Prn_Barcode(20, 20, 0, "1", 3, 3, 75, 'B', "079-305"); //Get a bar code.
//Get a PDF-417 2D bar code.
//B_Bar2d_PDF417(50, 150, 400, 300, 0, 0, 3, 7, 10, 2, 0, 0, "ARGOXINFO");
//Get a Maxi Code 2D bar code.
B_Bar2d_Maxi(400, 10, 300, 400, 93065, "This MaxiCode");
B_Draw_Line('E', 380, 200, 100, 10); //Line Draw by Exclusive or operation.
//B_Draw_Line('O', 400, 180, 10, 100); //Line draw by or operation.
//B_Draw_Line('W', 380, 220, 100, 10); //Draw white line.
//B_Draw_Line('E', 450, 180, 20, 110); //Line Draw by Exclusive or operation.
//B_Draw_Box(0, 0, 5, 815, 300); //Draw a box.
// B_Get_Pcx(50,55,"phone.pcx"); //Print Graphics of .PCX.
//B_Get_Pcx(400,0,"test1.pcx");
B_Prn_Text_TrueType(450, 20, 40, "Times New Roman", 1, 400, 0, 0, 0, "AA", "Library Test");
// Get a truetype text
//B_Prn_Text_TrueType(30,50,20,"Arial",4,400,0,0,0,"AB","TrueType Font");
B_Print_Out(1);
B_ClosePrn();
//PPLBDLL Test code end
}
}
}

PPLB条码打印的更多相关文章

  1. AX 条码打印

    AX 条码打印集成在BarCode类及其之类barcode*. 由子类的defaultFont方法指定字体属性. eg, BarcodeCode39 指定条码字体"BC C39 3 to 1 ...

  2. BarTender SDK 实现调用模板条码打印

    Demo:MyZebraPrint 基于BatTender .Net SDK 实现调用模板进行条码打印 有需要的朋友可以拿去研究下 在已经安装了BatTender10.1的电脑里测试通过. 下载地址: ...

  3. PowerBuilder -- 条码打印

    # 使用ocx控件 使用微软的MSBCODE9.OCX,但是注册老不成功,需要安装office之后才能注册成功,不知道有没有好的处理方法?? # 使用字体 字体下载:http://download.c ...

  4. smartforms 条码打印

    转自:http://blog.csdn.net/zhongguomao/article/details/6759642 SAP 条码打印有 新旧 两种技术方法:1.传统的(旧):将数据发送到打印机上, ...

  5. C#.Net集成Bartender条码打印,VS调试运行可以打印,发布到IIS运行打印报错

    C#.Net集成Bartender条码打印,VS调试运行可以打印,发布到IIS运行打印报错 问题原因: 问题出现在iis账户权限. 解决方法: iis默认是用network service这个账户去执 ...

  6. RDLC系列之七 条码打印

    参考: C# 条码标签打印程序,RDLC报表动态显示多条码标签的方法 http://www.cnblogs.com/vice/p/4105898.html 我做的思路是:不使用数据库存储image的b ...

  7. ABAP-smartform-一页3列的条码打印

    1.自建barcode: se73->System bar code->change->create->new input the name of the bar code y ...

  8. WinForm条码打印

    在这篇博客中,我曾经介绍了如何实现条形码的生成(生成jpg格式的图片),这篇博客借用上面生成的条码,能够实现条形码的打印功能. 出于批量打印操作的方便以及操作体验考虑,我选择了WinForm.功能很简 ...

  9. ZPL条码打印类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

随机推荐

  1. 转:【Java集合源码剖析】TreeMap源码剖析

    前言 本文不打算延续前几篇的风格(对所有的源码加入注释),因为要理解透TreeMap的所有源码,对博主来说,确实需要耗费大量的时间和经历,目前看来不大可能有这么多时间的投入,故这里意在通过于阅读源码对 ...

  2. 集美大学网络1413第十三次作业成绩(团队八) -- 第二次项目冲刺(Beta阶段)

    题目: 团队作业8--第二次项目冲刺(Beta阶段) 团队作业8-成绩:  团队/分值 新加入成员 角色 技术特点 改善的功能. 原因. bug 新增功能. 方法. 如何实现 团队分工改进. 原因 改 ...

  3. 201521123107 《Java程序设计》第6周学习总结

    第6周作业-接口.内部类与Swing 1.本周学习总结 2.书面作业 1.clone方法 1.1 Object对象中的clone方法是被protected修饰,在自定义的类中覆盖clone方法时需要注 ...

  4. 201521123099 《Java程序设计》第3周学习总结

    1. 本周学习总结 2. 书面作业 1.代码阅读 public class Test1 { private int i = 1;//这行不能修改 private static int j = 2; p ...

  5. 201521123040《Java程序设计》第2周学习总结

    1. 本周学习总结 本周学习目录: <1>回顾(Java程序) <2>掌握各种数据类型的使用 <3>掌握运算符和表达式的使用 <4>枚举类.String ...

  6. 201521145048《Java程序设计》第13周学习总结

    1. 本周学习总结 以你喜欢的方式(思维导图.OneNote或其他)归纳总结多网络相关内容. 2. 书面作业 Q1. 网络基础 1.1 比较ping www.baidu.com与ping cec.jm ...

  7. JAVA课设 学生基本信息管理 团队博客

    1.成员 邹其元 网络1512 201521123060 杨钧宇 网络1512 201521123062 2.项目Git地址 团队项目码云地址 //添加截图 3. 项目git提交记录截图(要体现出每个 ...

  8. 201521123011 《java程序设计》 第9周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 2. 书面作业 本次PTA作业题集异常 1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己 ...

  9. python函数式编程,列表生成式

    1.python 中常见的集中存储数据的结构: 列表 集合 字典 元组 字符串 双队列 堆 其中最常见的就是列表,字典. 2.下面讲一些运用循环获取字典列表的元素 >>> dic={ ...

  10. java类成员变量与代码块初始化

    首先根据下面的这个一段代码:引入关于java初始化顺序的问题public class InitationTest extends Person { public InitationTest() { S ...