put_in_text_file2

The function put_in_text_file2 writes produced text to a file. Text saved in this way does not appear in the result document. You can use this function several times in a Template script so the text produced up to the call is placed in the file.

This function produces a plain text document regardless of the word processor the Master Template has been made with. The plain text document is encoded using the character set encoding specified in the encoding parameter encoding. If the document content cannot be represented using the specified character set encoding, an error is generated. Unlike the put_in_text_file function, the put_in_text_file2 function does not support processing of Includes.

put_in_text_file2 ("textfile_to_be_produced"; 
                    "path/folder_of_the_text_file";
                    "overwrite Y/N"; 
                    "encoding") 

This function has no effect on the AiaDocXML and HTML output.

The function put_in_text_file2 requires four parameters:

  • textfile_to_be_produced, type TEXT. This is the name of the document.
  • path/folder_of_the_text_file, type TEXT. The path and name of the folder or a folder that the text file is written to.
  • overwrite, type TEXT, Y or N. When you set this parameter to Y, the existing file is overwritten; when you set this parameter to N, the end user is prompted to specify an alternative file name and folder. Interactivity is not possible in a KCM Core environment.
  • encoding, type TEXT. The value must be one of the following: UTF-8, UTF-8bom, UTF-16, ISO-8859-1, ISO-8859-15 and 1252. This parameter specifies the character set encoding of the plain text document that is to be written.

The put_in_text_file2 function writes the KCM output to a text file and does not create a copy. Once written to a file, the output is no longer available for a Template script and it does not appear in the result document. The reason for this is that KCM stores produced text in an internal buffer. When you call the put_in_text_file2 function, KCM writes the content of the buffer to the file, which clears the internal buffer.

To create multiple files from one output, you can use the open buffer mechanism (see open_buffer).

Documents that KCM produces through the put_in_text_file( ) function are directly available for opening after KCM successfully executes the put_in_text_file2( ) function.

The plain text result document also contains word processor instructions such as text boxes, fields, and footnotes. This may cause unexpected results as KCM makes no attempt to maintain the layout of the output document. Therefore, you should avoid using word processor instructions that will appear in result documents when the put_in_text_file2 function is used.

An example is provided here.

#
This line will be stored in the file 'file.txt' on c:\temp, and will not appear in the result document.
#
TEXT doc := put_in_text_file2("file.txt"; "c:\temp"; "Y"; "ISO-8859-1")
#
The file produced is @(doc). 
These lines will appear in the result document because they are produced after the put_in_text_file2 call above.
#