Does Aspose.word support TIF image insertion?

Dear all,

I have tried to use the aspose.word to insert a TIF image into a doc file. However, it fails to do so.
Here is my code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage("C:\W000063.tif",
RelativeHorizontalPosition.MARGIN,
0,
RelativeVerticalPosition.MARGIN,
0,
450,
600,
WrapType.SQUARE);
doc.save("C:\HelloWorld.doc");

Here is my result after running the code:

Hello World
java.lang.IllegalArgumentException: Unknown image file format.
at com.aspose.words.ImageData.setImage(Unknown Source)
at com.aspose.words.DocumentBuilder.insertImage(Unknown Source)
at com.aspose.words.DocumentBuilder.a(Unknown Source)
at com.aspose.words.DocumentBuilder.insertImage(Unknown Source)

So , how could insert a tif image into a word document?

Thank if anyone could help me.

I am using the Aspose.word for java 2.6.0

Hi

Thanks for your request. TIF images are not supported yet. But you can use workaround as described in the following forum thread.
https://forum.aspose.com/t/103813

Hope this helps.
Best regards.

Sorry , the above link can’t work.

By the way, may I know what kinds of file formats does Aspose.word support? Many Thanks.

Hi

Thanks for your request. Here is code provided there:

import com.aspose.words.*;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageDecoder;
import javax.media.jai.NullOpImage;
import javax.media.jai.OpImage;
import javax.media.jai.PlanarImage;
import java.awt.image.BufferedImage;
//....................................
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
//BufferedImage img = BufferedImage;
String file = "test.tif";
com.sun.media.jai.codec.FileSeekableStream ss = new com.sun.media.jai.codec.FileSeekableStream(file);
ImageDecoder decoder = ImageCodec.createImageDecoder("tiff", ss, null);
int numPages = decoder.getNumPages();
BufferedImage image[] = new BufferedImage[numPages];
for (int i = 0; i < decoder.getNumPages(); i++)
{
    PlanarImage op = new NullOpImage(decoder.decodeAsRenderedImage(i),
    null,
    OpImage.OP_IO_BOUND,
    null);
    builder.insertImage(op.getAsBufferedImage());
}
doc.save("out.doc");

You can download JAI from here.
https://docs.aspose.com/words/java/system-requirements/#optional-dependencies

Also GIF images are not natively supported. You can insert GIF image into the document but it will be converted to PNG during inserting.

Best regards.

Hi **alexey.noskov,

May I have the list of the image file format that are supported?

Many thanks.

Best Regards,

Vincent**

Hi Vincent,

It’s interesting question. We have here two points of view: 1) Aspose Words for Java itself; 2) Java ImageIO framework installed on the host computer.

There are three image types from Aspose Words point of view:

  1. MS Word native (can be stored directly in model): jpeg, png, pict.

  2. Windows Metafiles (can be stored directly in model): emf and wmf.

  3. MS Word non-native (have to be converted (to png) before stored in model): gif, tiff, bmp.

From other point of view, Java framework installed on the host computer can support different sets of image formats. For instance, core java 1.4 supports reading of jpeg, png, gif and writing jpeg and png. Java 1.5 additionally supports reading and writing bmp and wbmp. Java 1.6 adds writing of gif.

But you can install ImageIO plug-ins that will support additional image formats. For instance, Sun’s JAI library supports reading/writing of bmp, gif, jpeg, jpeg2000, png, pnm, raw, tiff, wbmp. For details see https://docs.aspose.com/words/java/system-requirements/#optional-dependencies . We do not include JAI in Aspose Words download because it has different distributives for different platforms (since it optimized for best performance on each platform).

Windows metafiles supported by Aspose Words itself, so you don’t need in plugins for metafiles.

So, resume: you better use jpeg and png in your documents since they are stored directly in model and will be supported in any java host computer.

Best regards,

I can only add that GIF and TIFF images are supported by MS Word, but they were only natively supported in MS Word 2002 or so. E.g. it was possible to select a GIF or TIFF image in MS Word 97, but it was internally converting it to PNG.

Aspose.Words generates documents that can be read by MS Word 97-2007 therefore we go for the least common denominator and don’t write GIF or TIFF images directly into a document. That’s why we convert them to PNG. MS Word also supports BMP, but BMPs are usually huge and we convert them to PNG as well. PNG is a lossless compression and there is no harm to the image, the document only gets smaller.

Aspose.Words for .NET automatically converts GIF, TIFF and BMP to PNG and uses .NET Image classes to do that. As Konstantin has explained this works differently in Aspose.Words for Java. You need to convert GIF, TIFF and BMP? to PNG yourself because we do not include JAI in Aspose.Words.

For the list of the image formats see https://reference.aspose.com/words/java/com.aspose.words/ImageType

I see an opportunity to improve here. I think being able to insert GIF, TIFF or BMP directly using Aspose.Words and not using any other conversion library will be a great feature to have in Aspose.Words for Java and I will log this request.

The issues you have found earlier (filed as WORDSNET-5557) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(6)