📜 ⬆️ ⬇️

Document generation - a view from the inside

Creating a module for generating documents only at first glance may seem like a simple task. In fact, to create such a module, it is necessary to solve several problems, without solving which its implementation will be incomplete. The functionality of the document generator should be able to solve problems in the form of requirements from real life. Consider one of the many problems.

Requirement: users \ business want to have a library of paragraphs (paragraphs) that are inserted into documents generated using various templates. Changing an item in the library should result in a change to this item in the documents that are generated from these templates. I would like to change the items of the business itself, without the participation of IT. Creating templates (according to which documents are generated), taking into account insertions of items from the library into their different places, reduces the size of templates, they become polymorphic, and, accordingly, the number of templates decreases and their maintenance is simplified.

Initial data: for convenience of working with items, the library may consist, for example, of document fragments created in MS Word. Those. their creation and editing is done in MS Word. Library items are stored, for example, in a database and \ or in a file folder. What specific items will be inserted into the document during generation is determined during the execution of the application that uses the generator module.
')
The first task to be solved is the task of pairing the indents of the text specified in the template and the added items from the library, pairing the font sizes, etc. This task is partially solved by the rules of drawing up paragraphs, the font chosen in advance and its size. Indenting the generator should determine itself, based on the context of the place in the template where the item is inserted. Fortunately, such a context is not difficult to determine, so this task is simply indicated here.

The second task is more difficult. Consider an example of a clause and on its basis list the problems:

[1.2] , - [] , [2.3] [3.1] [" "][ ]

In the above example, text fragments placed in [...] brackets should be set parametrically. Those. this library item when inserted into a real document could look like this:

3.1 , - .. , 4.1 4.6 " "

If the application at the time of execution may know about Gorbunkov S.S. and the application does not know about the description or description, which particular item number in the template is 1.2 or 3.1, and it should not. There may be several library items, they can be inserted in different places of different templates, the numbering of sections in them does not match, and points can be referenced to other items whose numbers should not be known to the application. The application must assign the task of calculating the numbers of items to the generator itself. The templates together with the generator should provide the numbering of their own and library items themselves, however, as well as the definition of reference numbers for items.

For example, in one template a specific library center may refer to clauses 4.1 and 4.6, in another (or in the same) only clause 2.5.1. In addition, if paragraphs are numbered within one document, then references may refer to paragraphs in another document, such as the “Brief Description” may not be a currently generated document, but an existing one. All this suggests that the library center should be parameterized. If the generator cannot perform such operations, then the person will have to make changes to the document manually, and the person may be mistaken.

For example, the layout of the library point can be as follows:

[:X] , - [ ] , [ :A][ [ :B]] [[:1=" "]|[:2= ]]

So, if the generator module knows what the counter value is: X before inserting the library item, knows the value of the [Name of the author] field, has information about the “Short description” document and can find in it specific values ​​of global counters (available from other documents) with the names A and B of this document, and if it knows the alternate 1 or 2, then the final value of the library point is calculated by the generator according to the input parameters and this point can be used in different templates without problems.

It only remains to add that not only IT employees, but also trained employees of organizational units can modify this library item in MS Word. What pleases.

Source: https://habr.com/ru/post/334090/


All Articles