Page 1 of 1

Adding a .svg image file

PostPosted: Wed Sep 22, 2010 5:30 pm
by sharu1484
Hello Jason,
I am new to docX4j. I am able to add an .jpeg image file to word document however, when I add .svg file it throws following error:

imconvert: Must specify image size `D:/TEMP/magick-itjvr8TN' @ mvg.c/ReadMVGImage/184.
imconvert: missing an image filename `png:-' @ convert.c/ConvertImageCommand/2838.
Exception in thread "main" org.docx4j.openpackaging.exceptions.Docx4JException: Error checking image format
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.ensureFormatIsSupported(BinaryPartAbstractImage.java:297)
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.createImagePart(BinaryPartAbstractImage.java:184)
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.createImagePart(BinaryPartAbstractImage.java:151)
at com.apcc.reports.docx4j.AddImage.newImage(AddImage.java:109)
at com.apcc.reports.docx4j.AddImage.main(AddImage.java:75)
Caused by: java.io.EOFException
at javax.imageio.stream.ImageInputStreamImpl.readInt(Unknown Source)
at javax.imageio.stream.ImageInputStreamImpl.readUnsignedInt(Unknown Source)
at org.apache.xmlgraphics.image.loader.impl.PreloaderEPS.preloadImage(PreloaderEPS.java:65)
at org.apache.xmlgraphics.image.loader.ImageManager.preloadImage(ImageManager.java:165)
at org.apache.xmlgraphics.image.loader.cache.ImageCache.needImageInfo(ImageCache.java:96)
at org.apache.xmlgraphics.image.loader.ImageManager.getImageInfo(ImageManager.java:112)
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.getImageInfo(BinaryPartAbstractImage.java:558)
at org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage.ensureFormatIsSupported(BinaryPartAbstractImage.java:289)
... 4 more

Also, I am not finding any API [methods] or samples to create TOC in the word file. Can you please help?

Regards,
Sharad

Re: Adding a .svg image file

PostPosted: Thu Sep 23, 2010 11:40 am
by jason
Hi Sharad,

As I'm sure you've worked out, docx4j is using image magick to convert the SVG to a PNG.
(Word 2007 can't open an SVG).

I just tried adding an SVG myself.
- I installed ImageMagick 6.6.4 (on Windows) and renamed the executable to imconvert
- I restarted eclipse (this seemed to be necessary in order for it to read the updated system path, and avoid "CreateProcess error=2, The system cannot find the file specified")

After that, it worked for me.

Googling for "convert.c ConvertImageCommand" might help with your specific issue? Let us know how you go, thanks.

cheers .. Jason

ps i've created a separate thread for your other question.

Re: Adding a .svg image file

PostPosted: Thu Sep 23, 2010 4:05 pm
by sharu1484
Hello Jason,
Thanks a lot for the reply.
I did install ImageMagick-6.6.4-Q16 and updated system path and restarted eclipse.
However, on executing the program I am getting the error attached in ImageMagickError.doc.
Not sure if this is windows and ImageMagick compatibility issue.

I have also attached the program AddImage.java for reference. I wanted to know if I need to call
BinaryPartAbstractImage.convertToPNG() method. !!

Please let me know. Thanks in advance.

Regards,
Sharad

Re: Adding a .svg image file

PostPosted: Thu Sep 23, 2010 4:52 pm
by jason
Obviously the imagemagick popup error window is something you need to resolve, but troubleshooting that is outside the scope of this forum. Maybe you need one of the other IM downloads instead?

Once you get past that, if you are still having problems with your svg, feel free to post it or send it to me, and I'll see whether it works for me.

(If you use the AddImage sample code which i think you are, everything is done for you. You don't need to manually call BinaryPartAbstractImage.convertToPNG() method )

Re: Adding a .svg image file

PostPosted: Thu Sep 23, 2010 5:20 pm
by sharu1484
Hello Jason,
Please ignore the error posted in previous reply. It happening because of corrupt file.

I am able to insert the .svg file into word now. I am opening this word.doc using Word 2003 and the 'Zoom In' and 'Zoom Out' options of .svg file are not appearing on right click.
Does DocX4j changes the format of the image file?

Regards,
Sharad

Re: Adding a .svg image file

PostPosted: Thu Sep 23, 2010 6:48 pm
by jason
Yes, it is being converted to a PNG (that's why you need ImageMagick )

As per my first reply, Word 2007 and earlier can't handle svg afaik. Not sure about 2010.

You could try the method at http://forums.3dmojo.com/showthread.php?t=102 but i bet this is pasting in a different format.

See further http://www.openclipart.org/wiki/MS_Office which suggests using Inkskape to convert svg to eps or emf.