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)
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;
}
}
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.