4D v16

Accessing document contents by programming

Home

 
4D v16
Accessing document contents by programming

Accessing document contents by programming  


 

 

4D Write Pro provides a full set of commands allowing you to modify text and image attributes in your documents. Thanks to these features, 4D developers can design their own user interfaces (using buttons, menus, check boxes, etc.) for 4D Write Pro documents. Commands can be applied to whole documents or to specific portions (ranges), either based on user selections or custom values. Available properties include document units, margins, padding, background, paragraph settings, colors, fonts, font styles, as well as image properties. 

For example, the 4D Write Pro area library object makes extensive use of these features to provide a sophisticated 4D Write Pro interface:

Several commands are dedicated to handling selections in the documents. Since selected text can contain (invisible) formatting tags, 4D Write Pro works with ranges. A range is an object that represents a portion of a 4D Write document.

  • WP Get range( wpArea ; startRange ; endRange ) -> rangeObj: returns a new range corresponding to boundaries you passed as parameters.
  • ( {*;} wpArea ) -> rangeObj: returns a new range corresponding to the current user selection.
  • WP Get pictures( rangeObj ) -> rangeObj: returns a new range containing only the pictures.
  • WP Get paragraphs( rangeObj ) -> rangeObj: returns a new range containing only the paragraphs.
  • WP SELECT( {*;} wpArea {; rangeObj}{; startRange ; endRange} ): selects the text corresponding to the range.

4D Write Pro allows you to create and work with dynamic references to parts of your documents, called bookmarks. A bookmark is a named reference attached to a specific range in a 4D Write Pro document.

Bookmarks are dynamic, which means that if the user moves, adds or removes text belonging to the bookmark, the associated range will be updated automatically and the bookmark will continue to reference the same content within the document. For example:

  • You create a bookmark named "MyBM" that references the "Hello world" text on page 20 of your document.
  • Then you insert 50 pages at the beginning of the document.
  • You will still be able to access the same "Hello world" text automatically, now on page 70 of the document, by means of the "MyBM" bookmark.

A document can contain an unlimited number of bookmarks. Several bookmarks can reference the same range, and bookmark ranges can be interleaved. However, each bookmark name must be unique in the document. Bookmarks are not imported when using the MissingRef or WP New command (bookmarks in the destination document cannot be overwritten).

Once created, a bookmark is stored within the document. It is saved with the document, and can be handled by several different commands. It can also be used to reference parts of a template document. These parts can then be assembled automatically with data from the database to produce dynamic output documents such as invoices or catalogs.

Several commands allow you to create, remove, and use bookmarks:

The following commands can get or set any attributes of the document:

  • WP SET ATTRIBUTES( rangeObj | wpDoc ; attribName ; attribValue {; attribName2 ; attribValue2 ; ... ; attribNameN ; attribValueN} ): sets one or more attribute/value pairs in the document or range.
  • WP GET ATTRIBUTES( rangeObj | wpDoc ; attribName ; attribValue {; attribName2 ; attribValue2 ; ... ; attribNameN ; attribValueN} ): gets the current value of attributes in the document or range.
  • WP RESET ATTRIBUTES( rangeObj ; attribName {; attribName2 ; ... ; attribNameN } ): resets attribute values in the document or range.

Attributes are detailed in the 4D Write Pro Attributes section.

This command allows you to get information about style support for a range:

  • WP Is font style supported( rangeObj ; wpFontStyle ) -> true or false: allows you to know if a range supports a given style (useful to design an interface).



See also 

Download HDI database

 
PROPERTIES 

Product: 4D
Theme: 4D Write Pro Language

 
HISTORY 

New
Modified: 4D v16

 
ARTICLE USAGE

4D Write Pro Reference ( 4D v16)