Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 23-02-2012
Avatar de ethangio
ethangio ethangio is offline
Miembro
 
Registrado: jul 2008
Posts: 63
Poder: 16
ethangio Va por buen camino
imprimir en impresora de red

Buen dia,

Disculpen hace un tiempo abri un hilo ( aqui ) acerca de la impresion y las funciones son algo complejas, y pues no me quise quedar con esa espinita que no cortaba el papel y hacerlo por mi mismo,
ahora ya corta el papel cuando es la impresora esta local , pero en red no se como asignarle la impresora para mandar a imprimir, si mi impresora es de red o que tal si no esta en el com3 y esta en el com1 o com2 ....

Codigo:

Código Delphi [-]
var F : TextFile;
    i, j : integer;
    temp : string;
begin
     AssignFile(F, 'COM3'); // SI MI IMPRESORA ESTA EN RED ? O EN EL COM1, COM2 ?
     Rewrite(F);
     temp := 'hola 0';
     Writeln(F, temp);
     Writeln(F, #13+#10);
     Writeln(F, 'Hola linea 1');
     Writeln(F, #13+#10);
     Writeln(F, 'Hola despues del enter linea 2');
     Writeln(F, #13+#10);
     Writeln(F, #13+#10);
     Writeln(F, #13+#10);
     Writeln(F, #13+#10);//enter
     Writeln(F, #27+#109);//corte de papel
     CloseFile(F);
end;

ya probe con AssignPrm(F) pero con esto no corta la secuencia ni local ni en red aunque si imprime, si escribo directamente al puerto local (con AssignFile(F. 'COM3')) si corta ...

NOTA: Espero no haberlos enredado... saludos
Responder Con Cita
  #2  
Antiguo 23-02-2012
Avatar de newtron
[newtron] newtron is offline
Membrillo Premium
 
Registrado: abr 2007
Ubicación: Motril, Granada
Posts: 3.460
Poder: 20
newtron Va camino a la fama
Hola.

Me da que esa solución solo es viable en impresoras locales porque no creo que puedas acceder al puerto COM de un terminal de la red de esta manera. Para poder acceder a las impresoras en red deberías usar el objeto Printer.

Saludos
__________________
Be water my friend.
Responder Con Cita
  #3  
Antiguo 23-02-2012
Avatar de ethangio
ethangio ethangio is offline
Miembro
 
Registrado: jul 2008
Posts: 63
Poder: 16
ethangio Va por buen camino
Newtron pero entonces como mando la secuencia de corte ??

He probado estos ejemplos de codigo y no me sale .. Tengo en el Form 1 listview y 1 memo

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var F : TextFile;
    i, j : integer;
    temp : string;
begin
     //AssignFile(F, 'COM3'); //corta localmente e imprime
     AssignPrn(F); //solo imprime 
     Rewrite(F);

     // Ponemos título de las columnas
     temp := 'Columna1 Columna2 Columna3 Columna4 Columna5';
     Writeln(F, temp);
     Writeln(F,'Hola linea 1');
     Writeln(F,#13+#10);
     Writeln(F,'Hola despues del enter linea 2');
     Writeln(F,#13+#10);
     Writeln(F,#13+#10);
     Writeln(F,#13+#10);
     Writeln(F,#13+#10); // secuencia de enter
     Writeln(F,#27+#109); //secuencia de corte
     CloseFile(F);
end;

procedure TForm1.Button2Click(Sender: TObject);
var y, i, j : integer;
    temp : string;
begin
     Printer.BeginDoc;
     With Printer.canvas do
      Begin
           Printer.Title := 'El titulo del documento que quiero';
           Font.Name := 'MS Sans Serif';
           Font.Color := ClBlack;
           Pen.Color := ClBlack;
           Font.Size := 12;
           Font.Name := 'Times New Roman';
           Font.Size := 12;

           // imprimimos ListView
           temp := 'Titulo que sale escrito en el papel';
           y := 100;
           TextOut(10, y, temp);
           for i := 0 to ListView1.Items.Count - 1 do
            begin
                 inc(y, 20);
                 temp := ListView1.Items[i].Caption;
                 for j := 0 to ListView1.Items[i].SubItems.Count - 1 do
                     temp := temp + ' ' + ListView1.Items[i].SubItems[j];
                 TextOut(10, y, temp);
            end;
                 inc(y, 20);
                 TextOut(10, y, #27+#109);
      end;
     Printer.EndDoc;
end;

procedure TForm1.Button3Click(Sender: TObject);
var
  r: TRect;
  i: Integer;
begin
  with Printer do
    begin
      r := Rect(200,200,(Pagewidth - 200),(PageHeight - 200));
      BeginDoc;
      Canvas.Brush.Style := bsClear;
      for i := 0 to Memo1.Lines.Count do
      begin
       Canvas.TextOut(200,200 + (i *
                   Canvas.TextHeight(Memo1.Lines.Strings[i])),
                   Memo1.Lines.Strings[i]);
      end;

       Canvas.TextOut(200,200 + (9 *
                   Canvas.TextHeight(Memo1.Lines.Strings[9])),
                   #27+#109);

      Canvas.Brush.Color := clBlack;
      Canvas.FrameRect(r);
      EndDoc;
    end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var
Handle: THandle;
N: DWORD;
DocInfo1: TDocInfo1;
s : string;
begin
if not OpenPrinter(PChar('\\ethan-PC\caja'), Handle, nil) then begin
ShowMessage('Printer «\\ethan-PC\caja» not found.');
Exit;
end;

with DocInfo1 do begin
pDocName := PChar('Document Name');
pOutputFile := nil;
pDataType := 'RAW';
end;

StartDocPrinter(Handle, 1, @DocInfo1);

s := 'First line of first page' + #13+#10;
WritePrinter(Handle, PChar(s), Length(s), N);
s := 'Second line of first page' + #13+#10;
WritePrinter(Handle, PChar(s), Length(s), N);
s := #27+#109;
WritePrinter(Handle, PChar(s), Length(s), N);

EndPagePrinter(Handle);

{s := 'First line of second page' + #13#10;
WritePrinter(Handle, PChar(s), Length(s), N);
s := 'Second line of second page' + #13#10;
WritePrinter(Handle, PChar(s), Length(s), N);
}
EndPagePrinter(Handle);

EndDocPrinter(Handle);

ClosePrinter(Handle);
end;

procedure TForm1.Button5Click(Sender: TObject);
var
  PrinterHandle: THandle;
  DocInfo: TDocInfo1;
  i: Integer;
  B: Byte;
  Escritos: DWORD;
  Str : String;
begin
  Str:='linea 1 ,,, '+#13+#10+'linea 2...'+#27+#109;
  if OpenPrinter(PChar('\\ethan-PC\caja'), 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;
      finally
        EndPagePrinter(PrinterHandle);
      end;
    finally
      EndDocPrinter(PrinterHandle);
    end;
  finally
    ClosePrinter(PrinterHandle);
  end;
end;

jeje son mis ejemplos para imprimir .. Saludos

Newtron hay forma de saber por medio del nombre de la impresora local en que puerto esta conectada ???
Responder Con Cita
  #4  
Antiguo 24-02-2012
Avatar de newtron
[newtron] newtron is offline
Membrillo Premium
 
Registrado: abr 2007
Ubicación: Motril, Granada
Posts: 3.460
Poder: 20
newtron Va camino a la fama
A ver....

Te pongo un ejemplo de una utilidad para abrir el cajón portamonedas, el corte de papel es exactamente igual solo poniendo los caracteres correspondientes. Lo he simplificado un poco para que te sea más legible.

Código Delphi [-]
// ****************************************************************************
// Rutina      : AbreElCajon
// Descripcion :
// ****************************************************************************
procedure AbreElCajon(var Impreso: TImpreso);

  function CreaLinea: String;
  var
    sAux: String;
  begin

    Result := '';

    sAux := Trim(DlgPropiedades.ComandoAperturaCajon);
    while Pos(' ', sAux) > 0 do begin

      try
        Result := Result + Chr(StrToInt(Copy(sAux, 1, Pos(' ', sAux)-1)));
      except

      end;

      sAux := TrimLeft(Copy(sAux, Pos(' ', sAux)+1, Length(sAux)));

    end;

    try
      Result := Result + Chr(StrToInt(sAux));
    except

    end;

  end;

var
  DocInfo1: TDocInfo1;
  Handle:   THandle;
  Linea:    String;
  N:        DWORD;
begin

    if not OpenPrinter(PChar(Printer.Printers[Impreso.Impresora]), Handle, nil) then begin
      ShowMessage('Error en OpenPrinter : ' + Printer.Printers[Impreso.Impresora]);
      Exit;
    end;

  end;

  with DocInfo1 do begin
    pDocName    := PChar(Impreso.Nombre);
    pOutputFile := nil;
    pDataType   := 'RAW';
  end;

  StartDocPrinter(Handle, 1, @DocInfo1);

  StartPagePrinter(Handle);

//  Linea := #27 + #112 + #0 + #127 + #127;
  Linea := CreaLinea;
  WritePrinter(Handle, PChar(Linea), Length(Linea), N);

  EndPagePrinter(Handle);

  EndDocPrinter(Handle);

  ClosePrinter(Handle);

end;

Espero que te ayude.

Saludos
__________________
Be water my friend.
Responder Con Cita
  #5  
Antiguo 24-02-2012
josemiguelbvs josemiguelbvs is offline
Registrado
NULL
 
Registrado: oct 2011
Posts: 4
Poder: 0
josemiguelbvs Va por buen camino
Thumbs up Mas simple de lo que parece.

Con este sencillo ejemplo deberia funcionar en Red. Con cualquier tipo de puerto (Usb, Ethernet, LPT, o COM). Yo lo uso hace anos sin ningun problema.

La unica salvedad es que debera estar compartida tu impresora. Y luego usar una asignacion en formato UNC para imprimir.

Port := '\\Server\Impresora'; // Server=Nombre del equipo donde se conecta la impresora. Impresora=Nombre de la impresora compartida.


Port := '\\Server\Impresora';
AssignFile(MyFile, Port);
try
Rewrite(MyFile);
except
ShowMessage( 'Impresora conectada en puerto: ' + Port + '. No funciona.');
end;

Write(MyFile, Chr(27) + chr(64)); // reseteo impresora;
...
...

Writeln(MyFile, 'Imprimo algo...' );
...
...

Write(MyFile, chr(29) + chr(86)+ chr(49)); // Corta Papel


Espero, te sirva.

Saludos

Jose Miguel Bakulic V.
Responder Con Cita
  #6  
Antiguo 24-02-2012
Avatar de ethangio
ethangio ethangio is offline
Miembro
 
Registrado: jul 2008
Posts: 63
Poder: 16
ethangio Va por buen camino
GRACIAS NEWTRON , JOSEMIGUELBVS ..

Voy a hacer algunas pruebas --- Gracias nuevamente ...
Responder Con Cita
  #7  
Antiguo 29-02-2012
Avatar de ethangio
ethangio ethangio is offline
Miembro
 
Registrado: jul 2008
Posts: 63
Poder: 16
ethangio Va por buen camino
Lamento responder hasta ahorita pero desde el dia de la respuesta ya no tengo donde hacer pruebas de corte de papel, me iban a prestar otra pero no se cuando , confio en que sus soluciones que me proporcionaron funcionan .. --- Y regresaba a agradecerles por su ayuda ...

GRACIAS !!

En cuanto tenga donde hacer pruebas y heche andar ese codigo les comento ... GRACIAS nuevamente ...
Responder Con Cita
  #8  
Antiguo 29-02-2012
Avatar de MAXIUM
MAXIUM MAXIUM is offline
Miembro
 
Registrado: may 2005
Posts: 1.488
Poder: 20
MAXIUM Va camino a la fama
Si lo anterior no sirve, proba un código en CMD primero:

net use LPT1 \\servidor\Okidata /persistent:yes

aunque en tu caso debiera resultar esto otro

net use COM3 \\servidor\Okidata /persistent:yes

Nota: Okidata es el nombre del recurso, es decir, el nombre la impresora. En tu caso debiera ser distinto.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Imprimir con una impresora que no es la predeterminada principiante22 Varios 3 20-11-2008 11:37:25
Error al imprimir en impresora en red santiago14 Impresión 1 04-10-2007 14:52:27
Imprimir en impresora remota jlrbotella API de Windows 1 12-06-2007 23:48:19
Imprimir en impresora Virtual Alexander Impresión 2 23-11-2006 14:32:41
Imprimir directamente en la impresora? danytorres Impresión 1 12-01-2004 21:23:07


La franja horaria es GMT +2. Ahora son las 17:41:14.


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
Copyright 1996-2007 Club Delphi