Create a text header with image

<< Click to Display Table of Contents >>

Navigation:  Programming > Create text under program control > Low level text creation >

Create a text header with image

You can use WPRichText1.HeaderFooter.Get to access a TWPRTFDataBlock to directly modify it with low level routines. AppendNewPar append a paragraph at the end, but you can also read FirstPar to create a loop over all paragraphs.

 

This example creates text and an image in a new header text.

 

var par : TParagraph;

   block : TWPRTFDataBlock;

   obj : TWPTextObj;

begin

 block := WPRichText1.HeaderFooter.Get(wpIsHeader,wpraOnAllPages,'');

 block.Clear(true);

 par := block.AppendNewPar();

 par.Append('Some Text');

 obj := par.AppendNewObject(wpobjImage);

 obj.LoadObjFromFile('c:\debug\test.bmp');

 obj.ScaleWH(1440,1440);

 WPRichText1.ReformatAll(false, true);

end;

 

Optionally you can move the image to a special position on the page:

 

 obj.PositionMode := wpotPage;

 obj.RelX := WPCentimeterToTwips(10);

 obj.RelY := WPCentimeterToTwips(15);

 

 

Hints:

Instead of wpIsHeader you can use wpIsFooter to create a footer text.

 

These values are possible in place of wpraOnAllPages:

wpraOnOddPages, wpraOnEvenPages, wpraOnFirstPage,

 

This Modes are not compatible to the RTF Standard:

wpraOnLastPage, wpraNotOnFirstAndLastPages, wpraNotOnLastPage, wpraNotOnFirstPage

 

Also possible:

wpraOnGivenPageNr  - This makes sense only for header and footer. The text is selected by name. The name must be specified as '#' + PageNumber in range [1...] (absolute-not per section!)

 

This low level code creates a text box in the header text - WPTools "Premium" is required:

 

var par : TParagraph;

   block, block2 : TWPRTFDataBlock;

   obj : TWPTextObj;

begin

  block :=  WPRichText1.HeaderFooter.Get(wpIsHeader,wpraOnAllPages,'');

 block.Clear(true);

 par := block.AppendNewPar();

 // We create the box directly in the header (par!)

 obj := WPRichText1.TextObjects.InsertTextBox(1440, 1440, block2, par);

 if obj <> nil then

 begin

   obj.Frame := [wpframe1pt];

   obj.RelX := WPRichText1.Header.LeftMargin;

   // Create a TWPRTFDataBlock for this box

   par := block2.AppendNewPar();

   par.Append('Some Text in box');

 end;