Hi,
I try to create a custom plug-in to convert SVG images to PNG with ImageMagick command line tool while producing a DOCX file with the com.elovirta.ooxml plug-in.
I would like to bypass the build-in Inkscape conversion (SVG to EMF), since it sometimes get stuck along the way (at least with the files I tested) and the commands don't work anymore with my version of InkScape.
My custom changes work perfectly fine when I just overwrite the code of the
com.elovirta.ooxml plug-in:
- I add the link to the ImageMagick.exe instead of inkscape.exe (as parameter)
- I replace the Inkscape commands with ImageMagick commands.
But overwriting the base plug-in is not the way to go of course, so I need to create a custom plug-in but that's where I am stuck. I am new to this kind of plug-ins.
This is what I find in the com.elovirta.ooxml build.xml:
<target name="docx.svg2emf" if="inkscape.exec" unless="docx.inkscape.skip">
<mkdir dir="${dita.temp.dir}/docx/word/media"/>
<for param="svg.file">
<path>
<fileset dir="${user.input.dir}">
<include name="**/*.svg"/>
</fileset>
</path>
<sequential>
<local name="emf.file"/>
<basename property="svg.name" file="@{svg.file}" suffix=".svg"/> <property name="emf.file" location="${dita.temp.dir}/docx/word/media/${svg.name}.emf"/> <echo taskname="inkscape">Converting @{svg.file} to ${emf.file}</echo>
<exec executable="${inkscape.exec}" taskname="inkscape">
<arg value="-z"/>
<arg value="--export-emf=${emf.file}"/>
<arg file="@{svg.file}"/>
</exec>
</sequential>
</for>
</target>
The only thing that needs some change are the commands to get it working and link the ${inkscape.exec} to ImageMagick.exe:
<arg value="convert"/>
<arg value="@{svg.file}"/>
<arg value="${emf.file}"/>
So, I created my build.xml file and made some minor changes:
<project>
<target name="docx.svg2png" if="magick.exec" unless="docx.inkscape.skip">
<mkdir dir="${dita.temp.dir}/docx/word/media"/>
<for param="svg.file">
<path>
<fileset dir="${user.input.dir}">
<include name="**/*.svg"/>
</fileset>
</path>
<sequential>
<local name="emf.file"/>
<basename property="svg.name" file="@{svg.file}" suffix=".svg"/> <property name="emf.file" location="${dita.temp.dir}/docx/word/media/${svg.name}.png"/> <echo taskname="inkscape">Converting @{svg.file} to ${emf.file}</echo>
<exec executable="${magick.exec}" taskname="inkscape">
<arg value="convert"/>
<arg value="@{svg.file}"/>
<arg value="${emf.file}"/>
</exec>
</sequential>
</for>
</target>
</project>
I also created a plug-in.xml, but here I am probably doing something wrong by adding an incorrect extension???
Could someone help me which kind of extension I should choose to make this work?
<plugin id="com.flow.magick.word">
<require plugin="com.elovirta.ooxml"/>
<feature extension="ant.import" file="build.xml"/>
<transtype name="docx" desc="DOCX">
<param name="magick.exec" desc="Magick executable" type="file"></param>
</transtype>
</plugin>
I attached both files for references.
Thanks a lot in advance.
Kind regards,
Pieterjan