How to set the maximum width of pictures in word when generating word from htm
How can a picture be automatically reduced to the maximum width of a document when it exceeds the width of the document
thanks
You can build on the following code to adjust the images according to the page size:
Document doc = new Document("E:\\temp\\input.html");
PageSetup ps = doc.FirstSection.PageSetup;
foreach (Shape shape in doc.GetChildNodes(NodeType.Shape, true))
{
if (shape.HasImage)
{
if (shape.Width > ps.PageWidth)
{
shape.Width = ps.PageWidth;
shape.AspectRatioLocked = false;
}
}
}
Hope, this helps.
@awais.hafeez,
thanks,the code doesn’t work properly, and the picture still doesn’t shrink.If subtract LeftMargin and RightMargin, the results are correct.
ps.getPageWidth()-ps.getLeftMargin()-ps.getRightMargin();
It is great that you were able to find what you were looking for. Please let us know any time you have any further queries.