Dynamically inserting an image in to a document requires two things:
- The template controls where the image will appear
- The data determines what image is used
This article explains how to use a placeholder image in the template. The placeholder image determines the position and attributes of the image that will appear in the final document.
Please refer to this article on how to send image data or retrieve images from a file or URL.
Not every image in a template will be replaced. Any image in a template that isn't marked for replacement will appear unchanged in the generated document.
Instead of using the usual <<field>> notation, Docmosis looks for placeholder images in the template.
The advantage of using a placeholder image is that the image is used to determine the size, position and attributes (eg: text wrapping) that will apply to the image in the generated document.
The placeholder image needs to be marked so that Docmosis know which images to replace.
- To mark an image using Microsoft Word - use Bookmarks.
- To mark an image in LibreOffice Writer - use Picture>Names.
Note: The ZIP file contains an example DOC and ODT file which each have detailed instructions depending on whether you are using Microsoft Word or LibreOffice Writer.
In either case the Bookmark or Name should have the format: img_fieldName.
The "img_" part is the instruction to Docmosis that this image should be replaced.
The "fieldName" part identifies the data that will be used to create the image.
We have provided a placeholder image in this example that will clearly stand out in a template, but any image could be used, provided it has been marked as described above.
In this example the data file contains the new image as Base64 encoded data. Please refer to this article for all of the ways image data can be specified: How to send image data or retrieve images from a file or URL.