Vamos a ver, esta función te puede útil:
Código Delphi
[-]
function WriteRawDataToPrinter(PrinterName: String; Str: String): Boolean;
var
PrinterHandle: THandle;
DocInfo: TDocInfo1;
i: Integer;
B: Byte;
Escritos: DWORD;
begin
Result:= FALSE;
if OpenPrinter(PChar(PrinterName), PrinterHandle, nil) then
try
FillChar(DocInfo,Sizeof(DocInfo),#0);
with DocInfo do
begin
pDocName:= PChar('Printer Test');
pOutputFile:= nil;
pDataType:= 'RAW';
end;
if StartDocPrinter(PrinterHandle, 1, @DocInfo) <> 0 then
try
if StartPagePrinter(PrinterHandle) then
try
while Length(Str) > 0 do
begin
if Copy(Str, 1, 1) = '\' then
begin
if Uppercase(Copy(Str, 2, 1)) = 'X' then
Str[2]:= '$';
if not TryStrToInt(Copy(Str, 2, 3),i) then
Exit;
B:= Byte(i);
Delete(Str, 1, 3);
end else B:= Byte(Str[1]);
Delete(Str,1,1);
WritePrinter(PrinterHandle, @B, 1, Escritos);
end;
Result:= TRUE;
finally
EndPagePrinter(PrinterHandle);
end;
finally
EndDocPrinter(PrinterHandle);
end;
finally
ClosePrinter(PrinterHandle);
end;
end;
Permite enviar datos directamente a la impresora, al igual que lo hacías antes a través del puerto paralelo, solo necesitas el nombre de la impresora. Si le echas un vistazo a la función seguro que averiguas como funciona y la puedes adaptar a tus necesidades, pero si te decides a utilizarla tal cual, el primer parámetro es el nombre de la impresora (tal cual aparece en la carpeta "Impresoras" de windows) y el segundo es el texto que se quiere enviar, con la particularidad que se pueden mandar secuencias de escape.
Por ejemplo, así mandaríamos el texto "Hola mundo":
Código Delphi
[-]
WriteRawDataToPrinter('Mi impresora','Hola mundo');
Ahora lo mismo pero con un retorno de carro y avance de linea:
Código Delphi
[-]
WriteRawDataToPrinter('Mi impresora','Hola mundo\x0D\x0A');
Y ahora un pitido (si la impresora lo soporta)
Código Delphi
[-]
WriteRawDataToPrinter('Mi impresora','Hola mundo\x0D\x0A\x1B\007');
Estos días estoy probando unas nuevas impresoras de toshiba, de las que no acabo de encontrar sus secuencias de escape (logo, negrita, subrayado, etc ...). Así que me he creado una pequeña aplicación, donde puede escoger una impresora y mandarle una secuencia de escape, y así realizar algunas pruebas. Aquí te la dejo por si quieres hacer algunas pruebas: