Free Support Forum -

TableStart/TableEnd enclosed in IF does not work in PDF

I am trying to generate a table, but it is only supposed to be visible when a certain codition is met. I use Aspose Words to fill the mergefields in my template.
When I create a .docx file it works just fine. But if I use the same code and template to generate a .pdf file instead, it does not work.

When I have only the mergefield TableStart/TableEnd in my template, the table is generated is also generated just fine in the pdf file.

So it seems the combination of an IF around a TabeStart/TableEnd does not work for .pdf
Am I overlooking something?
Kind regards


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output PDF file that shows the undesired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi Tahir,

I’m a collegue of the person above, having taking over the investigation of the problem. The problem seems to stem from the fact that a table that’s inside an IF is not evaluated properly after the IF is resolved. We found a workaround by performing a Document.UpdateFields() after the Document.MailMerge.ExecuteWithRegions(). Attached is a ZIP with a document that’s a stripped version of the original one we used, and a short test program (C# file) that shows the problem (note that the doc.UpateFields() line should be commented out for the problem to show itself).

EDIT: It seems there’s no way to attach a file? Please tell me how I can upload the ZIP file as you mentioned above.
EDIT 2: Here’s the file: (281.5 KB)


Thanks for your inquiry. Please edit your post or reply it and use upload button as shown in attached image to upload the ZIP file. upload.png (3.0 KB)

Thanks, I updated my post above. Also in the ZIP two PDFs, one with the wrong output (creataed with the UpdateFields line commented out) and one with the right output.


Thanks for sharing the detail. In this case, you need to call the Document.UpdateFields method. The MailMerge.Execute method updates the IF field. You can save the document after calling MailMerge.Execute to check this behavior. The TableStart or TableEnd fields inside IF field will be visible in the document.

The call of MailMerge.ExecuteWithRegions method in your code does not update the IF field in the document as it is not part of mail merge with region. If there is IF field inside TableStart or TableEnd, it will be updated by calling this method. This is expected behavior of Aspose.Words.