Tech Tip: Utility method to get height of 4D Write Pro header and footer
PRODUCT: 4D Write Pro | VERSION: 19 | PLATFORM: Mac & Win
Published On: October 17, 2022
Below is a utility method that will return the height of the header or the footer of the passed 4D Write Pro document.
// Method: WP_GetMarginAreaObjHeight // // Parameters: // $WParea : WP Document Object // $bHeader : True - Height of Header // False - Height of Footer // $lUnit (Optional) : Unit of results, // (use wk unit... contants ie. wk unit cm or wk unit inch) // ---------------------------------------------- #DECLARE($WParea : 4D.WriteDocument; $bHeader : Boolean; $lUnit : Text)->$height : Real var $wpObject : 4D.WriteRange var $wpAttribute; $wpUnit : Text var $calc1; $calc2; $docMargin; $objTMargin; $objBMargin : Real var $obPos : Object If ($bhHeader) $wpObject:=WP Get header($WParea; 1) $wpAttribute:=wk page margin top Else $wpObject:=WP Get footer($WParea; 1) $wpAttribute:=wk page margin bottom End if If (Not($wpObject=Null)) // Save current layout unit and apply specified unit If (Count parameters>2) WP GET ATTRIBUTES($WParea; wk layout unit; $wpUnit) WP SET ATTRIBUTES($WParea; wk layout unit; $lUnit) End if // Calculate size of container WP GET ATTRIBUTES(WP Get section($WParea; 1); $wpAttribute; $docMargin) WP GET ATTRIBUTES($wpObject; wk margin top; $objTMargin; wk margin bottom; $objBMargin) $calc1:=$docMargin-($objTMargin+$objBMargin) // Calculate size of content $obPos:=WP Get position($wpObject) $calc2:=$obPos.bounds.bottom-$obPos.bounds.top // Return the larger of the two (Container size vs Content size) $height:=Choose($calc1>$calc2; $calc1; $calc2) // Restore layout unit If (Count parameters>2) WP SET ATTRIBUTES($WParea; wk layout unit; $wpUnit) End if Else // No Footer $height:=0 End if |
Below is an example use to get the height of the header in inches and the height of the footer in centimeters for a 4D Write Pro document:
var $rHeaderH; $rFooterH : Real $rHeaderH:=WP_GetMarginAreaObjHeight(WParea; True; wk unit inch) $rFooterH:=WP_GetMarginAreaObjHeight(WParea; False; wk unit cm) |