We have the Aspose License that we are using for a long time. (Company Name: Everteam)
We are having troubles removing only the page containing a table of contents from a pdf or a word document.
So for instance, if we have a PDF document (Or word document) with 10 pages and the first page (Or any other page) contains a table of content, we would like to remove this particular page and thus result with a PDF with 9 pages in that case.
I am afraid, there is no concept of Page in MS Word document. Pages are created on the fly when you open a Word document with MS Word. However, you can use Aspose.Words for .NET to remove any Node (Paragraph, Shape, TOC Field etc) in a particular Page by using the following code:
Document doc = new Document("E:\\Temp\\Documents Samples\\file-sample_100kB.doc");
ArrayList tocList = new ArrayList();
foreach (Field field in doc.Range.Fields)
{
if (field.Type == FieldType.FieldTOC)
tocList.Add(field);
}
foreach (FieldToc toc in tocList)
{
LayoutCollector collector = new LayoutCollector(doc);
int tocPageNumber = collector.GetStartPageIndex(toc.Start.ParentParagraph);
Console.WriteLine("Removing TOC at Page# " + tocPageNumber);
toc.Remove();
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
if (collector.GetStartPageIndex(para) == tocPageNumber && collector.GetNumPagesSpanned(para) == 0)
para.Remove();
}
}
doc.Save("E:\\Temp\\Documents Samples\\20.4.docx");
Hope, this helps in achieving what you are looking for.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.