刚刚在上一个问题中贴过这一答案了,怕各位看不到因此在贴一次。
让我们看一下来自Inprise的正宗回答吧。
Question and Answer Database
FAQ651D.txt Writting a raw string of data to the printer.
Category :Windows API
Platform :All
Product :All 32 bit
Question:
Howdo
I write a raw string of a data to the printer?
Answer:
Under Win16, you can use the SpoolFile function, or the
Passthrough escape if the printer supports it. This is detailed in
TI3196 - Direct Commands to Printer - Passthrough/Escape available
from the Borland web site. Under Win32, you should use WritePrinter.
The following is an example of opening a printer and writing a raw
string of data to the printer. Note that you must send the correct
printer name, such as "HP LaserJet 5MP" for the function to succeed.
You are also responsible for embedding any necessary control codes
that the printer may require.
uses WinSpool;
procedure WriteRawStringToPrinter(PrinterName:String;
S:String);
var
Handle: THandle;
N: DWORD;
do
cInfo1: TDocInfo1;
begin
if not OpenPrinter(PChar(PrinterName), Handle, nil) then
begin
ShowMessage('error ' + IntToStr(GetLastError));
Exit;
end;
withdo
cInfo1do
begin
pDocName := PChar('testdo
c');
pOutputFile := nil;
pDataType := 'RAW';
end;
StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(S), Length(S), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WriteRawStringToPrinter('HP', 'Test This');
end;