[Demo] Page background and border in RTF and DocX
Posted: Wed Jan 26, 2022 8:22 am
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.
This file contains demos showing how to generate a document with page background image and borders: This document is saved to DocX and RTF files.
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.
Why don't we use 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.
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.
This file contains demos showing how to generate a document with page background image and borders: This document is saved to DocX and RTF files.
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 are calculated in absolute values (depending on page size and margins).
Why don't we use 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.