Get height of remaining space on page

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
wsigmund
Posts: 5
Joined: Wed Jun 07, 2017 7:59 am

Get height of remaining space on page

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17524
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Get height of remaining space on page

Post 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;
wsigmund
Posts: 5
Joined: Wed Jun 07, 2017 7:59 am

Re: Get height of remaining space on page

Post by wsigmund »

Thanks Sergey. Learning all the time.
Post Reply