officefileapi-405406-presentation-api-merge-split.md
This topic contains examples that implement the following merge and split tasks:
The following code snippet extracts a slide from a presentation and inserts it into another presentation:
using DevExpress.Docs.Presentation;
namespace PptxSample;
public class Program {
public static void Main(string[] _) {
// Load the first presentation from a file
Presentation presentation1 = new Presentation(File.ReadAllBytes(@"..\..\..\data\my-presentation.pptx"));
// Load the second presentation from a file
Presentation presentation2 = new Presentation(File.ReadAllBytes(@"..\..\..\data\NorthwindPresentation.pptx"));
// Clone the first slide from the first presentation, so you can edit the copy not the original slide, if necessary
Slide slide1 = presentation1.Slides[0].Clone();
// Insert the cloned slide at the beginning of the second presentation
presentation2.Slides.Insert(0, slide1);
// Export the modified second presentation to a PDF file
presentation2.ExportToPdf(new FileStream(@"D:\exported-document.pdf", FileMode.Create));
}
}
Imports DevExpress.Docs.Presentation
Namespace PptxSample
Public Class Program
Public Shared Sub Main(__ As String())
' Load the first presentation from a file
Dim presentation1 As Presentation = New Presentation(File.ReadAllBytes("..\..\..\data\my-presentation.pptx"))
' Load the second presentation from a file
Dim presentation2 As Presentation = New Presentation(File.ReadAllBytes("..\..\..\data\NorthwindPresentation.pptx"))
' Clone the first slide from the first presentation, so you can edit the copy not the original slide, if necessary
Dim slide1 As Slide = presentation1.Slides(0).Clone()
' Insert the cloned slide at the beginning of the second presentation
presentation2.Slides.Insert(0, slide1)
' Export the modified second presentation to a PDF file
presentation2.ExportToPdf(New FileStream("D:\exported-document.pdf", FileMode.Create))
End Sub
End Class
End Namespace
The following code snippet adds slides to a presentation from another presentation to merge two presentations:
using DevExpress.Docs.Presentation;
namespace PptxSample;
public class Program {
public static void Main(string[] _) {
// Load the first presentation from a file
Presentation presentation1 = new Presentation(File.ReadAllBytes(@"..\..\..\data\my-presentation.pptx"));
// Load the second presentation from a file
Presentation presentation2 = new Presentation(File.ReadAllBytes(@"..\..\..\data\NorthwindPresentation.pptx"));
// Append all slides from the second presentation to the first presentation
foreach (Slide slide in presentation2.Slides) {
presentation1.Slides.Add(slide);
}
// Export the resulting presentation to PDF
presentation1.ExportToPdf(new FileStream(@"D:\exported-document.pdf", FileMode.Create));
}
}
Imports DevExpress.Docs.Presentation
Namespace PptxSample
Public Class Program
Public Shared Sub Main(__ As String())
' Load the first presentation from a file
Dim presentation1 As Presentation = New Presentation(File.ReadAllBytes("..\..\..\data\my-presentation.pptx"))
' Load the second presentation from a file
Dim presentation2 As Presentation = New Presentation(File.ReadAllBytes("..\..\..\data\NorthwindPresentation.pptx"))
' Append all slides from the second presentation to the first presentation
For Each slide In presentation2.Slides
presentation1.Slides.Add(slide)
Next
' Export the resulting presentation to PDF
presentation1.ExportToPdf(New FileStream("D:\exported-document.pdf", FileMode.Create))
End Sub
End Class
End Namespace
The following code snippet extracts slides from a presentation and puts them into an empty presentation:
using DevExpress.Docs.Presentation;
namespace PptxSample;
public class Program {
public static void Main(string[] _) {
// Load the Northwind presentation from a file
Presentation presentation1 = new Presentation(File.ReadAllBytes(@"..\..\..\data\NorthwindPresentation.pptx"));
// Create a new empty presentation
Presentation presentation2 = new Presentation();
// Remove default slides in presentation
presentation2.Slides.Clear();
// Set the presentation1 slide size to match presentation2
presentation2.SlideSize = presentation1.SlideSize;
// Move the first three slides from presentation1 to presentation2
for (int i = 0; i < 3; i++)
{
presentation2.Slides.Add(presentation1.Slides[i]);
presentation1.Slides.RemoveAt(i);
}
// Export the modified presentation1 (with the remaining slides) to PDF
presentation1.ExportToPdf(new FileStream(@"D:\exported-document1.pdf", FileMode.Create));
// Export presentation2 (with the first three slides) to PDF
presentation2.ExportToPdf(new FileStream(@"D:\exported-document2.pdf", FileMode.Create));
}
}
Imports DevExpress.Docs.Presentation
Namespace PptxSample
Public Class Program
Public Shared Sub Main(__ As String())
' Load the Northwind presentation from a file
Dim presentation1 As Presentation = New Presentation(File.ReadAllBytes("..\..\..\data\NorthwindPresentation.pptx"))
' Create a new empty presentation
Dim presentation2 As Presentation = New Presentation()
' Remove default slides in presentation
presentation2.Slides.Clear()
' Set the slide size to match presentation2
presentation2.SlideSize = presentation1.SlideSize
' Move the first three slides from presentation1 to presentation2
For i = 0 To 2
presentation2.Slides.Add(presentation1.Slides(i))
presentation1.Slides.RemoveAt(i)
Next
' Export the modified presentation1 (with the remaining slides) to PDF
presentation1.ExportToPdf(New FileStream("D:\exported-document1.pdf", FileMode.Create))
' Export presentation2 (with the first three slides) to PDF
presentation2.ExportToPdf(New FileStream("D:\exported-document2.pdf", FileMode.Create))
End Sub
End Class
End Namespace