Hi,
I have created a word document using “DocumentBuilder.InsertHtml(Mycontent)”.In this content i have images too (i.e ). My question is how to align (for instance:align to right of the text) and wrap the image (for instance: square or tight …). If it is a single image i can use InsertImage method but i have lot of images.How to do it.Can you help.
Hi,
Thanks for your inquiry. I think, you need to implement INodeChangingCallback interface if you want to change settings of the Shape object i.e. being inserted via InsertHtml method. Please try run the following code snippet:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
HandleNodeChanging handler = new HandleNodeChanging();
doc.NodeChangingCallback = handler;
builder.InsertHtml("<img src'test,png' />");
foreach(Shape shape in handler.InsertedShapes)
shape.WrapType = WrapType.Inline;
doc.Save(@"C:\Temp\out.doc");
public class HandleNodeChanging: INodeChangingCallback
{
void INodeChangingCallback.NodeInserted(NodeChangingArgs args)
{
if (args.Node.NodeType == NodeType.Shape)
mInsertedShapes.Add(args.Node);
}
void INodeChangingCallback.NodeInserting(NodeChangingArgs args)
{
// Do Nothing
}
void INodeChangingCallback.NodeRemoved(NodeChangingArgs args)
{
// Do Nothing
}
void INodeChangingCallback.NodeRemoving(NodeChangingArgs args)
{
// Do Nothing
}
public List < Node > InsertedShapes
{
get { return mInsertedShapes; }
}
private readonly List < Node > mInsertedShapes = new List < Node > ();
}
I hope, this helps.
Best regards,
Hi,
Thanks for your reply. i tried but the interface INodeChangingCallback is not in our aspose.words(4.2.3.0).
Hi,
Thanks for your inquiry. First off, you’re using a very old version of Aspose.Words; unfortunately, we don’t provide support for older released versions of Aspose.Words. We always encourage our customers to use the latest version of Aspose.Words as it contains newly introduced features, enhancements and fixes to the issues that were reported earlier. So, I would suggest you please upgrade to the latest version of Aspose.Words for .NET (13.8.0). You can download it from the following link:
https://releases.aspose.com/words/net
Best regards,
Hi,
I have tried the given code. But the handler.InsertedShapes’s count is always is zero.
I tried this
NodeCollection shapes = e.Document.GetChildNodes(NodeType.Paragraph, true);
foreach(Paragraph s in shapes)
{
if ()//> i cannot check whether the para has image.since i have image tag inside para
{
HandleNodeChanging handler = new HandleNodeChanging();
e.Document.NodeChangingCallback = handler;
foreach(Shape shape in handler.InsertedShapes)
shape.WrapType = WrapType.Inline;
}
}
para :
A move towards using the Aspose Unified Framework which dictates an improved API for loading and saving. This makes for a more organized and consistent API to be used across all Aspose products.A move towards using the Aspose Unified Framework which dictates an improved API for loading and saving. This makes for a more organized and consistent API to be used across all Aspose products
Hi,
Thanks for your inquiry. I have fixed your code; please try running the following code snippet:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
HandleNodeChanging handler = new HandleNodeChanging();
doc.NodeChangingCallback = handler;
builder.InsertHtml("A move towards using the Aspose Unified Framework which dictates an improved API for loading and saving. This makes for a more organized and consistent API to be used across all Aspose products.A move towards using the Aspose Unified Framework which dictates an improved API for loading and saving. This makes for a more organized and consistent API to be used across all Aspose products
NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);
foreach(Paragraph para in paragraphs)
{
NodeCollection shapesInPara = para.GetChildNodes(NodeType.Shape, true);
if (shapesInPara.Count > 0) // --> i cannot check whether the para has image.since i have image tag inside para
{
foreach(Shape shape in handler.InsertedShapes)
shape.WrapType = WrapType.Inline;
}
}
doc.Save(@"C:\Temp\out.docx");
I hope, this helps.
Best regards,
Thanks,
it worked. I have inserted the html in table format.so the images are not aligned well. i changed the code to builder.write.