<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Insert a .png-File in a word Document by using Mergefields</title><link>https://answers.axonivy.com/questions/1820/insert-a-png-file-in-a-word-document-by-using-mergefields</link><description>&lt;p&gt;Hi everyone,&lt;/p&gt;
&lt;p&gt;i'm having a problem and hopefully you can help me.
Until now i always used MergeFields to import information from ivy to a word-document by using e.g. the following instructions:&lt;/p&gt;
&lt;p&gt;import ch.ivyteam.ivy.addons.docfactory.TemplateMergeField;&lt;/p&gt;
&lt;p&gt;in.MergeField.add(new TemplateMergeField("FIELD1", in.xxx));&lt;/p&gt;
&lt;p&gt;At the moment im facing the problem that i can't import .png files. 
It doesn't work when the data is from the type "string" because only the Path will be importet but also when the data-type is from the type "file".
From my point of view it is because the mergefields only support the type "string" - is it possible to change it to the type "file" (?)&lt;/p&gt;
&lt;p&gt;If not - is there a work around?&lt;/p&gt;
&lt;p&gt;Thank you very much for your time&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/1820/insert-a-png-file-in-a-word-document-by-using-mergefields" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 20 Jun 2016 15:46:20 -0400</lastBuildDate><item><title>Answer by Emmanuel</title><link>https://answers.axonivy.com/questions/1820/insert-a-png-file-in-a-word-document-by-using-mergefields/1825</link><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have tested it in IvyScript with the Ivy File type. Please get the Files path with &lt;code&gt;getAbsolutePath()&lt;/code&gt;
&lt;/p&gt;&lt;pre&gt;import ch.ivyteam.ivy.addons.docfactory.TemplateMergeField;
import ch.ivyteam.ivy.addons.docfactory.FileOperationMessage;
import ch.ivyteam.ivy.addons.docfactory.DocumentTemplate;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;File image = new File("logo-euro.jpg"); 
File template = new File("template_picture.docx"); // mergefield named Image:FIELD1&lt;/p&gt;
&lt;p&gt;List&amp;lt;templatemergefield&amp;gt; mergeFields = new List();
mergeFields.add(new TemplateMergeField("FIELD1", image.getAbsolutePath()));&lt;/p&gt;
&lt;p&gt;DocumentTemplate dt = new DocumentTemplate(template.getAbsolutePath(), 
    ivy.wf.getApplication().getFileArea().getAbsolutePath(), "result", "pdf", 
    mergeFields);&lt;/p&gt;
&lt;p&gt;FileOperationMessage fom = dt.generateDocument();
ivy.log.info("Result success ? {0} and document produced in {1}", fom.isSuccess(), fom.files.get(0));
&lt;/p&gt;&lt;/pre&gt;&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I get &lt;code&gt;Result success ? true and document produced in D:\ivy\designer\6.1\files\application\result.pdf&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It works fine :
&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/2016-06-20_1516.png"&gt;&lt;/p&gt;
&lt;p&gt;Cheers
Emmanuel&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emmanuel</dc:creator><pubDate>Mon, 20 Jun 2016 15:46:20 -0400</pubDate><guid>https://answers.axonivy.com/questions/1820/insert-a-png-file-in-a-word-document-by-using-mergefields/1825</guid></item><item><title>Answer by Emmanuel</title><link>https://answers.axonivy.com/questions/1820/insert-a-png-file-in-a-word-document-by-using-mergefields/1822</link><description>&lt;p&gt;Hi,&lt;/p&gt;

&lt;p&gt;So it is quite easy (I guess) :)
First in your template, your image mergefield name should start with "Image:" This allows the DocFactory Backend to intercept the mail merge operation and see it has to insert an image there.
For Example: "Image:my_logo" 
You do then:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;in.MergeField.add(new TemplateMergeField("my_logo", in.myLogoFile.getAbsolutePath()));&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This should work.&lt;/p&gt;

&lt;p&gt;A new improved version of the IvyAddOns in on the way with the possibility of using java.io.File objects directly as parameters.&lt;/p&gt;

&lt;p&gt;I hope this will help you&lt;/p&gt;

&lt;p&gt;Regards
Emmanuel&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Emmanuel</dc:creator><pubDate>Fri, 17 Jun 2016 14:05:33 -0400</pubDate><guid>https://answers.axonivy.com/questions/1820/insert-a-png-file-in-a-word-document-by-using-mergefields/1822</guid></item></channel></rss>