没问题,刚刚测试以后贴上来!
var
PrinterHandle:THandle;
uses WinSpool, Printers;
type TDocInfo1=packed record
lpszDocName: PAnsiChar;
lpszOutputFile: PAnsiChar;
lpszDatatype: PAnsiChar;
end;
*设置模块*
var
CTitle:array[0..31] of Char;
CMode:array[0..4] of Char;
do
cInfo:TDocInfo1;
begin
StrPLopy(CTitle, 'My Title');
StrPCopy(CMode, 'RAW');
FillChar(DocInfo, SizeOf(DocInfo), 0);
withdo
cInfodo
begin
lpszDocName:=CTitle;
//设置打印文档标题
lpszOutputFile:=nil;
lpszDatatype:=CMode;
end;
OpenPrinter('Printer Name Here', PrinterHandle, nil);
StartDocPrinter(PrinterHandle, 1, @DocInfo);
StartPagePrinter(PrinterHandle);
*打印模块*
var
Count
Word;
begin
WritePrinter(PrinterHandle, PChar(printText), Length(printText),
Count);
EndPagePrinter(PrinterHandle);
//结束当页
EndDocPrinter(PrinterHandle);
//结束文档
if PrinterHandle<>0 then
begin
ClosePrinter(PrinterHandle);
//关闭打印设备
PrinterHandle:=0;
//关闭设备通知
end;