Hi,
We are trying to convert Docx into Html which has image inside Textbox, there is a problem with Image alignment.
This happen only in case if In layout Horizontal alignment is set to other.
And can you help us in getting / setting the above stuff via Aspose
Kindly help in solving this issue.
Attached sample DOC
Regards,
Divesh Salian
Hi Divesh,
Thanks for your inquiry. Please note that Aspose.Words tries to mimic the same behavior as MS Word do. MS Word format and HTML formats are quite different so sometimes it’s hard to achieve 100% fidelity. Please try to convert your document to HTML by using MS Word, you will get almost same results.
Upon processing HTML, some features of HTML might be lost. You can find a list of limitations upon HTML exporting/importing here:
https://docs.aspose.com/words/net/load-in-the-html-html-xhtml-mhtml-format/
https://docs.aspose.com/words/net/save-in-html-xhtml-mhtml-formats/
Please use the following code snippet to set the shape’s HorizontalAlignment and RelativeHorizontalPosition value. Hope this solve your problem.
https://reference.aspose.com/words/net/aspose.words.drawing/groupshape/
Document doc = new Document(MyDir + "19439_GraphicsInsideTextBoxes.docx");
foreach (Shape shp in doc.GetChildNodes(NodeType.Shape, true))
{
shp.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Right;
shp.RelativeHorizontalPosition = RelativeHorizontalPosition.Margin;
}
doc.Save(MyDir + @"out.html");
Please let us know if you have any more queries.
Thanks a lot It would definately help us.
We just want this to happen if horizontal alignment is set to “other” in word doc.
Attached snapshot of the setting in MS word
As we are not able to find that in Aspose… Can help us with that.
1 more question What are different Type of NodeType available for TextBox. (E.g. DrawingML, Run etc.)
Regards,
Divesh
Hi Divesh,
Thanks for your inquiry. Please use the following code snippet for your requirements.
Shape.BehindText property specifies whether the shape is below or above text.
HorizontalAlignment : Specifies horizontal alignment of a floating shape, text frame or floating table.
Document doc = new Document(MyDir + "in.docx");
foreach (Shape shp in doc.GetChildNodes(NodeType.Shape, true))
{
// horizontal alignment of a floating shape
if (shp.HorizontalAlignment == Aspose.Words.Drawing.HorizontalAlignment.None)
{
shp.HorizontalAlignment = Aspose.Words.Drawing.HorizontalAlignment.Right;
shp.RelativeHorizontalPosition = RelativeHorizontalPosition.Margin;
// Make the image float, put it behind text and center on the page.
shp.WrapType = WrapType.None;
shp.BehindText = true;
}
}
doc.Save(MyDir + @"out.docx");
Please note that Aspose.Words is quite different from the Microsoft Word’s Object Model in that it represents the document as a tree of objects more like an XML DOM tree. If you worked with any XML DOM library you will find it is easy to understand and work with Aspose.Words. When you load a Word document into Aspose.Words, it builds its DOM and all document elements and formatting are simply loaded into memory. Please read the following articles for more information on DOM:
https://docs.aspose.com/words/net/aspose-words-document-object-model/
https://docs.aspose.com/words/net/logical-levels-of-nodes-in-a-document/
Shape represents an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture. Shapes that can have text, can contain Paragraph and Table nodes as children and a Paragraph node may have DrawingML node. Please see the attached image for DOM of your document.
Paragraph is a block-level node and can be a child of classes derived from Story or InlineStory. The complete list of child nodes that can occur inside a paragraph consists of BookmarkStart, BookmarkEnd, FieldStart, FieldSeparator, FieldEnd, FormField, Comment, Footnote, Run, SpecialChar, Shape, GroupShape, SmartTag.
Please check the list of node type from here:
https://reference.aspose.com/words/net/aspose.words/nodetype/