We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert image to ControlImage(a kind of Content Control) in docx?

Hi everybody,

I have a problem as below:
- I insert a building block to document. The building block contains some content controls(Action, Label, ControlImage, …).
- I need to insert an image to ControlImage of the building block by Aspose Word.

Can Aspose word do that?


Thanks and best regards!

Hello

Thanks for your request.

You can use DocumentBuilder.InsertImage method to insert Image. For instance the following code demonstrates how you can insert Image into Content control:

// Open the document.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Document doc = new Document("C:\\Temp\\in.doc");

// Create DocumentBuidler object, it will help use to insert Image.

DocumentBuilder builder = new DocumentBuilder(doc);

// Get content contorl where you would like to insert Image.

// Currently there is no way to identify content controls by title or tag,

// so to demonstrate the technique I just get the first SDT

StructuredDocumentTag sdt = (StructuredDocumentTag)doc.GetChild(NodeType.StructuredDocumentTag, 0, true);

// Remove old content from the SDT

sdt.RemoveAllChildren();

// Now, create an empty paragraph and append it to the content control

sdt.AppendChild(new Paragraph(doc));

// Move DocumentBuilder cursor to the first child of SDT (newly created paragraph)

builder.MoveTo(sdt.FirstChild);

// Insert Image

builder.InsertImage("C:\\Temp\\img.jpg");

// Save output

doc.Save("C:\\Temp\\out.doc");

But unfortunately, currently there is no way to identify content controls by title or tag. We plan to provide more control over SDT in one of the nearest version of Aspose.Words. I linked your request to the appropriate issue. We will let you know once it is supported.

Hope this could help you to achieve what you need.

Best regards,

Thanks AndreyN for your reply.
I tried your code, no error for the cpde. But the output doc can not be opened?
I dont know the reason why. Could you tell please why?


Thanks!

Hi there,

Thanks for this additional information. Could you please attach your input document and code here for testing?

Thanks,

Thanks aske012,

I found the the way to insert image to content control(Also base on your co-worker’s code, but change some things).
If you need to verify my changed code; please feel free to let me know, I’ll put the code.

Thanks for support!

Hi

Thank you for additional information. It is perfect that you already resolve the problem. Please let us know in case of any issue, we will be glad to help you.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Best regards,

The issues you have found earlier (filed as WORDSNET-4010) have been fixed in this .NET update and this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(11)