set BottomMargin with Footer Height

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
DanielM
Posts: 20
Joined: Thu Mar 27, 2025 5:31 pm

set BottomMargin with Footer Height

Post by DanielM »

srve.PageProperty.BottomMargin :=

Hi,

How can I set srve.PageProperty.BottomMargin with footer height?

procedure ApplyFooter(Vars: array of rVarS);
cousin
i, j: Integer;
Tables: TRVTableItemInfo;
CenteredParaNo, TabbedParaNo, NormalTextNo, NormalTextNo2: Integer;
// BoldTextNo, NormalParaNo, ColoredParaNo, RightParaNo, BigBoldTextNo: Integer;
RVStyle: TRVStyle;
Cell: TRVTableCellData;
RVData: TCustomRVData;
PItem: TRVPageNumberItemInfo;
sText: string;
begin
try
for j := 1 to 2 do
begin
if j = 1 then
begin
srve.SubDocuments[srvhftFirstPageFooter].Clear;
RVData := srve.SubDocuments[srvhftFirstPageFooter].GetRVData;
RVStyle := srve.SubDocuments[srvhftFirstPageFooter].GetRVStyle;
end
else
begin
srve.SubDocuments[srvhftNormalFooter].Clear;
RVData := srve.SubDocuments[srvhftNormalFooter].GetRVData;
RVStyle := srve.SubDocuments[srvhftNormalFooter].GetRVStyle; // RVData.GetRVStyle;
end;
// creating text and paragraph styles
// NormalParaNo := GetParaStyle(RVStyle, rvaLeft);
// RightParaNo := GetParaStyle(RVStyle, rvaRight);
// ColoredParaNo := GetParaStyle(RVStyle, rvaLeft, RVStyle.PixelsToUnits(0, 1), 0, $006CD9, clBlack);
CenteredParaNo := GetParaStyle(RVStyle, rvaCenter);
TabbedParaNo := GetParaStyle(RVStyle, rvaRight);
NormalTextNo := GetTextStyle(RVStyle, 8, [], clBlack, 'Georgia');
NormalTextNo2 := NormalTextNo;
if (j = 1) then
begin
RVData.AddTextNLW('', NormalTextNo, TabbedParaNo, TabbedParaNo);
end;

// making table 1 (logo | info)
Tables := TRVTableItemInfo.CreateEx(1, 2, RVData);
Table.ParaNo := CenteredParaNo;
Table.BorderWidth := 0;
Table.Color := clNone;
Table.BestWidth := -100;
Table.Cells[0, 0].BestWidth := -60;
Table.Cells[0, 1].BestWidth := -40;

Cell := Table.Cells[0, 1];
Cell.Clear;
Cell.VAlign := rvcTop;

Cell.AddTextNLW('Bank of Enterprising People', NormalTextNo, TabbedParaNo, TabbedParaNo);

Cell := Table.Cells[0, 0];
Cell.Clear;

TabbedParaNo := GetParaStyle(RVStyle, rvaLeft, 0, RVStyle.PixelsToUnits(0, 100));
for i := Low(Vars) to High(Vars) do
begin
sText := i.ToString+') '+ Vars.Value;
NormalTextNo := GetTextStyle(RVStyle, 8, GetStyle(sText), clBlack, 'Georgia');
Cell.AddTextNLW(sText, NormalTextNo, TabbedParaNo, TabbedParaNo);
end;
RVData.AddItem('', Table);


PItem := TRVPageNumberItemInfo.Create(RVData);
PItem.NumberType := rvpntDecimal;
PItem.ParaNo := CenteredParaNo;
PItem.TextStyleNo := NormalTextNo2;
RVData.AddItem('', PItem);

end;
serve.PageProperty.FooterY := 0.8;

srve.PageProperty.BottomMargin :=srve.RVFooter.Height ; //3.5;

serve.PageProperty.UpdatePageSize;

serve.RVFooter.Change;
if serve.RichViewEdit.Modified then
serve.RichViewEdit.Format;
Sergey Tkachenko
Site Admin
Posts: 18036
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: set BottomMargin with Footer Height

Post by Sergey Tkachenko »

Why do you want to do it?
ScaleRichView displays bottom margin large enough to include footer, even if PageProperty.BottomMargin is small (but the limit of 1/3 page height).
I.e.,

Code: Select all

visible_bottom_margin = max(
  PageProperty.BottomMargin, 
  min(PageProperty.FooterY + footer_height, PageProperty.PageHeight / 3)
 );
DanielM
Posts: 20
Joined: Thu Mar 27, 2025 5:31 pm

Re: set BottomMargin with Footer Height

Post by DanielM »

I use ScaleRichView as the non-visual component, if I manually set PageProperty.BottomMargin:= X Value, it displays correctly that X is set to a correct value, I approximate because I don't know what the Footer height is (work ok if I have 3..4 rows).

You said I have to use the formula: visible_bottom_margin = max(
PageProperty.BottomMargin,
min(PageProperty.FooterY + footer_height, PageProperty.PageHeight / 3)
);

the question is how do I find out what the value of footer_height is, no matter how many rows I add (ex: a number of 10 lines of text with a certain font/size set)
Sergey Tkachenko
Site Admin
Posts: 18036
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: set BottomMargin with Footer Height

Post by Sergey Tkachenko »

I mean, this is the formula used by ScaleRichView internally.

Does your footer has height greater than 1/3 of page height?
DanielM
Posts: 20
Joined: Thu Mar 27, 2025 5:31 pm

Re: set BottomMargin with Footer Height

Post by DanielM »

Hi,

No, it is not larger than 1/3.
The problem only occurs on the first page (only the first page) which also has a Header. When more lines are added to the Footer, the text in the document overlaps the text in the Footer, but only on the first page, on the rest of the pages the text in the document does not overlap the Footer.

It is possible that it is from the code that injects the Header, I am doing something wrong...

procedure ApplyHeader(Vars: array of rVarS);
var
i: Integer;
Table: TRVTableItemInfo;
Graphic: TGraphic;
CenteredParaNo, TabbedParaNo, NormalTextNo: Integer;
// NormalParaNo, ColoredParaNo, RightParaNo, BoldTextNo,BigBoldTextNo: Integer;
RVStyle: TRVStyle;
Cell: TRVTableCellData;
RVData: TCustomRVData;
begin
try
srve.SubDocuments[srvhftFirstPageHeader].Clear;
RVData := srve.SubDocuments[srvhftFirstPageHeader].GetRVData;
RVStyle := srve.SubDocuments[srvhftFirstPageHeader].GetRVStyle; // RVData.GetRVStyle;
// creating text and paragraph styles
CenteredParaNo := GetParaStyle(RVStyle, rvaLeft); // rvaCenter
NormalTextNo := GetTextStyle(RVStyle, 8, [], clBlack, 'Georgia');
// NormalParaNo := GetParaStyle(RVStyle, rvaLeft);
// RightParaNo := GetParaStyle(RVStyle, rvaRight);
// ColoredParaNo := GetParaStyle(RVStyle, rvaLeft, RVStyle.PixelsToUnits(0, 1), 0, $006CD9, clBlack);
// BoldTextNo := GetTextStyle(RVStyle, 10, [fsBold]);
// BigBoldTextNo := GetTextStyle(RVStyle, 14, [fsBold]);

// making table 1 (logo | info)
Tables := TRVTableItemInfo.CreateEx(1, 2, RVData);
Table.ParaNo := CenteredParaNo;
Table.BorderWidth := 0;
Table.Color := clNone;
Table.BestWidth := -100;
Table.Cells[0, 0].BestWidth := -60;
Table.Cells[0, 1].BestWidth := -40;

Cell := Table.Cells[0, 0];
Cell.Clear;
Cell.VAlign := rvcTop;

// (if loading was not successful, Graphic = nil)
if FileExists(sFileHeader) then
begin
Graphic := RVGraphicHandler.LoadFromFile(sFileHeader); // 'c:\temp\signalBT.png'
if Graphic <> nil then
Cell.AddPicture('', Graphic, CenteredParaNo, rvvaBaseline);
end
else
AddERROR('Missing graphic file Header: ' + sFileHeader);
// resizing the added picture by 1.2
// Cell.SetItemExtraIntProperty(Cell.ItemCount - 1, rvepImageWidth,
// RVStyle.PixelsToUnits(0,Round(RVStyle.PixelsToUnits(0,Graphic.Width) * 1.2)));
// Cell.SetItemExtraIntProperty(Cell.ItemCount - 1, rvepImageHeight,
// RVStyle.PixelsToUnits(0,Round(RVStyle.PixelsToUnits(0,Graphic.Height) * 1.2)));

Cell := Table.Cells[0, 1];
Cell.Clear;

TabbedParaNo := GetParaStyle(RVStyle, rvaLeft, 0, RVStyle.PixelsToUnits(0, 100));
for i := Low(Vars) to High(Vars) do
Cell.AddTextNL(Vars.Value, NormalTextNo, TabbedParaNo, TabbedParaNo);
RVData.AddItem('', Table);
serve.PageProperty.HeaderY:=1;
serve.PageProperty.TopMargin := 2.5;
if serve.RichViewEdit.Modified then
serve.RichViewEdit.Format;
exception
AddERROR('Error applying Hedear: ' + ExtractFileName(arrContainer_Used[q].FileOut));
end;
end;

firstpage.jpg
firstpage.jpg (14.64 KiB) Viewed 64 times
secondpge.jpg
secondpge.jpg (11.28 KiB) Viewed 64 times
Sergey Tkachenko
Site Admin
Posts: 18036
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: set BottomMargin with Footer Height

Post by Sergey Tkachenko »

Please send me a project (as simple as possible) reproducing this problem.
Post Reply