We have already demonstrated how to add a brand new TOC when we create the word documents. This article will show you how to insert a TOC to the existing word documents with styles and remove the TOC from the word document.

Firstly, view the sample document with Title, Heading1 and Heading 2 styles:

C# insert and remove TOC from the word document

The below code snippet shows how to insert a Table of contents (TOC) into a document.

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Text.RegularExpressions;
namespace InsertTOC
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new instance of Document and load the document from file.
            Document doc = new Document();
            doc.LoadFromFile("Sample.docx", FileFormat.Docx2010);

            //Add the TOC to the document
            TableOfContent toc = new TableOfContent(doc, "{\\o \"1-3\" \\h \\z \\u}");
            Paragraph p = doc.LastSection.Paragraphs[0];
            p.Items.Add(toc);
            p.AppendFieldMark(FieldMarkType.FieldSeparator);
            p.AppendText("TOC");
            p.AppendFieldMark(FieldMarkType.FieldEnd);
            doc.TOC = toc;

            //Update the table of contents
            doc.UpdateTableOfContents();

            //Save the document to file
            doc.SaveToFile("Result.docx", FileFormat.Docx);

        }
    }
}

C# insert and remove TOC from the word document

Removing a Table of Contents from the Document

using Spire.Doc;
using System.Text.RegularExpressions;
namespace RemoveTOC
{
    class Program
    {
        static void Main(string[] args)
        {
            //load the document from file with TOC 
            Document doc = new Document();
            doc.LoadFromFile("Result.docx", FileFormat.Docx2010);

            //get the first body from the first section
            Body body = doc.Sections[0].Body;

            //remove TOC from first body
            Regex regex = new Regex("TOC\\w+");
            for (int i = 0; i < body.Paragraphs.Count; i++)
            {
                if (regex.IsMatch(body.Paragraphs[i].StyleName))
                {
                    body.Paragraphs.RemoveAt(i);
                    i--;
                }
            }
            //save the document to file
            doc.SaveToFile("RemoveTOC.docx", FileFormat.Docx2010);

        }
    }
}

C# insert and remove TOC from the word document

We have already demonstrated how to view the PDF file on the web with the help of Spire.PDFViewer for ASP.NET. This article we will demonstrate how to use three PDFViewer Control to view multiple PDF files on One Web Form in C#.

Before started, we need to create a new ASP.NET Empty Web Application in Visual Studio and add the Spire.PDFViewer.Asp dll file as the references. Then add the PDFViewer control and the PDFDocumentViewer control into toolbox.

Usually, we can Right-click Default.aspx, select view designer, and then drag the PDFViewer control from toolbox into Deafault.aspx to view one PDF file from web. This article we will use the code to add the PDFViewer control to one Web Form.

Step 1: Right-click Default.aspx, click the “Source” and use the following code to add three PDFViewer control from toolbox into Deafault.aspx. We can set the size for each PDFViewer control.

<div>

<cc1:PdfViewer ID="PdfViewer1" runat="server" Height="378px" 
        style="margin-top: 33px" Width="961px">
      
</cc1:PdfViewer>

</div>

<cc1:PdfViewer ID="PdfViewer2" runat="server"         
     Height="200px" style="margin-top: 20px" Width="961px">
  
</cc1:PdfViewer>   

<cc1:PdfViewer ID="PdfViewer3" runat="server"         
     Height="200px" style="margin-top: 20px" Width="961px">
  
</cc1:PdfViewer>

How to view multiple PDF files from one Web page in C#

Step 2: Add a new folder under the projects and add the sample PDF files need to view on the web.

How to view multiple PDF files from one Web page in C#

Step 3: Double-click Default.aspx.cs, add the code below to load a PDF file.

this.PdfViewer1.LoadFromFile("Document/Test.pdf");
this.PdfViewer2.LoadFromFile("Document/Sample.pdf");
this.PdfViewer3.LoadFromFile("Document/Test2.pdf");

After clicking the debug button, we will view the three PDF files on web.

How to view multiple PDF files from one Web page in C#

A PDF Portfolio can combine a wide range of file types such as Word, Excel, PDF and Image files, compared with merging files into a single PDF file, PDF Portfolio remains the individual identities of the files, and you can easily open, read, edit, and format each of them independently of the other files in the PDF Portfolio.

Spire.PDF allows developers to detect if a PDF file is a Portfolio programmatically using c# and vb.net. The following example uses a PDF Portfolio consists of an image, a PDF document and a Word file:

Detect if a PDF File is a Portfolio in C#, VB.NET

Detail steps:

Step 1: Instantiate a PdfDocument object and load the PDF file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Portfolio.pdf");

Step 2: Detect if the PDF file is a Portfolio.

bool isPortfolio = pdf.IsPortfolio;
if (isPortfolio)
{
    Console.WriteLine("It's a Portfolio!");
}

Screenshot:

Detect if a PDF File is a Portfolio in C#, VB.NET

Full code:

[C#]
using System;
using Spire.Pdf;

namespace Detect_if_a_PDF_is_a_Portfolio
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("Portfolio.pdf");

            bool isPortfolio = pdf.IsPortfolio;
            if (isPortfolio)
            {
                Console.WriteLine("It's a Portfolio!");
            }
            Console.ReadKey();
        }
    }
}
[VB.NET]
Imports Spire.Pdf

Namespace Detect_if_a_PDF_is_a_Portfolio
	Class Program
		Private Shared Sub Main(args As String())
			Dim pdf As New PdfDocument()
			pdf.LoadFromFile("Portfolio.pdf")

			Dim isPortfolio As Boolean = pdf.IsPortfolio
			If isPortfolio Then
				Console.WriteLine("It's a Portfolio!")
			End If
			Console.ReadKey()
		End Sub
	End Class
End Namespace
page 185