We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Show/hide of static content in a document

possibility of show/hide of static content in a document based on the merge field selection


Hi Ravi,

Thanks for your inquiry. Yes this is possible. Please see input/output Word documents and try running the following code:
Document doc = new Document(getMyDir() + “input.docx”);

doc.getMailMerge().setFieldMergingCallback(new HandleMergeField());
doc.getMailMerge().execute(new String[] { “HideIt” }, new Object[] { “Y” });

doc.save(getMyDir() + “15.8.0.docx”);

static class HandleMergeField implements IFieldMergingCallback
public void fieldMerging(FieldMergingArgs e) throws Exception
Document doc = (Document) e.getDocument();
Paragraph para = doc.getFirstSection().getBody().getFirstParagraph();
<font color="RED"><b>public</b></font> <font color="RED"><b>void</b></font> imageFieldMerging<font color="BLUE"><b>(</b></font>ImageFieldMergingArgs args<font color="BLUE"><b>)</b></font> <font color="RED"><b>throws</b></font> Exception
<font color="BLUE"><b>{</b></font>
    <font color="GREEN"><i>// Do nothing.


I hope, this helps.

Best regards,