Board index » delphi » RTF and Margins

RTF and Margins

Hi,
I have a RTF file and want to print it, so I used :

RTF.Lines.LoadFromFile('FILE.RTF');
R.Left:=300;
R.Top:=600;
R.Right:=300;
R.Bottom:=300;
RTF.PageRect:=R;
RTF.Print;

My printer has 600dpi,  but the property PageRect simply doesn't work and no
margins are respected.
How can I do to leave at least 1/2 inch of margin.

Thanks,
Donis.

 

Re:RTF and Margins


Quote
In article <3b4c4725_2@dnews>, Donis wrote:
> I have a RTF file and want to print it, so I used :

> RTF.Lines.LoadFromFile('FILE.RTF');
> R.Left:=300;
> R.Top:=600;
> R.Right:=300;
> R.Bottom:=300;
> RTF.PageRect:=R;
> RTF.Print;

> My printer has 600dpi,  but the property PageRect simply doesn't work and no
> margins are respected.

You are using it wrong, that is all. The PageRect specifies the rectangle to
print in, not the margins.

procedure TForm1.Button1Click(Sender: TObject);
 var
   presX, presY: Integer;
   r: TRect;
 Begin
   with richedit1 do begin
     plaintext := true;
     lines.loadfromfile( changefileext( application.exename, '.DPR' ));
   end;
   presX := GetDeviceCaps( printer.handle, LOGPIXELSX );
   presY := GetDeviceCaps( printer.handle, LOGPIXELSY );
   with r do begin
     left := presX;  // 1 inch left margin
     top  := 3 * presY div 2;  //  1.5 inch top margin
     right := Printer.PageWidth - 3 * presX div 4; // 0.75 inch right margin
     bottom := Printer.PageHeight - presY; // 1 inch bottom margin
   end;
   with richedit1 do begin
     Pagerect := r;
     Print('Testjob');
   end;
 End;
end.

Note that the margins in the example are relative to the printable area
of the page, not the physical page. To correct for the nonprintable
margin use GetDeviceCaps with PHYSICALOFFSETX and PHYSICALOFFSETY (this
tells you how far the page coordinate system has been shifted left and
down by Delphi to put the origin at the upper left corner of the
printable area) and PHYSICALWIDTH and PHYSICALHEIGHT to get the paper
size in device units.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads