Free Support Forum - aspose.com

"Error! Missing test condition" When converting DOC to PDF containg image

I have a word document which contains an image file.

The path of the image file is populated in a merge field.

This image appears fine when opening it as a Word Doc. However as soon as Aspose is used to convert it to PDF, the following appears instead of the image: "Error! Missing test condition"

The merge field is as follows

{ IF { INCLUDEPICTURE { IF TRUE "{MERGEFIELD "ImagePath""}"} \d }{INCLUDEPICTURE { IF TRUE "{MERGEFIELD "ImagePath""}"} \d}}

Again, it appears fine when opening in Word, but only fails when converting to PDF using Aspose.

I have also tried a more simple merge:

{INCLUDEPICTURE {IF TRUE "{ImagePath}"} \d }

This will allow the PDF to save an image without the above error however the image never dynamically updates. It appears to be a static image that was saved during creation of the mail merge template, instead of dynamically updating to the correct image.

Further to this. I followed the instructions here as a workaround to use the image:xxxxx tagv instead.

https://forum.aspose.com/t/121077

This has worked, but at the bottom of the thread it says that the issue should be resolved so I dont understand why I still have to use the image tag?

Hi,


Thanks for your inquiry. May be you can use LoadOptions.PreserveIncludePictureField property to override the default behaviour and if you need the INCLUDEPICTURE field to be preserved, for example, if you wish to update it programmatically. And of course you can use a MERGEFIELD as a child field to dynamically change the source path of the picture.

Please let us know if this solves your problem.

Best regards,

Thanks, do you mind expanding on what you mean by this? I am not familiar with the concept: "And of course you can use a MERGEFIELD as a child field to dynamically change the source path of the picture."

If it helps this is my scenario, maybe you can give me a better solution that the way I am looking at it.

We have Word documents which require images of scanned signatures. The path of the scanned signature is saved as a UNC path in the datasource.

What is the best way for Aspose to read the image from the UNC path during the mail merge, then input the image into the document?

Hi,


Thanks for your inquiry. I have attached a template Word document that contains a sample Image MERGEFIELD here for your reference. I believe you can achieve what you need after using the code suggested below:

Document doc = new
Document(@“C:\Temp\ImageTemplate.docx”);

doc.MailMerge.Execute(new string[] { "MyImageField"}, new object[] { @"C:\temp\Sample.png" });

doc.Save(@"C:\Temp\out.docx");


private class HandleImageMergeField : IFieldMergingCallback

{

void IFieldMergingCallback.FieldMerging(FieldMergingArgs args)

{

// Do nothing.

}

void IFieldMergingCallback.ImageFieldMerging(ImageFieldMergingArgs e)

{

e.ImageFileName = e.FieldValue.ToString();

}

}


Alternatively, you can use DocumentBuilder object to move the cursor to a MERGEFIELD and then insert the image there by using the following code snippet:

Document doc = new Document(@"C:\Temp\ImageTemplate.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToMergeField("MyImageField");

builder.InsertImage(@"C:\Temp\Sample.png", 200, 200);

doc.Save(@"C:\Temp\out.docx");


Please let me know if I can be of any further assistance.

Best regards,