Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Corte de Papel en impresora (https://www.clubdelphi.com/foros/showthread.php?t=76900)

ethangio 02-12-2011 23:24:04

Corte de Papel en impresora
 
Hola buen dia a todos.

Llevo dias probando como realizar el corte de papel en una impresora Epson, la secuencia de corte es #27#109 pero no corta
al mandar la secuencia se impreme sus respectivos caracteres ascii .(27) m(109)

Ya he buscado en el foro a muchos dicen que siles funciona pero ami no :S ..

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var x, y: Integer;
begin
  Printer.BeginDoc;
  with Printer.Canvas do
  begin
    x := Printer.PageHeight div 50;
    y := Printer.PageWidth div 15;
    Font.Name:= 'tahoma';
    Font.Height:= x*2;
    Font.Color:= clblack;
    TextOut (x,y * 3, 'Prueba ...'+IntToStr(x)+'--'+IntToStr(y));
    x := x + 2;
    y := y + 2;
    TextOut(x, y, #27+#109); //corte de papel
  end;
  Printer.EndDoc;
end;

La impresora está esta dada de alta como Generica - Solo texto
Puede alguien darme una sugerencia de que hacer ???

Gracias

Casimiro Notevi 03-12-2011 09:50:30

Algunas impresoras tienen unos switchs para configurar que corte o que no corte, no sé si la tuya será de esas.

newtron 03-12-2011 10:33:29

Hola.

Igual estoy confundido pero creo que los caracteres de corte de la EPSON son #27+#i, o sea, #27+#105.

Saludos

CrazySoft 03-12-2011 11:30:26

Si no estoy mal no funciona con canvas
prueba de esta manera
Código Delphi [-]
var Impresora: TextFile;
 
Begin
            assignFile(Impresora,'LPT1');
 
//           o
//                       AssignPrn(Impresora);
 
            rewrite(Impresora); //apertura del archivo, creacion
            Write(Impresora, #27); //ESC, Write(Impresora, ESC);
            Write(Impresora, '!'); // ! , Write(Impresora, !);
            Write(Impresora, #0); //Write(Impresora, n); #n
            Writeln(Impresora, ' Prueba');
            CloseFile(Impresora); //cerrar el archivo
        except
            Showmessage('Error impresora');
        end;
End;

ethangio 05-12-2011 07:52:12

Hola disculpa la demora. Tuve que salir y no pude checar el foro antes

He estado probando con tu ejemplo CrazySoft ,, pero no me ha funcionado sigue sin cortar el papel
e imprimiendo los caracteres correspondientes al 27 y al 105 y/o 109

por cierto la impresora esta conectada por el puerto serial.

Tendras alguna otra solucion que nos pueda ayudar

Gracias, seguiré investigando.

newtron 05-12-2011 10:08:10

Hola.

No tengo impresora de tickets a mano para probar pero mira a ver si esto te sirve, tendrás que poner en el uses del formulario la unidad WinSpool.

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  DocInfo1: TDocInfo1;
  sLinea:   String;
  N:        DWORD;
  Handle:   THandle;
begin
  OpenPrinter('NombreImpresora', handle, nil);
  with DocInfo1 do begin
    pDocName    := PChar('prueba.doc');
    pOutputFile := nil;
    pDataType   := 'RAW';
  end;
  StartDocPrinter(Handle, 1, @DocInfo1);
  StartPagePrinter(Handle);
  sLinea := #27 + #105;
  WritePrinter(Handle, PChar(sLinea), Length(sLinea), N);
  EndPagePrinter(Handle);
  EndDocPrinter(Handle);
  ClosePrinter(Handle);
end;

Saludos

CrazySoft 06-12-2011 02:53:42

perdon se me fue el corte de papel
Código Delphi [-]
var Impresora: TextFile; 
Begin
        try
            assignFile(Impresora,'COM1');
            rewrite(Impresora); //apertura del archivo, creacion
                        Write(Impresora, #27); //ESC, Write(Impresora, ESC);
            Write(Impresora, '!'); // ! , Write(Impresora, !);
            Write(Impresora, #0); //Write(Impresora, n); #n
            Writeln(Impresora, ' Prueba');
            Write(Impresora, #27+#105); //corte de papel   ESC+i  o #27+(el valor ascii de i)
            CloseFile(Impresora); //cerrar el archivo
                 except
            Showmessage('Error impresora');
         end;
End;

ethangio 06-12-2011 04:44:51

No he podido conseguir que corte el papel, sigue imprime los caracteres ascii correspondientes ...
Miren encontré este ejemplo en el foro
enviandole como parametros, el nombre de la impresora ya sea local o en red y la cadena pero la cadena con la que corta es esta
\x1B@\x0A\x0D\x1Bi\x0A\x0D
.... Pero por que no quiere cortar con #27 # 109 o #105

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;

Dejo la liga por si alguien le sirve asi :
http://delphi.jmrds.com/?q=node/50

y este

http://www.clubdelphi.com/foros/showthread.php?t=54626

En el segundo esta el codigo ..


La franja horaria es GMT +2. Ahora son las 20:21:07.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi