Expertsystemen

 

Picture in Word

Just like text, in some cases you might want to have pictures in your documents based on certain conditions. In the Studio, this can be done by making use of the picture fragment functionality. First, add any pictures you want to have in your Word template. Then, by making use of the picture fragment you can replace the pictures in Word depending on the rules you make in your model. Below, an example is given, based on the Word template presented in the document assembly intro.

The first step is to give the image a title. This is done so you can refer to it. By selecting the properties of the picture in Word, you can add a title. In English, right-click the image and select Format picture; in Dutch, select Afbeelding opmaken. Then, navigate to the correct tab and change the title:

Adding a title
Adding a title

Note: when editing a template with LibreOffice, it is the “description” field you want.

We have called the picture “berkeley_bridge_logo”, but you can use any name. Just make sure it is a clear name. If you have added this document to your model, you can go to Layout > Picture fragment. This opens the following dialog;

Picture fragment dialog
Picture fragment dialog

In the condition field you can add a condition like you normally do. If you don’t know how to use conditions, please take a look at the documentation on conditions.

In ‘Existing picture in document’ there is a drop-down menu. If you open this menu, the Studio will look at all the documents that are created by the model and search them for pictures. If the picture has a title, it will show it, otherwise it shows just the (file)name of the picture. In this example, ‘employee female’ is found in a document called ‘arbeidsovereenkomst.docx’.

In the drop-down ‘Replace with this picture’, the first option is <delete picture>. This deletes the image from the document if the condition is either empty or met.

If you want to replace the picture, you can press the […] button, and select a picture from your hard drive. If you do this, the Studio will copy this picture to a sub folder <modelname>_images. The drop-down menu will show all the pictures you have added. After selecting the picture, press [OK] to save the changes. This works just like text fragments, so the picture fragment must come before the action to create the document. Again, the replacement will only happen if the condition is either empty or met.

Picture upload

The user might also have to upload a picture (e.g. a signature) and use it in a document.

This is only possible when running the model on an actual server.

For this you need a document and a model, both of these links together are an example of how picture uploading could be done.

In this model there are three nodes that are important. These nodes are signature, collect and document.

NOTE Uploading documents in this way requires the so-called uploads plugin to be enabled in your presentation layer. Please file a ticket with us if you want to use this functionality.

The first node, signature, contains a text interface and some metadata. The function setmetadata() takes two arguments: a key and a value. The key starts with uploads., followed by a numeric id, in this case 0. After that we get the property name. For instance 'uploads.0.mimetypes', setting it to '.png'. This means only .png files (pictures) can be uploaded to the server:

setmetadata('uploads.0.mimetypes', '.png')

The uploaded file can also be have multiple tags. We want a tag in our upload widget to tell us that documents uploaded with this widget are of the ‘type’ called ‘signature’:

In the example below tag number 0 is a 'constant' – meaning it is not editable by the end-user – , its name is the value 'type' and its value set to 'signature'.

setmetadata('uploads.0.tags.0.type', 'constant');
setmetadata('uploads.0.tags.0.name', 'type');
setmetadata('uploads.0.tags.0.value', 'signature');

Next is the node collect, which looks at all the files that are part of the current model and sees if it can find a file with a type tag whose value is 'signature', as defined in the node signature. Key to this is the function sessionfiletag(file, 'type'), which for a file uploaded in this widget would return the value 'signature'.

If this file is found, the name of that file is saved in the variable called filename. By using pictureoutput, the picture ‘signature’ is set on that filename.

The document node is built the same way we are used to. In the picture.docx file we need to describe the object picture. We give the description the text “signature” — matching the name of the picture fragment. The uploaded picture replaces the one in the template. You can access this description by pressing the right button on your mouse and selecting “Edit alt text” in your Word template.