Hi,
I am using Aspose Word to convert the attached html document to docx.
The issue is images used in html document are cut-off right side when docx file is generated even i have set AutoFit window property = true.
I have attached the html document as well as generated docx.
Please let me know if there is any option that i can use to generate docx document that fit within page size.
Thanks
Attachments:
Sample Hmtl.zip (1.2 MB)
Converted Document.zip (1.2 MB)
@HassanNorthbay,
You can build logic on the following C# code of Aspose.Words for .NET API to fit HTML images within the Page bounds of Word document:
Document doc = new Document("C:\\temp\\Sample Hmtl\\exhibit101-independentco.html");
ShrinkImageToFit(doc);
doc.Save("C:\\temp\\Sample Hmtl\\21.1.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)
{
}
}
}