We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Object Model Changed for Image Paragraph

Hi there..I used to be able to use this code to mail merge a document with pictures but the WordImageParagraph class no longer exists in 17.4.0.39. What has it changed to?



 //Opens the Word template document
            using (WordDocument document = new WordDocument(assembly.GetManifestResourceStream(resourceName), FormatType.Docx))
            {
                Dictionary<WParagraph, int> pictureFieldsData = new Dictionary<WParagraph, int>();

                var list = new List<WordImageParagraph>();

                document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(
                    delegate (object sender, MergeImageFieldEventArgs args)
                    {
                        //Get the image from disk during Merge.
                        if (args.FieldName == "ClientSignature" || args.FieldName == "UserSignature")
                        {
                            if (args.FieldName == "ClientSignature" && this.Item?.Client.Signature == null)
                            {
                                args.ImageStream = new MemoryStream();
                                return;
                            }

                            if (args.FieldName == "UserSignature" && App.UserInfo?.Signature == null)
                            { 
                                args.ImageStream = new MemoryStream();
                                return;
                            }


                            args.ImageStream = args.FieldName == "ClientSignature" ?
                                new MemoryStream(this.Item?.Client.Signature) :
                                new MemoryStream(App.UserInfo.Signature);

                            WParagraph paragraph = args.CurrentMergeField.OwnerParagraph;

                            if (paragraph != null)
                            {
                                //had to change this code as we were getting duplicate OwnerParagraphs added to the dictionary
                                //pictureFieldsData.Add(paragraph, paragraph.Items.IndexOf(args.CurrentMergeField));
                                list.Add(new WordImageParagraph { Paragraph = paragraph, Index = paragraph.Items.IndexOf(args.CurrentMergeField) });
                            }
                        }
                        


                    });

                document.MailMerge.ExecuteGroup(this.GetMailMergeDataTable());

              

                foreach (var item in list)
                {
                    WParagraph paragraph = item.Paragraph as WParagraph;

                    //Fields are updated with pictures.
                    //Gets picture from the index of image field.
                    WPicture picture = paragraph.Items[item.Index] as WPicture;
                    if (picture != null)
                    {
                        //Changes the size of picture.
                        picture.Height = 40;
                        picture.Width = 65;
                    }
                }


                MemoryStream stream = new MemoryStream();

                //Saves the Word file to MemoryStream
                document.Save(stream, FormatType.Docx);

                return stream;
            }

1 Reply

MR Manikandan Ravichandran Syncfusion Team February 10, 2020 12:49 PM UTC

Hi Mario,

Thank you for contacting Syncfusion.

We are unable to reproduce the mentioned issue at our end with given details. For your reference we have attached the sample which we have tried at our end to reproduce the mentioned issue.

Sample Link
https://www.syncfusion.com/downloads/support/forum/151360/ze/XamarinFormsApp1712152682

So, kindly provide us complete runnable sample and input document used at your end to reproduce the mentioned issue, so that we can proceed further to analyse and update you with the appropriate details.

Note: If you have any confidential data in your Word document, please replace with some dummy data and provide us the same. We just need your document to recreate the problem you face.

Please let us know if you have any other questions.

Regards,
Manikandan Ravichandran
 


Loader.
Live Chat Icon For mobile
Up arrow icon