Conversion from MHTL to DOCX not scaling and positioning images properly

Hi,

I’m using the current version of Aspose.Words to convert an mhtml file to docx:

var loadOptions = new Aspose.Words.HtmlLoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml;

var filePath = @"D:\DOWNLOAD\TestDocs\Msg\ADEM\50 tree top hill.mhtml";
var document = new Aspose.Words.Document(filePath, loadOptions);

document.Save(Path.ChangeExtension(filePath, ".docx"));

See downloadable input and saved output files: Files.zip

How can I save the docx file so that the images inside the mhtml are scaled property to the page (in the same way they would be when viewing the mhtml file in a browser), instead of showing half the image on the page and adding an empty page into the docx?

@ted-1,

You can build logic on the following C# code of Aspose.Words for .NET API to fit MHTML images within the Page bounds of Word document:

var loadOptions = new Aspose.Words.HtmlLoadOptions();
loadOptions.LoadFormat = Aspose.Words.LoadFormat.Mhtml;
Document doc = new Document("C:\\temp\\Files\\50 tree top hill.mhtml", loadOptions);
ShrinkImageToFit(doc);
doc.Save("C:\\Temp\\Files\\21.3.docx");

private static void ShrinkImageToFit(Document doc)
{
    PageSetup ps = doc.FirstSection.PageSetup;
    double contentWidth = ps.PageWidth - (ps.LeftMargin + ps.RightMargin);
    double contentHeight = ps.PageHeight - (ps.TopMargin + ps.BottomMargin);

    NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
    foreach (Shape shape in shapes)
    {
        double imageHeight = shape.Height;
        double imageWidth = shape.Width;
        double vScale = 1;
        if (imageHeight > contentHeight)
        {
            vScale = contentHeight / imageHeight;
        }
        double hScale = 1;
        if (imageWidth > contentWidth)
        {
            hScale = contentWidth / imageWidth;
        }
        double scale = Math.Min(hScale, vScale);
        double imageHeight2 = imageHeight *= scale;
        double imageWidth2 = imageWidth *= scale;

        try
        {
            shape.Height = imageHeight2;
            shape.Width = imageWidth2;
        }
        catch (Exception e)
        {

        }
    }
}

It would be nice if Aspose.Words did this automatically, so that the MHTML file converted to Word in the same manner it views in the browser. This is a lot of work to override like this, and who knows what other sorts of graphics this will be required for?

@ted-1,

We have logged your requirement in our issue tracking system. Your ticket number is WORDSNET-21946. We will further look into the details of this requirement and will keep you updated on the status of the linked ticket.