Page 1 of 1
How to get the PrintAreaRect from a RVPrint
Posted: Thu Aug 30, 2012 8:19 am
by DaleC
Hi there,
I use a TRVPrint on a form, and I would like to get the PrintAreaRect (to get the print area height and the print area width).
I don't want to use a preview or somthing visual.
Is there a RVPrint.GetPrintArea or somthing equivalent ?
Thanks in advance
DaleC
Posted: Thu Aug 30, 2012 9:21 am
by Sergey Tkachenko
Do you mean page size excluding margins, in printer pixels?
Code: Select all
procedure GetPageSize(RVPrint: TRVPrint;
var Width, Height: Integer);
var DC: HDC;
phoX, phoY, phW, phH, lpy, lpx, LM, TM, RM, BM: Integer;
begin
DC := RV_GetPrinterDC; // from PtblRV unit
Width := GetDeviceCaps(DC, HORZRES);
Height := GetDeviceCaps(DC, VERTRES);
lpy := GetDeviceCaps(DC, LOGPIXELSY);
lpx := GetDeviceCaps(DC, LOGPIXELSX);
phoX := GetDeviceCaps(DC, PHYSICALOFFSETX);
phoY := GetDeviceCaps(DC, PHYSICALOFFSETY);
phW := GetDeviceCaps(DC, PHYSICALWIDTH);
phH := GetDeviceCaps(DC, PHYSICALHEIGHT);
LM := MulDiv(RVPrint.LeftMarginMM, 5*lpx, 127)- phoX;
TM := MulDiv(RVPrint.TopMarginMM, 5*lpy, 127)- phoY;
RM := MulDiv(RVPrint.RightMarginMM, 5*lpx, 127)- (phW-(phoX+Width));
BM := MulDiv(RVPrint.BottomMarginMM, 5*lpy, 127)- (phH-(phoY+Height));
if LM<0 then LM := 0;
if TM<0 then TM := 0;
if RM<0 then RM := 0;
if BM<0 then BM := 0;
dec(Width, LM+RM);
dec(Height, TM+BM);
DeleteDC(DC);
end;
Posted: Thu Aug 30, 2012 10:29 am
by DaleC
In fact, I want to get the PrintAreaRect.
When you use the RVPrint.OnPrePaint event, one parameter is PrintAreaRect.. I don't know how it is calculated, but values are differents than the "GetPageSize" example procedure.
I need to find (calculate) this PrintAreaRect to use somewhere else, but I don't know how to get it. (I don't want to use the event).
Any idea ?
thanx
DaleC
Posted: Sat Sep 01, 2012 12:33 pm
by Sergey Tkachenko
I cannot reproduce the case of different values.
My tests.
I used the demo in Demos\Delphi\Editors\Editor 1\
I added the menu item:
Code: Select all
procedure TForm1.ss1Click(Sender: TObject);
var Width, Height: Integer;
begin
GetPageSize(RVPrint1, Width, Height);
Caption := 'Calculated: '+IntToStr(Width)+','+IntToStr(Height);
end;
Also, I processed OnPagePostpaint event:
Code: Select all
procedure TForm1.RVPrint1PagePostpaint(Sender: TRVPrint; PageNo: Integer;
Canvas: TCanvas; Preview: Boolean; PageRect, PrintAreaRect: TRect);
begin
Caption := 'From event: '+IntToStr(PrintAreaRect.Right-PrintAreaRect.Left)+','+
IntToStr(PrintAreaRect.Bottom-PrintAreaRect.Top);
end;
In the both cases, the same values are shown on the form caption: 4017,6072
Posted: Sat Sep 01, 2012 12:38 pm
by Sergey Tkachenko
Code: Select all
function GetPrintAreaRect(RVPrint: TRVPrint): TRect;
var DC: HDC;
phoX, phoY, phW, phH, lpy, lpx, LM, TM, RM, BM, Width, Height: Integer;
begin
DC := RV_GetPrinterDC; // from PtblRV unit
Width := GetDeviceCaps(DC, HORZRES);
Height := GetDeviceCaps(DC, VERTRES);
lpy := GetDeviceCaps(DC, LOGPIXELSY);
lpx := GetDeviceCaps(DC, LOGPIXELSX);
phoX := GetDeviceCaps(DC, PHYSICALOFFSETX);
phoY := GetDeviceCaps(DC, PHYSICALOFFSETY);
phW := GetDeviceCaps(DC, PHYSICALWIDTH);
phH := GetDeviceCaps(DC, PHYSICALHEIGHT);
LM := MulDiv(RVPrint.LeftMarginMM, 5*lpx, 127)- phoX;
TM := MulDiv(RVPrint.TopMarginMM, 5*lpy, 127)- phoY;
RM := MulDiv(RVPrint.RightMarginMM, 5*lpx, 127)- (phW-(phoX+Width));
BM := MulDiv(RVPrint.BottomMarginMM, 5*lpy, 127)- (phH-(phoY+Height));
if LM<0 then LM := 0;
if TM<0 then TM := 0;
if RM<0 then RM := 0;
if BM<0 then BM := 0;
dec(Width, LM+RM);
dec(Height, TM+BM);
Result := Bounds(LM, TM, Width, Height);
DeleteDC(DC);
end;