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

Free Support Forum - aspose.com

Table and Image is Rendered outside of the Page | MHT to PDF Conversion using Java

Hi,

I’m using Aspose.Net nuget C#, and a want to convert MHT file to PDF.
In my case, the MHT is converting to PDF but in my page a don’t see the entire image and table. (because it’s to big)

TR Relev des heures semaine 24.zip (520.8 KB)

With the online converter the render is good (all is in the page) : https://products.aspose.app/pdf/fr/conversion/mht

Using : aspose.pdf\21.6.0

Thx
Eric

@ericbesson

The PDF file is generated by Aspose.Words.

Please use Aspose.Words for .NET with following code example to get the desired output.

Document doc = new Document(MyDir + "TR Relevé des heures semaine 24.mht");
foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
    ResizebigImage(shape);
}

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
    table.PreferredWidth = PreferredWidth.FromPercent(100);
}

doc.Save(MyDir + "21.6.pdf");
public static void ResizebigImage(Shape image)
{
    // Return if this shape is not an image.
    if (!image.HasImage)
        return;

    // Calculate the free space based on an inline or floating image. If inline we must take the page margins into account.
    PageSetup ps = image.ParentParagraph.ParentSection.PageSetup;
    double freePageWidth = image.IsInline ? ps.PageWidth - ps.LeftMargin - ps.RightMargin : ps.PageWidth;
    double freePageHeight = image.IsInline ? ps.PageHeight - ps.TopMargin - ps.BottomMargin : ps.PageHeight;


    ImageSize size = image.ImageData.ImageSize;
    Boolean exceedsMaxPageSize = size.WidthPoints > freePageWidth || size.HeightPoints > freePageHeight
        || image.Width > freePageWidth || image.Height > freePageHeight;

    if (exceedsMaxPageSize)
    {
        // Set the new size.
        image.AspectRatioLocked = true;
        image.Width = ps.PageWidth - ps.LeftMargin - ps.RightMargin;
    }
}

It’s works perfectly :slight_smile:
Thx verry much