uses winapi.WinSpool, Printers;
procedure TForm5.Button1Click(Sender: TObject);
begin
TextToPrinter(Printer.Printers[Printer.PrinterIndex], '
Mein Text');
end;
procedure TForm5.TextToPrinter(Drucker, TextToPrint:
String);
var pHandle: THandle; DocInfo1: TDocInfo1; N: DWORD;
begin
DocInfo1.pDocName:=PChar('
MeinDokumentname');
DocInfo1.pOutputFile:=nil;
DocInfo1.pDataType:='
RAW';
if not OpenPrinter(PChar(Drucker), pHandle,
NIL)
then raise Exception.Create(SysErrorMessage(GetLastError));
if StartDocPrinter(pHandle, 1, @DocInfo1)=0
then raise Exception.Create(SysErrorMessage(GetLastError));
if not StartPagePrinter(pHandle)
then raise Exception.Create(SysErrorMessage(GetLastError));
if not WritePrinter(pHandle, PChar(TextToPrint), Length(TextToPrint), N)
then raise Exception.Create(SysErrorMessage(GetLastError));
if not WritePrinter(pHandle, PChar(#12#13), 2, N)
then raise Exception.Create(SysErrorMessage(GetLastError));
if not EndPagePrinter(pHandle)
then raise Exception.Create(SysErrorMessage(GetLastError));
if not EndDocPrinter(pHandle)
then raise Exception.Create(SysErrorMessage(GetLastError));
if not ClosePrinter(pHandle)
then raise Exception.Create(SysErrorMessage(GetLastError));
end;