Demo: page border and background

Demo: Page background and border in RTF and DocX

Microsoft Word Documents (DocX and RTF) do not support page background directly.
However, there is a workaround: you can insert a text box in a header or a footer, and add an image to this textbox. Additionally, this textbox can have a border.
Actually, Microsoft Word itself uses this technique when adding a page watermark.

The demo shows how to generate a document having a page border and a page background image, and how to same it to DocX and RTF files. The demo can be found in the support forum:

There are 4 versions of the demo: (for TRichView and for ScaleRichView) x (for Delphi and for C++Builder 11)
The demos for C++Builder 11 can be used in older versions of C++Builder, you just need to change references to packages in the CBProj file.

Note 1: A text box is positioned relative to the whole page, its size and position is calculated in absolute values (depending on the page size and margins).
Why don’t we used sizing and positioning relative to the main text area? It was done for compatibility with Libre Office. Unfortunately, its current version has problems with advanced options for textbox positioning.

Note 2: This demo shows the simplest case: the same background image for all pages. TRichView and ScaleRichView support special headers for the first page and odd/even pages, so they can have different background images and borders.

Share this article