KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Creating headers and footers programatically in 4D Write Pro object
PRODUCT: 4D | VERSION: 16R5 | PLATFORM: Mac & Win
Published On: March 30, 2018

In order to enable the headers and footers in a 4D Write Pro object, the areas have to be clicked on the form. But what if you need to have this 4D Write Pro object generated programatically? The headers and footers will not be active. Here is a utility method to activate the headers and footers of a 4D Write Pro object:

//---------------------------------------------------------------------------------
// Name: ADD_HEADER_FOOTER_WP_DOC
// Description: Method will add a Header and/or Footer in the WritePro object
//
// Parameters:
// $1 (POINTER) - Write Pro object
// $2 (LONGINT) - Choice 1 - Header only, 2 - Footer only, 3 - Both
// --------------------------------------------------------------------------------
C_POINTER($1;$writePro)
C_LONGINT($2;$choice;$posBody)
C_TEXT($div;$beforeText;$afterText;$completedText)

If (Count parameters=2)

  $writePro:=$1
  $choice:=$2

  WP EXPORT VARIABLE($writePro->;$wpHtml;wk web page html 4D)

  Case of
   : ($choice=1) // Header
    $div:="<div class=\"section1Header\" style=\"visibility: hidden; height: 0\"></div>"
   : ($choice=2) // Footer
    $div:="<div class=\"section1Footer\" style=\"visibility: hidden; height: 0\"></div>"
   Else
    $div:="<div class=\"section1Header\" style=\"visibility: hidden; height: 0\"></div><div class=\"section1Footer\" style=\"visibility: hidden; height: 0\"></div>"
  End case

  $posBody:=Position("";$wpHtml)

  $beforeText:=Substring($wpHtml;1;$posBody-1)
  $afterText:=Substring($wpHtml;$posBody;Length($wpHtml))
  $completedText:=$beforeText+$div+$afterText

  $writePro->:=WP New($completedText)

End if



Example #1: Adding a header to the Write Pro object.

ADD_HEADER_FOOTER_WP_DOC (->WriteProArea;1)





Example #2: Adding a footer to the Write Pro object.

ADD_HEADER_FOOTER_WP_DOC (->WriteProArea;2)





Example #3: Adding a header and footer to the Write Pro object.

ADD_HEADER_FOOTER_WP_DOC (->WriteProArea;3)

Commented by Roland Lannuzel on August 8, 2018 at 6:35 AM
Hello, Trying to manage headers and footers by HTML manipulation is (might be) a good idea but the good news is that specific commands to manage headers and footers shall be available in V17 R3... Stay tuned, the beta test will begin in Q4 ! Roland Lannuzel.