Make Autotext empty

We have Autotext in header for which we don’t have data to display.If we don’t have value/data to display we are displaying as “Error Autotext not defined”

Can you please help me how to make display autotext empty if there is no value /data.

@NanthiniSenthil123 Could you please attach your input document here for our reference? We will check it and provide you more information. Unfortunately, screenshot does not allow to analyze the issue.

Here i have attached a document which includes sample code i used,input document,output document, expected output.Sample code.docx (64.8 KB)

@NanthiniSenthil123 The document contain screenshots of your document. For analysis the real input document is required. So please attach your input document here for testing.

Test Input Document.docx (21.4 KB)
Sample code.docx (64.8 KB)

Here i have attached sample input document and sample code. we are expecting to remove autotext if we dont have data/value in it.

@NanthiniSenthil123 You can simply remove AUTOTEXT fields with an error in the result. Please see the following code:

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

// Update fields.
doc.UpdateFields();
// get autotext fields and remvoe the firat with error in the result.
doc.Range.Fields.Where(f => (f.Type == FieldType.FieldAutoText) && (f.DisplayResult.StartsWith("Error!")))
    .ToList().ForEach(f => f.Remove());

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