In my document I have a left page margin of 6cm so that I have quite some space to add custom things on the left side. I want to use this space to add text boxes and position them to fixed positions.
This works well as long as I have simple text in the boxes. But I also want to add an image to the box and that fails. I used TWPORTFTextBox.AddSubImage for that purpose but I can't see the image. Here is my code:
Code
procedure AddLogo;
var
lTextObj: TWPTextObj;
lTextBox: TWPORTFTextBox;
Img: TWPOImage;
begin
Img:=TWPOImage.Create(FRtfDoc);
Img.LoadFromFile('C:\tmp\flag.png');
Img.WidthTW:=Img.ContentsWidth;
Img.HeightTW:=Img.ContentsHeight;
lTextBox := TWPORTFTextBox.Create(FRtfDoc);
lTextBox.WidthTW := WPCentimeterToTwips(4.2);
lTextBox.HeightTW := WPCentimeterToTwips(2.5);
lTextBox.ObjName := '_AUTO_' + IntToStr(GetTickCount);
lTextBox.AddSubImage('Logo', Img);
lTextObj := FRtfDoc.TextObjects.InsertMovableImage(lTextBox);
if lTextObj <> nil then
begin
lTextObj.Mode := lTextObj.Mode + [ wpobjObjectUnderText, wpobjCreateAutoName ];
lTextObj.RelX := WPCentimeterToTwips(0);
lTextObj.RelY := WPCentimeterToTwips(9);
end;
end;
Alles anzeigen
Can you please correct my code or tell me another approach to add an image to a text box?
Many thanks in advance,
Dirk.