text at specific position

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
sorega2022
Posts: 23
Joined: Tue May 07, 2024 4:30 am

text at specific position

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

Re: text at specific position

Post 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.
sorega2022
Posts: 23
Joined: Tue May 07, 2024 4:30 am

Re: text at specific position

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

Re: text at specific position

Post by Sergey Tkachenko »

InsertTextAt is a procedure that I posted here, in the first code fragment. See my previous answer.
Post Reply