4D Blog

Home Product Programmatically manage headers and footers in 4D Write Pro

Programmatically manage headers and footers in 4D Write Pro

October 16, 2017

Product Manage Header and footer with 4D Write Pro

We’ve received several customer requests to provide the ability to use the 4D Write Pro template with headers and footers to create other documents based on this template. Well, we heard you and this is available in 4D v16 R5.

A new set of commands have been added to 4D Write Pro to fulfill this need. Some of these commands can be used to get references of headers, body and footers inside documents. Others are handy to get a reference to the frame (header, footer, etc.) where the cursor is currently located, or to set the cursor into a specific frame.

Example database

Get a reference to headers, footers or body

New 4D commands – WP Get header, WP Get body and WP Get footer – have been added so that developers can get a reference to any header or footer for the document or for a specific section.

These references can then be used to get associated ranges, create documents, etc. The final goal is to copy the content of any frame (fully or partially) and paste it inside any other frame of the same document or any other new or existing one.

Code sample

// Get the header from a template and put it in the header of the main document
$source:=WP Get header(mytemplate;1)  // first section
$rangeSource:=WP Get range($source;wk start text;wk end text)
$tempoc:=WP New($rangeSource)
 
$target:=WP Get header(myDocument;1)  // first section
$rangeTarget:=WP Get range($target;wk start text;wk end text)
WP INSERT DOCUMENT($rangeTarget;$tempoc;wk replace)

Move the cursor to a specific frame

Upon creating elaborate documents by programming, you may want to successively put some information first in the header, then in the footer, and finally go back to fill the document body. It basically means that you need have a means to navigate in the different document frames.

The WP Get frame command is used to get the reference to the frame where the cursor is currently located: header, first header, body, first footer, etc. The WP SET FRAME command does the opposite job. It places the cursor inside a specific frame as long as this frame exists in the document.

Code samples

Let’s say you want to move the cursor to the main header:

WP SET FRAME(*;"WParea";wk current section default header)

If you want to make sure that the user has set the cursor in a header or footer:

$frame:=WP Get frame(*;"WParea")
If($frame=wk body)
ALERT("Please select a footer or a header")
End if

Discuss

Tags 4D Write Pro, Programming, v16 R5, v17, Word processor

Latest related posts

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

  • April 29, 2025

    Discover your AI-powered writing assistant in 4D Write Pro

Roland Lannuzel
Roland Lannuzel
• Product Owner & 4D Expert •After studying electronics, Roland went into industrial IT as a developer and consultant, building solutions for customers with a variety of databases and technologies. In the late 80’s he fell in love with 4D and has used it in writing business applications that include accounting, billing and email systems.Eventually joining the company in 1997, Roland’s valuable contributions include designing specifications, testing tools, demos as well as training and speaking to the 4D community at many conferences. He continues to actively shape the future of 4D by defining new features and database development tools.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy