Converting to tiff changed after upgrading Words 14.2 to 15.7

Hi,

As can be seen in the title, after updating the Aspose Words 14.2 to 15.7, we noticed some issues when converting files to tiff. This only goes for existing tif / tiff images and files we’ve extracted from a .zip or .7z file.
When inputting an image the outputs are as follow:

  • Words 14.2: image equal to input
  • Words 15.7: image is shrunk to the top left corner of the page, about a quarter of the page.

Keep in mind that the piece of code below is used for multiple types of images, not just tiff. (Including bmp, png, jpeg, tiff, and gif)

Let’s just focus on the tiff to tiff for now - one may want to convert this to e.g. lower the resolution, but for now we input a tiff and want the same image as an output.

Code
Where:

  • “Data” is a MemoryStream containing the file.
  • "MAX_PAGE_ … " equals 1584, as taken somewhere from the Aspose documentation. The CalculateImageSize is never reached in this example though.
// create the document - no data
document = new Document();

// we use the builder to fill the document
DocumentBuilder builder = new DocumentBuilder(document);

// load the input image from the stream
using (System.Drawing.Image image = System.Drawing.Image.FromStream(Data))
{
    // 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". 
    FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);

    // Get the number of frames in the image.
    FrameDimension fd = this.Type == FileType.GIF ? FrameDimension.Time : FrameDimension.Page;
    int framesCount = image.GetFrameCount(fd);

    // 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);

        double imageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
        double imageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);

        // If the image is larger than the maximum size for word document: shrink the image.
        if (imageWidth >= Words.MAX_PAGE_WIDTH || imageHeight >= Words.MAX_PAGE_HEIGHT)
            // Shrink the image
            CalculateImageSize(image, Words.MAX_PAGE_HEIGHT, Words.MAX_PAGE_WIDTH, out imageHeight, out imageWidth);

        // 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.
        PageSetup ps = builder.PageSetup;
        ps.PageWidth = imageWidth;
        ps.PageHeight = imageHeight;

        // 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);
    }
}

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
// any resolution
// any compression

document.Save(*Some other Stream *, options);

End Code

If there are any questions, let me know.

Cheers,
Knots

Hi Knots,

Thanks for your inquiry. Your inquiry pertains to Aspose.Words, so I am moving it to related forum. My Aspose.Words colleague will look into it and guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

Hi Knots,

Thanks for your inquiry. Could you please attach your input and output Tiff files here for testing? I will investigate the issue on my side and provide you more information.

Hello again,

Attached you’ll find a sample image.

Regards,
Knots

Hi Knots,

Thanks
for sharing the detail. I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-12462. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved. We apologize for your inconvenience.

Please use the following highlighted code as a workaround of this issue. Hope this helps you.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Read the image from file, ensure it is disposed.
using (Image image = Image.FromFile(MyDir + "Tiff-13p.tif"))
{
    // Get the number of frames in the image.
    int framesCount = image.GetFrameCount(FrameDimension.Page);
    // 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(FrameDimension.Page, frameIdx);
        // Max page size
        const double maxPageHeight = 1584;
        const double maxPageWidth = 1584;
        double currentImageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
        double currentImageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
        if (currentImageWidth >= maxPageWidth || currentImageHeight >= maxPageHeight)
        {
            // Get max image size.
            CalculateImageSize(image, maxPageHeight, maxPageWidth, out currentImageHeight, out currentImageWidth);
        }
        // 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.
        PageSetup ps = builder.PageSetup;
        ps.PageWidth = currentImageWidth;
        ps.PageHeight = currentImageHeight;
        // Insert the image into the document and position it at the top left corner of the page.
        Shape shape = builder.InsertImage(
        image,
        RelativeHorizontalPosition.Page,
        0,
        RelativeVerticalPosition.Page,
        0,
        currentImageWidth,
        currentImageHeight,
        WrapType.None);
        shape.Width = currentImageWidth;
        shape.Height = currentImageHeight;
    }
}
doc.Save(MyDir + "Out.tiff");

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

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