• 0
Sign in to follow this  

Usando o PageSetupDialog para imprimir um RichEdit


Usando o PageSetupDialog1 para definir as margens do RichEdit para impressão

uses Printers;

(* Setar as margens do RichEdit em Polegadas (1 polegada = 2.54 cm)
    para a impressora ativa *)
procedure SetRichEditMargins(
   const mLeft, mRight,
         mTop, mBottom: extended;
   const re : TRichEdit);
   ppiX, ppiY : integer;
   spaceLeft, spaceTop : integer;
   r : TRect;
   // pixels por polegadas
   ppiX := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
   ppiY := GetDeviceCaps(Printer.Handle, LOGPIXELSY);

   // não imprimir margens
   spaceLeft := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
   spaceTop := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);

   //calcular as margens
   R.Left := Round(ppiX * mLeft) - spaceLeft;
   R.Right := Printer.PageWidth - Round(ppiX * mRight) - spaceLeft;
   R.Top := Round(ppiY * mTop) - spaceTop;
   R.Bottom := Printer.PageHeight - Round(ppiY * mBottom) - spaceTop;

   // setar as margens
   re.PageRect := r;

procedure TForm1.Button1Click(Sender: TObject);
var MEsq, MDir, MSup, MInf : real;
   {Estilo = RETRATO
   Margem Esquerda = 25
   Margem Direita = 20
   Margem Superior = 20
   Margem Inferior = 20}

   if PageSetupDialog1.Execute then

         Printer.Orientation := poPortrait; // vertical

         MEsq := (PageSetupDialog1.MarginLeft / 2.54)/1000;
         MDir := (PageSetupDialog1.MarginRight / 2.54)/1000;
         MSup := (PageSetupDialog1.MarginTop  / 2.54)/1000;
         MInf := (PageSetupDialog1.MarginBottom / 2.54)/1000;

         SetRichEditMargins(MEsq, MDir, MSup, MInf, richEdit1);
         richEdit1.Print('Printing with margins');


Share this post

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this