set BottomMargin with Footer Height

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
DanielM
Posts: 22
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: 18038
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: 22
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: 18038
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: 22
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 378 times
secondpge.jpg
secondpge.jpg (11.28 KiB) Viewed 378 times
Sergey Tkachenko
Site Admin
Posts: 18038
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.
DanielM
Posts: 22
Joined: Thu Mar 27, 2025 5:31 pm

Re: set BottomMargin with Footer Height

Post by DanielM »

Hi,

Hi,

It is difficult to make a simple example code, I should give you the whole project and another one with which the project is called, parses its parameters and triggers the generation of documents, I have no problem giving it all, but your time is limited and I can't abuse it.

I am trying to solve the problem in another way, can you guide me with the question below?

If I have a Header/Footer with a table (x Row, Y Col), in which I have one or more "variables", how can I search for the variable to replace it with a specific text or, if necessary, insert an image?

I should be able to do it even if I have a single Header/Footer or more. Any example is welcome.

e.g. variables \A\ or \IMAGE1\.
I will also attach some pictures with examples of how the Header/Footer looks in the template.
Header.jpg
Header.jpg (16.57 KiB) Viewed 282 times
FOOTER.jpg
FOOTER.jpg (15.79 KiB) Viewed 282 times
DanielM
Posts: 22
Joined: Thu Mar 27, 2025 5:31 pm

Re: set BottomMargin with Footer Height

Post by DanielM »

Hi,

I think I found a solution to the Header/Footer variable pop-up, but on the first page the text in the main overlaps the one in the footer. Somehow the text on the first page does not adjust to the height, the rest of the pages are rendered correctly. If after injecting the footer I set a value for srve.PageProperty.BottomMargin:= X the height of the main is adjusted, but I don't know how to calculate the X value based on the height of the Footer. I'll keep looking and if I don't succeed I'll make a small example to send you.
Sergey Tkachenko
Site Admin
Posts: 18038
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: set BottomMargin with Footer Height

Post by Sergey Tkachenko »

Try to reformat the editor not as SRichViewEdit.RichViewEdit.Format, but as SRichViewEdit.Format.
Post Reply