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.