Page 1 of 1

text at specific position

Posted: Thu May 09, 2024 6:32 am
by sorega2022
hi,

i am searching the right command to put a text or pic at a specific position on a page. i want to do that with x and y coordinates in cm or mm.
i found only tables. but tables begin at top of page and it would be very uncomfortable to work with it.

how can i do that. do you have a sample for me please?

Re: text at specific position

Posted: Fri May 10, 2024 8:34 am
by Sergey Tkachenko
If you need to place many text strings, I suggest using tables.
If you need to place one or several text strings, you can use text boxes.

This code inserts a text in a text box at the specified position X, Y measured in mm. The inserted text has the specified width (in mm); if it is longer, it is wrapped.

Code: Select all

uses RVSideNote, RVFloatingPos, RVFloatingBox;

procedure InsertTextAt(Edit: TCustomRichViewEdit; Xmm, Ymm, Widthmm: Integer;
  const Text: TRVUnicodeString; StyleNo, ParaNo: Integer);
var
  TextBox: TRVTextBoxItemInfo;
begin
  TextBox := TRVTextBoxItemInfo.Create(Edit.RVData);
  with TextBox.BoxPosition do
  begin
    HorizontalAnchor := rvhanPage;
    HorizontalOffset := Edit.Style.RVUnitsToUnits(Xmm, rvuMillimeters);
    VerticalAnchor := rvvanPage;
    VerticalOffset := Edit.Style.RVUnitsToUnits(Ymm, rvuMillimeters);
  end;
  with TextBox.BoxProperties do
  begin
    Border.Style := rvbNone;
    Border.BorderOffsets.SetAll(0);
    Width := Edit.Style.RVUnitsToUnits(Widthmm, rvuMillimeters);
    Background.Color := clNone;
  end;
  TextBox.Document.AddNL(Text, StyleNo, ParaNo);
  Edit.InsertItem('', TextBox);
end;
This code inserts a text box at the position of the caret. The exact place if insertion does not matter: it is aligned relative to a page. So, a place of insertion may be anywhere inside this page.
Example for TRichViewEdit:

Code: Select all

  InsertTextAt(RichViewEdit1, 30, 50, 50, 'Hello world!', 0, 0);
Example for ScaleRichView:

Code: Select all

  SRichViewEdit1.StartEditing(srvrveMain); // making sure that insertion is in the main document
  InsertTextAt(SRichViewEdit1.ActiveEditor, 30, 50, 50, 'Hello world!', 0, 0);
Note 1: in TRichViewEdit, text boxes are not shown; they are visible only on printing or in a print preview. In ScaleRichView, they are shown WYSIWYG.

Note 2: If you want to insert text in all pages, insert it in a header or a footer. For example, for ScaleRichView:

Code: Select all

  SRichViewEdit1.StartEditing(srvrveHeader); // making sure that insertion is in the header
  InsertTextAt(SRichViewEdit1.ActiveEditor, 30, 50, 50, 'Hello world!', 0, 0);
Note 3: If you want to add this text not as an editing operation at the caret position, but when generating a new document, change InsertItem to AddItem (and do not forget to call Format when generation is finished)

Note 4: in RichViewActions, you can use Insert | Text Box command.

Re: text at specific position

Posted: Mon May 13, 2024 9:21 am
by sorega2022
hi, i have a problem with the sample for ScaleRichView. I cannot use the command InsertTextAt. Where is here the reference to use it? It is not in TSRichViewEdit.

Re: text at specific position

Posted: Tue May 14, 2024 7:56 pm
by Sergey Tkachenko
InsertTextAt is a procedure that I posted here, in the first code fragment. See my previous answer.