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

Free Support Forum - aspose.com

Insert Image and Word Mailmerge Print Results/Preview

Hello,

we have a Csv file with a lot of adresses and create with Docx File and Aspose .net for every adress a PDF file.
Also we need in every document an own QR Code
So we inserted in the Docx file
<MERGEFIELD Image(100;100):MyImage>

When the user clicks in Word Review Results, he gets the error Image(100;100):MyImage not found. Is there a way to suppress this message or a workaround. The danger is, that the user press remove field.
It would also be ok, that he shows some other field of the csv File, but i don´t know how todo. Just there should be no message that the field does not exist.

Thanks for any help

Hi Martin,

I was not able to reproduce this issue at my end. Can you please share your code and sample document to reproduce the issue? It would be even better if you can create a sample application to reproduce the issue.

Best Regards,

Hello,

in the end it´s very simple. And more how to deal in Word with non existing mail fields.

Please open sample and click view mail merge result. Then Popup appears, with Mergefield Image: MyImage not exist and the user has the press several time cancel.

Is there a way that word ignore missing MergeFields (which will be filled by aspose later).

Hi Martin,

Thanks for your inquiry. I think, you can simply use the following code which clears the mail merge settings in such a way that when the document is saved, no
mail merge settings will be saved and it will become a normal document.

Document doc = new Document(MyDir + @"Seriendokument.docx");
doc.MailMergeSettings.Clear();
doc.Save(MyDir + @"out.docx");

Best regards,

Hi Awais,

first thanks for you answers. Seems that i explained it not so well.

User wants to send a lot of faxes. He exports from CRM a CSV file.
He starts Word. Open old Wordfile. Change Layout.
Look at Mail Preview. When it´s fine. Start Word Macro which start an
exe which creates by aspose the PDF files.

So how to deal with the Mailmerge Field Image:MyImage. I can´t do it in Aspose. It´s too late
and the user wants to reuse the Word file. So just clearing Mailsettings wouldn´t fit or i don´t get the point.

The only workaround seems no for me. To change Image Mail Field with a constant. Find it by code. Parse it to get picture size. Insert picture manually and remove constant text. Is there no easier way. I just want to supress the message ‘that the Field does not exist’ not appears?

Hi Martin,

Thanks for your inquiry. You can find an Image mergefield and then replace it with actual image by using the following code:

Document doc = new Document(MyDir + @"Seriendokument.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection fields = doc.GetChildNodes(NodeType.FieldStart, true);
foreach (FieldStart fieldStart in fields)
{
    if (fieldStart.FieldType == FieldType.FieldMergeField)
    {
        string fieldCode = fieldStart.GetField().GetFieldCode();
        if (fieldCode.Contains("Image(") && fieldCode.Contains(":"))
        {
            //parse fieldCode and extract width and heigh values
            double imgWidth = 100;
            double imgHeight = 100;
            string fieldName = fieldCode.Split(new char[] { ':' })[1].Split(new char[] { ' ' })[0];
            builder.MoveToMergeField(fieldName);
            Shape img = builder.InsertImage(MyDir + "out.001.png");
            img.Width = imgWidth;
            img.Height = imgHeight;
        }
    }
}
doc.Save(MyDir + @"out.pdf");

I hope, this helps.

Best regards,