I am having trouble inserting images when there is a drawing canvas on a word document. Basically, I have this program that will look for the location of a text box and replace the text box with an image. When the text box is in a drawing canvas I get the following error: The node must be a paragraph or a direct child of a paragraph. For free
technical support, please post this error and the file in the Aspose.Words
Forums https://forum.aspose.com/c/words/8.
When the text box is not in the drawing canvas my code works fine. Is there anything special that I have to do to access text boxes in a drawing canvas?
Here is my code (VB.NET
):
Try
Dim x As Integer
Dim objNC As Aspose.Words.NodeCollection
Dim objNode As Aspose.Words.Node
Dim objShape As Aspose.Words.Drawing.Shape
Dim y As Integer
Dim objdoc As New Aspose.Words.Document("C:\temp\test.doc")
Dim objDB As Aspose.Words.DocumentBuilder = New Aspose.Words.DocumentBuilder(objdoc)
objNC = objDB.Document.GetChildNodes(Aspose.Words.NodeType.Shape, True)
x = objNC.Count 'keep track of number of shapes
For y = 0 To x 'checks each node since removing a text box node exits the objNode loop
For Each objNode In objNC
'set the shape equal to the node
objShape = objNode
objDB.MoveTo(objShape)
Try
objShape = objDB.InsertImage(System.Drawing.Image.FromFile("c:\Temp\logo.jpg"), objShape.RelativeHorizontalPosition, objShape.Left, objShape.RelativeVerticalPosition, objShape.Top, objShape.Width, objShape.Height, objShape.WrapType.Square)
Catch ex As Exception
MsgBox("Invalid image " & ex.Message)
Exit For
End Try
objNode.Remove()
Next
Next
'save the file
objDB.Document.Save("c:\Temp\TestProduct.doc")
Catch ex As Exception
MsgBox("Unable to add image " & ex.Message)
End Try