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

Free Support Forum - aspose.com

A Mergefield into a FieldImport

Hi,

I have a model document (that i can’t modify) with this:

{ IMPORT " {MERGEFIELD logo }" \d }

when i execute the method MailMerge.Execute(data), the mergefield “logo” has the correct value (wich is a URL to a picture).

But the Field Import don’t display the picture. (blank line)

How can i display the picture?

Regards.

@SMES,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi,

Thanks for your response, there is a standalone application with the input file included (the outputs files are the results)

StandAloneMailMerge.zip

@SMES,

Thanks for your inquiry. Please use latest version of Aspose.Words for .NET 18.4 and LoadOptions as shown in following method to get the desired output. We have attached the output PDF with this post for your kind reference. 18.4-output.pdf (19.5 KB)

private static void MergeModel(Stream model, DataRow data, MailMergeCleanupOptions cleanupOption)
{
    Aspose.Words.LoadOptions loadoptions = new Aspose.Words.LoadOptions();
    loadoptions.PreserveIncludePictureField = true;
    mergedDocument = new Document(model, loadoptions);

    mergedDocument.MailMerge.CleanupOptions = cleanupOption;
    mergedDocument.MailMerge.Execute(data);
}

I think i can’t change version of aspose .Is it possible to resolve this problem with the version 17.2 ?

@SMES,

Please note that we do not provide support for older released versions of Aspose.Words. Moreover, we do not provide any fixes or patches for old versions of Aspose products either. All fixes and new features are always added into new versions of our products.

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.

Ok, i understand.
In this case, is it possible to replace in the fly the field { IMPORT " {MERGEFIELD logo }" \d } by a mergeregion (like {MERGEFIELD TableStart:Logo} { MERGEFIELD Image:ImageLogo} {TableEnd:Logo})?

@SMES,

Thanks for your inquiry. Please use the following code example to get the desired output. Hope this helps you.

private static void MergeModel(Stream model, DataRow data, MailMergeCleanupOptions cleanupOption)
{
    Aspose.Words.LoadOptions loadoptions = new Aspose.Words.LoadOptions();
    loadoptions.PreserveIncludePictureField = true;
    mergedDocument = new Document(model, loadoptions);
    DocumentBuilder builder = new DocumentBuilder(mergedDocument);

    foreach (Field field in mergedDocument.Range.Fields)
    {
        if (field.Type == FieldType.FieldIncludePicture)
        {
                     
            builder.MoveToField(field, true);
            builder.Writeln();
            //builder.MoveToField(field, false);
            builder.InsertField(@"MERGEFIELD TableStart:Logo");
            builder.InsertField(@"MERGEFIELD Image:ImageLogo");
            builder.InsertField(@"MERGEFIELD TableEnd:Logo");

            field.Start.ParentParagraph.Remove();

        }
    }

    mergedDocument.MailMerge.CleanupOptions = cleanupOption;
    mergedDocument.MailMerge.Execute(data);
}