Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Impresión (https://www.clubdelphi.com/foros/forumdisplay.php?f=4)
-   -   Imprimir un formulario! AYUDA POR FA! (https://www.clubdelphi.com/foros/showthread.php?t=52172)

mtirado 12-01-2008 16:27:31

Imprimir un formulario! AYUDA POR FA!
 
Hola a todos.
Escribo pues en realidad nunca me ha hecho falta imprimir un formulario o algo por el estilo.
El hecho es que necesito imprimir unos datos en una medida en especifico. Por ejemplo, dado un cliente buscar sus datos, los productos que ha comprado e imprimir esos datos como una especie de tique o comprobante. Este comprobante debe tener una medida en especifico, de 75 mm por 75 mm, he logrado imprimir pero no con esa medida. No se como trabajar con la escala, ahh trabajo directamente con el Printers no utilizo ningun sistema de reporte. POr favor si alguien me ayuda.
Muchas gracias.
Aca va el ejemplo en code.
Printer.Canvas.TextOut(90, 90, LbComprobanteTexto.Caption);
Tambien tengo que imrpimir un StringGrid donde muestro los pedidos del cliente.
Pero todo debe caber en esas medidas de 75 por 75 mm.
Espero puedana yudarme.
Muchas gracias.

salvica 14-01-2008 16:42:34

Hola mtirado, hace tiempo hice una aplicación para imprimir imágenes que recibía vía FTP (en horizontal o vertical) y las copiaba directamente en el canvas de la impresora, no se si te servirá pero te paso el código.
Código Delphi [-]
{
  al pulsar en el menú IMPRIMIR
}
procedure TWin_Main.mnuImprimir_OnClick(Sender: TObject);
var
//  Impresora      : TPrinter;
  tmpTImage      : TImage;
  tmpGifImagen   : TGIFImage;
  tmpRotateImage : TRotateImage;
  tmpBitMapRotado: TBitMap;
  newArea        : TRect;
  FILE_PRINTER   : string;
  estaHorizontal : boolean;
  estaVertical   : boolean;
begin
{ crear una copia de la imágen original y guardarla como "PRINTER.BMP" }
  FILE_PRINTER   := ExtractFilePath( FILE_COPY ) + 'PRINTER';
  estaHorizontal := false;
  estaVertical   := false;
  tmpGifImagen   := TGIFImage.Create;
  try
    tmpGifImagen.LoadFromFile( FILE_COPY+'.GIF' );
    tmpGifImagen.Frames[0].Bitmap.SaveToFile( FILE_PRINTER+'.BMP' );
    if( tmpGifImagen.Frames[0].Bitmap.Width>tmpGifImagen.Frames[0].Bitmap.Height )
        then estaHorizontal := true
        else estaVertical   := true;
  finally
    tmpGifImagen.Free;
  end;
{ crear un TImage para trabajar con la copia creada }
  tmpTImage      := TImage.Create( nil );
  with tmpTImage do begin
       Visible  := false;
       Parent   := Win_Main;
       AutoSize := true;
       Center   := false;
       Stretch  := false;
  end;
  try
    tmpTImage.Picture.Bitmap.LoadFromFile( FILE_PRINTER+'.BMP' );
    tmpTImage.Refresh;
    if( tmpTImage.Width>tmpTImage.Height ) then begin
        tmpRotateImage := TRotateImage.Create(nil);
        try
          with tmpRotateImage do begin
               UniqueSize := false;
               Picture.LoadFromFile( FILE_PRINTER+'.BMP' );
               Angle := -90;
               RotatedBitmap.SaveToFile(FILE_PRINTER+'.BMP');
          end;
        finally
          tmpRotateImage.Free;
        end;
    end;
  finally
    tmpTImage.Free;
  end;
{ rotar la imágen en "vertical" (si hace falta) }
  {
  if( estaHorizontal and (Printer.PageHeight>Printer.PageWidth) ) or
    ( estaVertical   and (Printer.PageWidth>Printer.PageHeight) ) then begin
      tmpRotateImage := TRotateImage.Create(nil);
      try
        with tmpRotateImage do begin
             UniqueSize := false;
             Picture.LoadFromFile( FILE_PRINTER+'.BMP' );
             if( Picture.Bitmap.Width>Printer.PageWidth ) then begin
                 Angle := -90;
                 RotatedBitmap.SaveToFile(FILE_PRINTER+'.BMP');
             end;
        end;
      finally
        tmpRotateImage.Free;
        Image.Picture.LoadFromFile( FILE_PRINTER+'.BMP' );
      end;
  end;
  }
  tmpBitMapRotado:= TBitMap.Create;
  try
    tmpBitMapRotado.LoadFromFile( FILE_PRINTER+'.BMP' );
    with Printer do begin
         Title := 'MAPA '+ExtractFileName( FILE_COPY )+' correspondiente al '+FechaToCadena( Now, true );
         if( tmpBitMapRotado.Width>tmpBitMapRotado.Height ) then begin
           { orientación horizontal, girar el mapa }
             Orientation := poLandscape;
         end else begin
           { orientación vertical }
             Orientation := poPortrait;
         end;
         with newArea do begin
              Left   := 100;
              Top    := 100;
              Right  := PageWidth  - 200;
              Bottom := PageHeight - 200;
         end;
         BeginDoc;
         Canvas.StretchDraw( newArea, tmpBitMapRotado );
         Canvas.TextOut( 50, 10, Title );
         EndDoc;
    end;
  finally
    tmpBitMapRotado.Free;
  end;
{ eliminar la copia de la imágen original y desactivar el menú "IMPRIMIR" }
  if FileExists( FILE_PRINTER+'.BMP' ) then DeleteFile( FILE_PRINTER+'.BMP' );
  mnuImprimir.Enabled := false;
end;
La imágen podía tener cualquier tamaño. La parte que te interesa está al final, donde ajusto la imagen al tamaño del paper (DIN-A4)

Saludos
salvica


La franja horaria es GMT +2. Ahora son las 13:50: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