Create headers and footers with code in a 4D Write Pro document

Automatically translated from English

Since v16 R5, it’s been possible to access and modify an existing header and footer by programming. If you want to add a header and footer to your 4D Write Pro document, you use a template to do so!

If you’re not a fan of templates, good news! With 4D v17 R3, you can create a header and a footer by programming for a given section

Two new commands are at your disposal for this purpose: WP New header and WP New footer.

Of course, you can also delete a header and a footer by programming with the WP DELETE HEADER and WP DELETE FOOTER commands.


For example, the following code adds a header and a footer in the current section:

// Retrieve the current section
$section:=WP Get section($range)
// Create a header
$header:=WP New header($section)
// Create a footer
$footer:=WP New footer($section)


Then you can insert your text in the header and format it as follows:

// Create a new range containing only the header
$headerRange:=WP Create range($header;wk end text;wk end text)
// Insert text
WP SET TEXT($headerRange;"Hello World!";wk append)
// Set in bold
WP SET ATTRIBUTES($header;wk font bold;wk true)

Vanessa Talbot

• Product Owner •

Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.

Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.