We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Can't convert TIF images with JPEG compression

I cannot get Aspose.Words to convert a TIFF image when it is using JPEG compression (i.e. go to the TIF’s property details and note that the compression="JPEG).

Instead of showing the image, it just shows a gray page.

The default windows image viewer also shows just a gray page instead of the actual image. However, if I use a competitor’s product, the image is converted to PDF just fine. I read that GDI+ has issues with TIF’s that have JPEG compression, so I think the problem has something to do with that. I’m assuming the competing product doesn’t use GDI+.

Here is my code.


// Create Aspose.Words.Document and DocumentBuilder.
// The builder makes it simple to add content to the document.
var document = new Aspose.Words.Document();
var builder = new DocumentBuilder(document);

// Read the image from file, ensure it is disposed.
using (var image = Image.FromStream(stream))
{
// Find which dimension the frames in this image represent. For example
// the frames of a BMP or TIFF are “page dimension” whereas frames of a GIF image are “time dimension”.
var dimension = new FrameDimension(image.FrameDimensionsList[0]);

// Get the number of frames in the image.
var framesCount = image.GetFrameCount(dimension);

// Loop through all frames.
for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
{
// Insert a section break before each new page, in case of a multi-frame TIFF.
if (frameIdx != 0)
builder.InsertBreak(BreakType.SectionBreakNewPage);

// Select active frame.
image.SelectActiveFrame(dimension, frameIdx);

// We want the size of the page to be the same as the size of the image.
// Convert pixels to points to size the page to the actual image size.
// However, the maximum the height or width can be is 1584pt (see Aspose.Words.DocumentBuilder's InsertImage Method Page Size Limitations)
PageSetup ps = builder.PageSetup;
ps.PageWidth = Math.Min(ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution), 1584);
ps.PageHeight = Math.Min(ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution), 1584);

// Insert the image into the document and position it at the top left corner of the page.
builder.InsertImage(
image,
RelativeHorizontalPosition.Page,
0,
RelativeVerticalPosition.Page,
0,
ps.PageWidth,
ps.PageHeight,
WrapType.None);
}
}
document.Save(tempFilePath);

Hi Joshua,


Thanks for your inquiry. Could you please attach your sample TIFF and output document showing the undesired behavior here for testing? We will investigate the issue on our end and provide you more information.

Best regards,