Using MERGEFIELD and INCLUDEPICTURE fields inside IF field structure

  1. Does anyone have a link from Microsoft saying this is “by design” and not a bug?

  2. I’m merging from an application and database where I can get the currently logged-in user’s username but the database doesn’t store the image to their signature so I have a bunch of IF statements like below. Is there a way to get this to work for .DOCX? Does the “Image:” prefix idea require code changes in how the Aspose object is instantiated?

{ IF { MERGEFIELD CurrentUserName } = “JBLOW” { INCLUDEPICTURE “Signatures\JoeBlow.jpg” \d * MERGEFORMAT } }

Thanks,
Greg

@gregbrownclerk,

Unfortunately, your questions are not clear enough therefore we request you to please elaborate your inquiries further by providing complete details of your usecases. This will help us to understand your scenarios, and we will be in a better position to address your concerns accordingly.

Please also ZIP and provide your simplified Word documents (input, expected files) here for testing.

Thanks for responding. Let me try to better explain. I’m trying to merge the currently logged-in user’s digital signature (.jpg file). The only thing currently stored in the database and accessible by the application that is instantiating the Aspose objects is the currently logged-in user’s username. So, I’m translating this value to that user’s signature file/path which only resides on disk. So when the form is merged and the user is “JBLOW” the Word document then knows to merge the file located at …\Signatures\JoeBlow.jpg". I have other IF statements for each other user that will merge the form. This all works fine with .DOC file formats but not .DOCX so I found this thread about using the “Image:” prefix but couldn’t get it to work. Is that any clearer? Attached is my .DOC file zipped uptlTransferLien - ASPOSE.zip (167.3 KB)

A SQL Server stored proc is what supplies the data (except the path for the user’s signature image). Thanks!

@gregbrownclerk,

Please check these sample input/output Word documents (Docs.zip (21.0 KB)) and try running the following simple code:

LoadOptions opts = new LoadOptions();
opts.LoadFormat = LoadFormat.Doc;
opts.PreserveIncludePictureField = true;

Document doc = new Document("E:\\Temp\\in.doc", opts);

doc.MailMerge.Execute(
            new string[] { "DeputyClerkUserName" },
            new object[] { "YRAMIREZ" });

doc.Save("E:\\Temp\\19.10.docx"); 

Hope, this helps in achieving what you are looking for.

Thanks so much for the reply! Unfortunately I don’t have access to the code in the application that creates the Aspose object but I will pass it along to my vendor in hopes that this allows me to use .DOCX instead of .DOC.

@gregbrownclerk,

Please let us know if you have any troubles and we will be glad to look into this further for you.

I see Aspose.Words for .NET 18.12 has the below bug fix but does it fix the specific issue in this thread?
https://forum.aspose.com/t/doc-to-docx-includepicture-problem/95500/3

https://docs.aspose.com/words/net/aspose-words-for-net-18-12-release-notes/

(I’d test myself but our vendor is the one with the software license and they’re running v17.9 anyway)

Thanks,
Greg

@gregbrownclerk,

We worked on the following points as per WORDSNET-2163:

  • The include picture field is lost when converting to DOCX or WML
  • The include picture field changes to absolute (from relative) path when converting to DOC or RTF
  • The picture placeholder comes out wrong size when saving as RTF, but MS Word has the same result. So this is not a defect.

Secondly, I tested my previous code with the latest 21.9 version of Aspose.Words for .NET and it now produces desired output in saved DOC and DOCX formats.

Can you please tell what exact problem(s) are you getting with the latest version of Aspose.Words for .NET now?

Thanks, awais.hafeez.
When using .DOCX with an INCLUDEPICTURE where the path to the image is determined at runtime it doesn’t actually merge the image. It’s a relative path.

The below DeputyClerkUserName value comes from the database dynamically and I have a series of these IF statements to determine which JPG to display depending upon this value (which is the currently logged-in user to the application).

{ IF { MERGEFIELD DeputyClerkUserName } = “YRAMIREZ” { INCLUDEPICTURE “Signatures\YRAMIREZ.jpg” \d * MERGEFORMAT} }

@gregbrownclerk,

The latest (21.9) version of Aspose.Words for .NET works fine on my end. I have attached a sample Console Application here for your reference:

Input/Output Word documents and a sample image can be found at this path: ~\204121\bin\Debug\