Image and Text Formatting - Mail Merge

Hello there,

I have a document which contain various codes, two of which look like:
[XFO = AN]
[WAITPHOTO]

[XFO=AN] specifies the Image code which identifies the Image to be placed.
[WAITPHOTO] specifies the formatting of text around Image.

Details of these two codes are in the attached document along with examples for both.

I need to run mail merge for such documents keeping in state the formatting, template asks for.

Could you please guide how can I do above.
Replacing [XFO=AN] with Image Merge field and then replacing it with actual Image during Mail Merge is fine but if you can suggest anything regarding formatting on the basis of additional code
[WAITPHOTO], would be great.

Thanks in advance!

Hi

Thanks for your inquiry. Maybe in your case it is better to insert images and text during find and replace process. In this case, you will be able to parse your “magic” tags and set the appropriate formatting to images and text.
Best regards.

In that case also, if you can suggest me how can I wrap text around Image on the basis of presence/absence of my magic tag [WAITPHOTO], it would be great.

To apply Image formatting, I need to verify the presence/absence of [WAITPHOTO] tag after [XFO=BS] tag with possibly one paragraph in between them. Please see my earlier attached document for detail.

Further, there may be multiple [XFO…] tags each with their own possible [WAITPHOTO] tag,
So also need a way if a particular [XFO…] tag is followed by [WAITPHOTO] tag.

Thank you!

Hi

Thank you for additional information.

  1. I think, you can just specify WrapSide and WrapType of shape to achieve this.
    https://reference.aspose.com/words/net/aspose.words.drawing/shapebase/wraptype/
    https://reference.aspose.com/words/net/aspose.words.drawing/shapebase/wrapside/
  2. I think, you can check this using ReplaceEvaluator:
    https://reference.aspose.com/words/net/aspose.words/range/replace/

Best regards.

Thanks for your reply.

I am getting an issue while setting alignment and wrapping style around an Image.
Below is the Image Code/Placeholder:

// Image needs to be center aligned

Rule: For all Images that are coded to be ‘Center’ aligned, no wrapping around it should be done.

Code to set Alignment:

if (imageFormatting.Keys.Contains("ALIGN"))
{
    DocumentBuilder builder = new DocumentBuilder(e.Document);
    builder.MoveToMergeField(fieldName);
    Shape shape = builder.InsertImage(objImage); //Inserted Image

    string imageAlignment = imageFormatting["ALIGN"];
    if (imageAlignment == "LEFT" || imageAlignment == "RIGHT")
    {
        shape.WrapType = WrapType.Square;
        shape.BehindText = true;
    }
    else
    {
        shape.WrapType = WrapType.None;
    }

    switch (imageAlignment)
    {
        case "RIGHT":
            shape.HorizontalAlignment = HorizontalAlignment.Right;
            break;
        case "CENTER":
            shape.HorizontalAlignment = HorizontalAlignment.Center;
            break;
        default:
            shape.HorizontalAlignment = HorizontalAlignment.Left;
            break;
    }
}

Source/Output Documents are attached for your reference.

Please guide how can I make the text below Image with ‘Center’ alignment to be pushed downwards.

Thank you!

Hi

Thanks for your request. I think, in your case it is better to use inline images and specify alignment of paragraphs where the images is placed as I described here:
https://forum.aspose.com/t/80181
Best regards.

Thanks Alexey,

But I don’t want any text wrapping around this Center aligned Image.

Should I create an empty paragraph, set its alignment = Center and then Insert Image into it
Please guide.

Thank you!

Hi Nutan,

Thanks for your inquiry. I do not think, you need to insert additional paragraphs. I think it would be enough to set alignment of paragraph where mergefield is located.
Best regards.

Thanks for your reply Alexey!

Setting Paragraph alignment worked

Below is my code:

DocumentBuilder builder = new DocumentBuilder(e.Document);
builder.MoveToMergeField(fieldName);
Shape shape = builder.InsertImage(objImage);

shape.WrapType = WrapType.Inline;
Paragraph para = shape.ParentParagraph;
para.ParagraphFormat.Alignment = ParagraphAlignment.Center;

Thank you!