Filling Form Field Image

Hello, we have a word document which contains Form-Field from type Image.

We didn’t find a way to replace the Form-Field-Image with a Image (e.g. Logo etc.) .
Is there a possible way of function to do this with Aspose.Words ?

Thanks,

@VolkerJahns

Could you please ZIP and attach your input and expected output documents? We will then provide you code example according to your requirement.

AsposeWordDemoFormFields.zip (19.1 KB)

Hello, please find attached Word-Document which we try to proceed.
You will find several form-fields on it.

We are trying to fill now content into these fields but weren’t able to do that with aspose-Words.
Can you show us, how we can replace / add content to such fields:

  • Add image into the form-field-image
  • Add text into form-field-text

Our program should open this document, analyse which fields with “Our” Tags exist and then replace values from Database .

Thanks,

@VolkerJahns

Your document contains content controls. You can use StructuredDocumentTag.Title property to get the title of content control e.g. User.Name. Following code example shows how to update content control of type image and text.

We suggest you please read the following article. Hope this helps you.
Working with Content Control SDT

Document doc = new Document(MyDir + "AsposeWordDemoFormFields.docx");
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
    if (sdt.SdtType == SdtType.Picture)
    {
        Shape _shape = (Shape)sdt.GetChild(NodeType.Shape, 0, true);
        _shape.ImageData.SetImage(MyDir + @"in.png");
    }
    else if (sdt.SdtType == SdtType.PlainText || sdt.SdtType == SdtType.RichText)
    {
        if (sdt.Level == MarkupLevel.Inline)
        {
            Run run = (Run)sdt.FirstChild.Clone(false);
            run.Text = "New text of content control";

            sdt.RemoveAllChildren();
            sdt.AppendChild(run);
        }
        else if (sdt.Level == MarkupLevel.Block)
        {
            Paragraph paragraph = (Paragraph)sdt.FirstChild.Clone(true);
            paragraph.Runs[0].Text = "New text of content control";

            sdt.RemoveAllChildren();
            sdt.AppendChild(paragraph);
        }
    }
    else if (sdt.SdtType == SdtType.Checkbox)
    {
        sdt.Checked = true;
    }
}

doc.Save(MyDir + @"19.11.docx");