@k.sukumar,
To get the desired result you can remove unwanted TOC and unwanted paragraphs from your output document after producing it. Please check the following code example:
public static void RemoveTableOfContents(Document doc, int index)
{
// Store the FieldStart nodes of TOC fields in the document for quick access.
ArrayList fieldStarts = new ArrayList();
// This is a list to store the nodes found inside the specified TOC. They will be removed
// At the end of this method.
ArrayList nodeList = new ArrayList();
foreach (FieldStart start in doc.GetChildNodes(NodeType.FieldStart, true))
{
if (start.FieldType == FieldType.FieldTOC)
{
// Add all FieldStarts which are of type FieldTOC.
fieldStarts.Add(start);
}
}
// Ensure the TOC specified by the passed index exists.
if (index > fieldStarts.Count - 1)
throw new ArgumentOutOfRangeException("TOC index is out of range");
bool isRemoving = true;
// Get the FieldStart of the specified TOC.
Node currentNode = (Node)fieldStarts[index];
while (isRemoving)
{
// It is safer to store these nodes and delete them all at once later.
nodeList.Add(currentNode);
currentNode = currentNode.NextPreOrder(doc);
// Once we encounter a FieldEnd node of type FieldTOC then we know we are at the end
// Of the current TOC and we can stop here.
if (currentNode.NodeType == NodeType.FieldEnd)
{
FieldEnd fieldEnd = (FieldEnd)currentNode;
if (fieldEnd.FieldType == FieldType.FieldTOC)
isRemoving = false;
}
}
// Remove all nodes found in the specified TOC.
foreach (Node node in nodeList)
{
node.Remove();
}
}
Document doc = new Document(@"C:\Temp\32p531-val-of-analytical-proc-benzyl alcohol (1).doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// removing unwanted TOC (list of tables) from document
RemoveTableOfContents(doc, 1);
//removing unwanted paragraps from first TOC and from document
int num = 1;
foreach (Node p in doc.GetChildNodes(NodeType.Paragraph, true))
{
if (p.GetText().Contains("LIST OF TABLES"))
{
if (num == 1)
p.Remove();
if (num == 3)
{
builder.MoveTo(p.NextSibling);
p.Remove();
break;
}
num += 1;
}
}
builder.InsertBreak(BreakType.PageBreak);
doc.Save(@"C:\Temp\32p531-val-of-analytical-proc-benzyl alcohol (1)-updated.doc");
Please also check the attached document, produced by the code above.
32p531-val-of-analytical-proc-benzyl alcohol (1)-updated.zip (59.0 KB)