Spire.PDF offers a method of PdfDocument.MergeFiles(); to enable developers to merge PDF files easily and conveniently. This article will show you how to insert a new page from the first PDF into the second PDF file at a specified index by using the method of Pages.Insert(); offered by Spire.PDF.

Note: Before Start, please download the latest version of Spire.PDF and add Spire.PDF.dll in the bin folder as the reference of Visual Studio.

Here comes to the steps of how to insert the page from the first PDF (sample.pdf) into the second PDF (test.pdf) at a specified index:

Step 1: Create the first PDF document and load file.

PdfDocument doc1 = new PdfDocument();
doc1.LoadFromFile("sample.pdf");

Step 2: Create the second PDF document and load file.

PdfDocument doc2 = new PdfDocument();
doc2.LoadFromFile("test.pdf");

Step 3: Get the first page and its size from the first PDF document.

PdfPageBase page = doc1.Pages[0];
SizeF size = page.Size;

Step 4: Inserts a new blank page with the specified size at the specified index into the second PDF.

PdfPageBase newPage = doc2.Pages.Insert(1, size);

Step 5: Copy the contents on the page into the second PDF.

newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(0, 0));

Step 6: Save the document to file.

doc2.SaveToFile("result.pdf");

Effective screenshot of insert a new PDF page to an existing PDF at a specified index:

How to insert a new PDF page to an existing PDF at a specified index

Full codes:

using Spire.Pdf;
using System.Drawing;

namespace InsertNewPage
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument doc1 = new PdfDocument();
            doc1.LoadFromFile("sample.pdf");
            PdfDocument doc2 = new PdfDocument();
            doc2.LoadFromFile("test.pdf");

            PdfPageBase page = doc1.Pages[0];
            SizeF size = page.Size;

            PdfPageBase newPage = doc2.Pages.Insert(1, size);
            newPage.Canvas.DrawTemplate(page.CreateTemplate(), new PointF(0, 0));

            doc2.SaveToFile("result.pdf");
        }
    }
}

Microsoft PowerPoint lets you hide specific slides so they won’t appear during the slide show. You can also unhide the hidden slides at any time if you wish them to be visible in future presentations. In this article, you will learn how to hide or unhide slides in PowerPoint in C# and VB.NET using Spire.Presentation for .NET library.

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

Hide or Unhide Slides in PowerPoint in C# and VB.NET

The following are the steps to hide or unhide a slide in PowerPoint:

  • Create an instance of Presentation class.
  • Load a PowerPoint document using Presentation.LoadFromFile() method.
  • Get the slide that you want to hide or unhide by its index using Presentation.Slides[index] property.
  • Hide or unhide the slide by setting the ISlide.Hidden property as true or false.
  • Save the result document using Presentation.SaveToFile() method.
  • C#
  • VB.NET
using Spire.Presentation;

namespace HideOrUnhideSlides
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Presentation instance
            Presentation ppt = new Presentation();
            //Load a PowerPoint document
            ppt.LoadFromFile("Sample.pptx");

            //Get the first slide 
            ISlide slide = ppt.Slides[0];

            //Hide the slide
            slide.Hidden = true;
            //Unhide the slide
            //slide.Hidden = false;

            //Save the result document
            ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013);
        }
    }
}

The following is the result document after hiding the first slide:

C#/VB.NET: Hide or Unhide Slides in PowerPoint

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.

A combo box is a commonly-used GUI widget. It is a combination of a drop-down list or list box and a single-line textbox, allowing the user either to type a value directly into the control or choose from the list of existing options. In this article, we'll introduce how to programmatically manage the item of combo box in Word file using Spire.Doc.

Here is a combo box in the sample Word document, which contains three items including A, B and C. In the following section, we'll add, select and remove an item in the combo box using code.

How to Add, Select and Remove an Item in Combo Box in C#, VB.NET

Code Snippet:

Step 1: Initialize a new instance of Document class and load the sample Word file.

Document document = new Document();
document.LoadFromFile( "test.docx");

Step 2: Get the combo box from the file.

foreach (Section section in document.Sections)
{
    foreach (Body body in section.ChildObjects)
    {
        foreach (DocumentObject bodyObj in body.ChildObjects)
        {
            if (bodyObj is StructureDocumentTag)
            { 
                if ((bodyObj as StructureDocumentTag).SDTProperties.SDTType == SdtType.ComboBox)
                {
                    SdtComboBox combo = (bodyObj as StructureDocumentTag).SDTProperties.ControlProperties as SdtComboBox;
                    
               }
            }
        }
    }

}

Step 3: Create a new item and set two parameters for it: display text and value. Call ListItems.Add() method to add the new item into combo box.

SdtListItem item = new SdtListItem("D","d");
combo.ListItems.Add(item);

Step 4: Call ListItems.RemoveAt() method to remove an item by its index.

combo.ListItems.RemoveAt(0);

Step 5: Call ListItems.SelectedValue() to choose an item from combo box.

combo.ListItems.SelectedValue = sdtItem;

Step 6: Save and launch the file.

document.SaveToFile("result.docx", FileFormat.Docx2013);
System.Diagnostics.Process.Start("result.docx");

Output:

How to Add, Select and Remove an Item in Combo Box in C#, VB.NET

Entire Code:

[C#]
using Spire.Doc;
using Spire.Doc.Documents;
namespace IteminCombo
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document();
            document.LoadFromFile("test.docx");
            foreach (Section section in document.Sections)
            {
                foreach (Body body in section.ChildObjects)
                {
                    foreach (DocumentObject bodyObj in body.ChildObjects)
                    {
                        if (bodyObj is StructureDocumentTag)
                        {
                            if ((bodyObj as StructureDocumentTag).SDTProperties.SDTType == SdtType.ComboBox)
                            {
                                SdtComboBox combo = (bodyObj as StructureDocumentTag).SDTProperties.ControlProperties as SdtComboBox;
                                SdtListItem item = new SdtListItem("D", "d");
                                combo.ListItems.Add(item);
                                foreach (SdtListItem sdtItem in combo.ListItems)
                                {
                                    if (string.CompareOrdinal(sdtItem.Value, "d") == 0)
                                    {
                                        combo.ListItems.SelectedValue = sdtItem;
                                    }
                                }
                                combo.ListItems.RemoveAt(1);
                            }
                        }
                    }
                }

            }
            document.SaveToFile("result.docx", FileFormat.Docx2013);
            System.Diagnostics.Process.Start("result.docx");
        }
    }
}
[VB.NET]
Dim document As New Document()
document.LoadFromFile("test.docx")
For Each section As Section In document.Sections
	For Each body As Body In section.ChildObjects
		For Each bodyObj As DocumentObject In body.ChildObjects
			If TypeOf bodyObj Is StructureDocumentTag Then
				If TryCast(bodyObj, StructureDocumentTag).SDTProperties.SDTType = SdtType.ComboBox Then
					Dim combo As SdtComboBox = TryCast(TryCast(bodyObj, StructureDocumentTag).SDTProperties.ControlProperties, SdtComboBox)
					Dim item As New SdtListItem("D", "d")
					combo.ListItems.Add(item)
					For Each sdtItem As SdtListItem In combo.ListItems
						If String.CompareOrdinal(sdtItem.Value, "d") = 0 Then
							combo.ListItems.SelectedValue = sdtItem
						End If
					Next
					combo.ListItems.RemoveAt(1)
				End If
			End If
		Next

	Next
Next
document.SaveToFile("result.docx", FileFormat.Docx2013)
System.Diagnostics.Process.Start("result.docx")
page 233