Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Feb 03, 2016 11:01 pm

I am attempting to use to get the INCLUDEPICTURE working with a mail merge and was wondering if you had any suggestions, or if my only option is to convert everything to the <<Image:Item>> that works fine for me, I just have a ton of docs and a ton of merged items, and would prefer not to convert them all if possible.

Basically, we are using this tag in our Word template { INCLUDEPICTURE "{ MERGEFIELD filepath \* MERGEFORMAT }" \* MERGEFORMAT \d }. This approach works fine using the Office COM stuff, rendering the proper NEW image, the catch was we had to tell Office to ActiveDocument.Fields.Update() before the Word merge for the images to update.

I was hoping this was going to work the same with Spire.Doc however when we run the mail merge it is replaced with { INCLUDEPICTURE "filepath" \* MERGEFORMAT \d } perfect, however the doc still shows the original image that it was bound to and not the new filepath. I was hoping the document.IsUpdateFields would also update these INCLUDEPICTURE items but it doesn't. Any idea how I might be able to auto refresh these images or am I stuck converting all my merge items to <<Image:filepath>>?

Thanks for the help!

sdbbell
 
Posts: 5
Joined: Tue Dec 29, 2015 5:59 pm

Thu Feb 04, 2016 3:58 am

Hi,

Thanks for your posting and using our Spire.Doc component.
Sorry that we don't support the field({ INCLUDEPICTURE "{ MERGEFIELD filepath \* MERGEFORMAT }" \* MERGEFORMAT \d }) at present, but we have added it as new feature into our schedule. We will tell you when it is supported.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Thu Feb 04, 2016 6:56 am

So I am going ahead and trying to convert one of my docs into the <<Image:filename>> technique and it is working with them all converted however I have no way to control the size of the image from the merge item it seems. With the INCLUDEPICTURE technique the image inserted would scale down to the size of the INCLUDEPICTURE item, this was super helpful as not all images were scaled properly to fix on the pages.

When I convert everything over to the <<Image>> way all the images are the size of their respective files, so some of them don't fit on the page. Now I know I could change the size of the original image going in, but that would require a ton of code changes as well as new code to re-size images from other sources. Is there a way for me to control the width and height of the image?

Without some kind of control over this I might have to find a new solution (which I really don't want to do), do you have any kind of timeline to get the INCLUDEPICTURE support? Possibly even a one off hotfix build if it's not something that is too hard?

Trying to figure out other solutions if you have any suggestions. :|

sdbbell
 
Posts: 5
Joined: Tue Dec 29, 2015 5:59 pm

Thu Feb 04, 2016 7:49 am

Hi,

Please try the following solution to set size of image.
Code: Select all
  public  void mailmerge()
    {
        string input = "..\\..\\template.docx";
            Document doc = new Document();
            doc.LoadFromFile(input);
            string[] filedNames = { "photo1", "photo2" };
            string[] filedValues = { "..\\..\\spire.doc.png", "..\\..\\spire.pdf.png" };

            doc.MailMerge.MergeImageField += new MergeImageFieldEventHandler(MailMerge_MergeImageField);
            doc.MailMerge.Execute(filedNames, filedValues);
            doc.SaveToFile("ResultPictureField.docx", FileFormat.Docx2010);
            System.Diagnostics.Process.Start("ResultPictureField.docx");
        }
        public  void MailMerge_MergeImageField(object sender, MergeImageFieldEventArgs field)
        {
            //set size of picture
            field.PictureSize = new SizeF(100, 100);
        }


Our dev team is investigating INCLUDEPICTURE feature. Sorry that we have no timeline for supporting it now.
We will inform immediately you once it is supported.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Thu Feb 04, 2016 8:32 am

So until I can get a complete change over to the new <<Image>> tags I have devised a hack that kind of does what I need, I need to do some more testing to make sure it is multi thread-able but it seems to be allowing me to work with INCLUDEPICTURE and it might give some insight for your developers.

Before we were using the native Office framework, but when trying to multi-thread it, it was failing on the mail-merge part. So now I am using the Spire.DOC to do my mail-merge and at the very end just a quick open, ActiveDocument.Fields.Update(), and save with the native Office framework. This updates all the INCLUDEIMAGES in the Word file with the image from the path that was merged in on the mail-merge so when I do the PDF conversion all the images are correct and sized to the proper sizes.

I know it's a hack but its working. I'd still like to have native support so your IsUpdateFields property will refresh the image on INCLUDEPICTURE tags, this would eliminate me having to use the Office framework at all. But for now it will suffice.

Thanks for all the help and letting me bounce these ideas off you, I think we are getting somewhere!

sdbbell
 
Posts: 5
Joined: Tue Dec 29, 2015 5:59 pm

Thu Feb 04, 2016 8:43 am

Hi,

Thanks for your response.
Please feel free to write to us if you have any problems when using our Spire.Doc.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Fri Feb 26, 2016 8:34 am

Hi,

Thanks for your waiting.
The issue about { INCLUDEPICTURE "{ MERGEFIELD filepath \* MERGEFORMAT }" \* MERGEFORMAT \d } has been resolved.
Welcome to download and test Spire.Doc Pack(hot fix) Version:5.6.34.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Fri Feb 26, 2016 5:46 pm

*EDIT*

Forgot to turn on IsUpdateFields.

It works now, just one thing. Would it be possible to keep the merged in images the same size as the placeholders that were in the doc before the merge takes place? Right now it is merging in the images good but keeping them at their image size so some of them blow apart the doc as they are way larger width and height than the placeholder image.

Thanks for all the help with this!

sdbbell
 
Posts: 5
Joined: Tue Dec 29, 2015 5:59 pm

Mon Feb 29, 2016 5:53 am

Hi,

Thanks for your feedback.
Please share your testing documents to show your issue. Thank you.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc