ESC P列印 程式控制印表機自動進退紙

2021-09-24 23:48:04 字數 3600 閱讀 1739

列印連續紙張的時候,經常會遇到需要自動進退紙的功能,譬如下列場景:

1. 列印完乙個小標;(自動進紙)

2. 使用者撕斷列印出來的小標;

3. (自動退紙,紙張歸位) 接著列印下乙個小標;

下列**在愛普生lq 730k印表機上測試通過:

1:

//使用示例

2:

new printdirect("printername").printesc(1);//列印後進紙

3:

new printdirect("printername").printesc(0);//列印前退紙

源**:

1:
2:     [structlayout(layoutkind.sequential)]
3:

public

struct docinfo

4:
12:
13:

public

class printdirect

14:
16:

public printdirect(string port)

17:
20:
21:         [dllimport("winspool.drv", charset = charset.unicode, exactspelling = false, callingconvention = callingconvention.stdcall)]
22:

public

static

extern

long openprinter(string pprintername, ref intptr phprinter, int pdefault);

23:
24:         [dllimport("winspool.drv", charset = charset.unicode, exactspelling = false, callingconvention = callingconvention.stdcall)]
25:

public

static

extern

long startdocprinter(intptr hprinter, int level, ref docinfo pdocinfo);

26:
27:         [dllimport("winspool.drv", charset = charset.unicode, exactspelling = true, callingconvention = callingconvention.stdcall)]
28:

public

static

extern

long startpageprinter(intptr hprinter);

29:
30:         [dllimport("winspool.drv", charset = charset.ansi, exactspelling = true, callingconvention = callingconvention.stdcall)]
31:

public

static

extern

long writeprinter(intptr hprinter, string data, int buf, ref

int pcwritten);

32:
33:         [dllimport("winspool.drv", charset = charset.unicode, exactspelling = true, callingconvention = callingconvention.stdcall)]
34:

public

static

extern

long endpageprinter(intptr hprinter);

35:
36:         [dllimport("winspool.drv", charset = charset.unicode, exactspelling = true, callingconvention = callingconvention.stdcall)]
37:

public

static

extern

long enddocprinter(intptr hprinter);

38:
39:         [dllimport("winspool.drv", charset = charset.unicode, exactspelling = true, callingconvention = callingconvention.stdcall)]
40:

public

static

extern

long closeprinter(intptr hprinter);

41:
42:

public

void printesc(int type)

43:         !", this.printport),
56:

"提示", messageboxbuttons.ok, messageboxicon.error);

57:

return;

58:                 }
59:                 printdirect.startdocprinter(lhprinter, 1, ref di);
60:                 printdirect.startpageprinter(lhprinter);
61:

string send = string.empty;

62:

for (int j = 0; j < 3; j++)

63:
79:

byte buf = new

byte[80];

80:

for (int i = 0; i < send.length; i++)

81:
84:                     printdirect.writeprinter(lhprinter, send, send.length, ref pcwritten);
85:                 }
86:             }
87:

catch (exception e)

88:
91:

finally

92:
99:             }
100:         }
101:     }

標籤:

esc/p,

列印,自動進紙,

自動退紙

ESC P列印 程式控制印表機自動進退紙

列印連續紙張的時候,經常會遇到需要自動進退紙的功能,譬如下列場景 1.列印完乙個小標 自動進紙 2.使用者撕斷列印出來的小標 3.自動退紙,紙張歸位 接著列印下乙個小標 下列 在愛普生lq 730k印表機上測試通過 1 使用示例2 new printdirect printername printe...

檢測印表機並於指定印表機上列印

1.自動檢測印表機 tprinter p printer tstringlist list new tstringlist list assign p printers 重點是這句 if list count 0 delete list else 2.在指定的印表機上列印報表 tprinter pr...

安裝印表機

如果是串列埠印表機一般先接印表機,然後再裝驅動程式,如果是 usb口的印表機一般先裝驅動程式再接印表機。一 印表機硬體安裝 實際上現在計算機硬體介面做得非常規範,你把印表機得資料線只有一端在計算機上能接,所以不會接錯。這個部分略。二 驅動程式安裝 如果驅動程式安裝盤是以可執行檔案方式提供,則最簡單直...