Knowledgebase (2311)
Children categories
Sections in PowerPoint is a feature that allows you to organize slides into different groups/segments for easy management. Adding sections with unique names can help keep track of specific groups of slides, or can also help outline the topics of a PowerPoint presentation. In this article, you will learn how to programmatically add or remove sections in a PowerPoint document using Spire.Presentation for .NET.
- Add a Section at the End of a PowerPoint Document in C# and VB.NET
- Insert a Section Before a Specified Section in PowerPoint in C# and VB.NET
- Add a Section Before a Specified Slide in PowerPoint in C# and VB.NET
- Remove a Section from a PowerPoint Document in C# and VB.NET
Install Spire.Presentation for .NET
To begin with, you need to add the DLL files included in the Spire.Presentation for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Presentation
Add a Section at the End of a PowerPoint Document in C# and VB.NET
Spire.Presentation for .NET provides the Presentation.SectionList.Append(string sectionName) method to append a section with section name at the end of a PowerPoint document. The detailed steps are as follows.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Append a section at the end of the document using Presentation.SectionList.Append(string sectionName) method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
namespace AppendSectionAtEnd
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.LoadFromFile("Test.pptx");
//Add a section at the end of the document
Section section = ppt.SectionList.Append("End Section");
//Save the result document
ppt.SaveToFile("AddSectionAtEnd.pptx", FileFormat.Pptx2013);
}
}
}

Insert a Section Before a Specified Section in PowerPoint in C# and VB.NET
If you want to insert a section before an existing section to make the document more logical, Spire.Presentation for .NET provides the Presentation.SectionList.Insert(int sectionIndex, string sectionName) method. The following are the steps to insert a section at a specified position by section index.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Insert a new section before the specified section using Presentation.SectionList.Insert(int sectionIndex, string sectionName) method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
namespace InsertSectionAtSpecifiedPosition
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.LoadFromFile("Test.pptx");
//Insert a section before the second section
Section section = ppt.SectionList.Insert(1, "New Section");
//Save the result document
ppt.SaveToFile("InsertSectionAtSpecifiedPosition.pptx", FileFormat.Pptx2013);
}
}
}

Add a Section Before a Specified Slide in PowerPoint in C# and VB.NET
To divided the existing PowerPoint slides into different sections, you can use the Presentation.SectionList.Add(string sectionName, ISlide slide) method to insert a section before a specified slide. The detailed steps are as follows.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Get a specified slide using Presentation.Slides property.
- Add a section before the specified slide using Presentation.SectionList.Add(string sectionName, ISlide slide) method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
namespace AddSectionBeforeSlide
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.LoadFromFile("Test.pptx");
//Get the second slide in the document
ISlide slide = ppt.Slides[1];
//Add a section before the second slide
Section section = ppt.SectionList.Add("New Section", slide);
//Save the result document
ppt.SaveToFile("AddSectionBeforeSlide.pptx", FileFormat.Pptx2013);
}
}
}

Remove a Section from a PowerPoint Document in C# and VB.NET
If you do not need a particular section, you can simply remove it using Presentation.SectionList.RemoveAt(int index) method. Note that removing a section does not remove the slides in that section. The following are the steps to remove a specified section but keep the slides in it.
- Initialize an instance of Presentation class.
- Load a PowerPoint document using Presentation.LoadFromFile() method.
- Remove a specified section using Presentation.SectionList.RemoveAt(int index) method. Or you can remove all the sections in the document using Presentation.SectionList.RemoveAll() method.
- Save the result document using Presentation.SaveToFile() method.
- C#
- VB.NET
using Spire.Presentation;
namespace RemoveSection
{
class Program
{
static void Main(string[] args)
{
//Create a Presentation instance
Presentation ppt = new Presentation();
//Load a sample PowerPoint document
ppt.LoadFromFile("Test.pptx");
//Remove the second section
ppt.SectionList.RemoveAt(1);
//Remove all the sections
//ppt.SectionList.RemoveAll();
//Save the result document
ppt.SaveToFile("RemoveSection.pptx", FileFormat.Pptx2013);
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
This article demonstrates how to set an expiration date for a PDF document using Spire.PDF for Java.
import com.spire.pdf.actions.PdfJavaScriptAction;
public class ExpiryDate {
public static void main(String[] args) {
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a PDF file
doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pdf");
//Set expiration date and warning information,and close the document through JavaScript
String javaScript = "var rightNow = new Date();"
+ "var endDate = new Date('June 20, 2020 23:59:59');"
+ "if(rightNow.getTime() > endDate)"
+ "app.alert('This document is no longer valid, please contact us for a updated one.',1);"
+ "this.closeDoc();";
//Create a PdfJavaScriptAction object based on the javascript
PdfJavaScriptAction js = new PdfJavaScriptAction(javaScript);
//Set PdfJavaScriptAction as the AfterOpenAction
doc.setAfterOpenAction(js);
//Save to file
doc.saveToFile("ExpirationDate.pdf", FileFormat.PDF);
}
}

Document comparison is the process of checking new versions of a document against previous copies in order to identify changes made by different contributors. These differences may include additions or omissions of words, sentences or paragraphs, and formatting adjustments. This article demonstrates how to compare two Word documents in Java using Spire.Doc for Java.
- Compare Two Documents and Save Result in a Third Word Document
- Compare Two Documents and Return Insertions and Deletions in Lists
Below is a screenshot of the two Word documents that’ll be compared.

Install Spire.Doc for Java
First, you're required to add the Spire.Doc.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc</artifactId>
<version>14.1.3</version>
</dependency>
</dependencies>
Compare Two Documents and Save Result in a Third Word Document
Saving the comparison result in a separate Word document allows users to see all the changes made to the original document, including insertions, deletions as well as modifications on formatting. The following are the steps to compare two documents and save the result in a third Word document using Spire.Doc for Java.
- Load two Word documents separately while initialing the Document objects.
- Compare these two documents using Document.compare() method.
- Save the result in a third Word document using Document.saveToFile() method.
- Java
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
public class CompareDocuments {
public static void main(String[] args) {
//Load one Word document
Document doc1 = new Document("C:\\Users\\Administrator\\Desktop\\original.docx");
//Load the other Word document
Document doc2 = new Document("C:\\Users\\Administrator\\Desktop\\revised.docx");
//Compare two documents
doc1.compare(doc2, "John");
//Save the differences in a third document
doc1.saveToFile("Differences.docx", FileFormat.Docx_2013);
doc1.dispose();
}
}

Compare Two Documents and Return Insertions and Deletions in Lists
Sometimes, we may only care about the insertions and deletions instead of the whole differences. The following are the steps to get insertions and deletions in two separate lists.
- Load two Word documents separately while initialing the Document objects.
- Compare two documents using Document.compare() method.
- Get the revisions using the constructor function of the DifferRevisions class.
- Get a list of insertions using DifferRevisions.getInsertRevisions() method.
- Get a list of deletions using DifferRevisions.getDeleteRevisions() method.
- Loop through the elements in the two lists to get the specific insertion and deletion.
- Java
import com.spire.doc.DifferRevisions;
import com.spire.doc.Document;
import com.spire.doc.DocumentObject;
import com.spire.doc.fields.TextRange;
import com.spire.ms.System.Collections.Generic.List;
public class CompareReturnResultsInLists {
public static void main(String[] args) {
//Load one Word document
Document doc1 = new Document("C:\\Users\\Administrator\\Desktop\\original.docx");
//Load the other Word document
Document doc2 = new Document("C:\\Users\\Administrator\\Desktop\\revised.docx");
//Compare the two Word documents
doc1.compare(doc2, "Author");
//Get the revisions
DifferRevisions differRevisions = new DifferRevisions(doc1);
//Return the insertion revisions in a list
List insertRevisionsList = differRevisions.getInsertRevisions();
//Return the deletion revisions in a list
List deleteRevisionsList = differRevisions.getDeleteRevisions();
//Create two int variables
int m = 0;
int n = 0;
//Loop through the insertion revision list
for (int i = 0; i < insertRevisionsList.size(); i++)
{
if (insertRevisionsList.get(i) instanceof TextRange)
{
m += 1;
//Get the specific revision and get its content
TextRange textRange = (TextRange)insertRevisionsList.get(i) ;
System.out.println("Insertion #" + m + ":" + textRange.getText());
}
}
System.out.println("============================================");
//Loop through the deletion revision list
for (int i = 0; i < deleteRevisionsList.size() ; i++)
{
if (deleteRevisionsList.get(i) instanceof TextRange)
{
n += 1;
//Get the specific revision and get its content
TextRange textRange = (TextRange) deleteRevisionsList.get(i) ;
System.out.println("Deletion #" + n + ":" + textRange.getText());
}
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.