Page 1 of 1

Get height of remaining space on page

Posted: Wed Jun 21, 2017 4:47 pm
by wsigmund
I want to find the height in pixels of the space remaining on the page after the last item was added (so I can add and resize an image to fit into the remaining space).

I'm unable to find anything in the help or forums relating to 'current y pos' etc. I'm sure this has been done before now.

Any help is greatly appreciated.

Re: Get height of remaining space on page

Posted: Fri Jun 23, 2017 4:28 pm
by Sergey Tkachenko

Code: Select all

function GetFreeSpaceAtTheEndOfPage(srv: TSRichViewEdit; PageNo: Integer): Integer;
var
  ItemNo, Offs, Part, PageNo1, PageNo2: Integer;
  rve: TCustomRichViewEdit;
  R: TRect;
begin
  Result := 0;
  if (PageNo < 1) or (PageNo > srv.PageCount) then
    exit;
  rve := srv.RichViewEdit;
  // getting the last item on the page
  srv.GetPageLastItemNo(PageNo, ItemNo, Offs);
  // if this is a middle of a table, returing 0
  if (rve.GetItem(ItemNo) is TRVTableItemInfo) and
    (Offs < TRVTableItemInfo(rve.GetItem(ItemNo)).RowCount - 1) then
    exit;
  // finding the bottom coordinates of the last item on the page, storing in Result
  Part := 0;
  R := Rect(0, 0, 0, 0);
  while srv.GetItemBounds100(rve.RVData, ItemNo, R, PageNo1, PageNo2, Part, False) do
  begin
    if PageNo2 > PageNo then
      break;
    Result := R.Bottom;
    inc(Part);
  end;
  // Calculating the space till the end of page
  Result := srv.GetPageHeight100Pix(PageNo) - srv.GetBottomMargin100Pix(PageNo) -
     Result;
end;

Re: Get height of remaining space on page

Posted: Sun Jun 25, 2017 10:09 pm
by wsigmund
Thanks Sergey. Learning all the time.