Skip to content

Commit 4c6b09f

Browse files
Merge pull request #1 from ZeeshanShafqat/master
Aspose.Slides Vs OpenXML Presentations v 1.1
2 parents 9c67031 + 24370eb commit 4c6b09f

File tree

40 files changed

+1422
-0
lines changed

40 files changed

+1422
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.21005.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenXML Presentation", "OpenXML Presentation\OpenXML Presentation.csproj", "{295EB9B5-B3D9-4CEB-BAB2-459E3749FB4D}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspose.Slides", "Aspose.Slides\Aspose.Slides.csproj", "{5B9A8791-85FF-4CD2-B494-F7DDC6BC777B}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{295EB9B5-B3D9-4CEB-BAB2-459E3749FB4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{295EB9B5-B3D9-4CEB-BAB2-459E3749FB4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{295EB9B5-B3D9-4CEB-BAB2-459E3749FB4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{295EB9B5-B3D9-4CEB-BAB2-459E3749FB4D}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{5B9A8791-85FF-4CD2-B494-F7DDC6BC777B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{5B9A8791-85FF-4CD2-B494-F7DDC6BC777B}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{5B9A8791-85FF-4CD2-B494-F7DDC6BC777B}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{5B9A8791-85FF-4CD2-B494-F7DDC6BC777B}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{5B9A8791-85FF-4CD2-B494-F7DDC6BC777B}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Aspose.Slides</RootNamespace>
11+
<AssemblyName>Aspose.Slides</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="Aspose.Slides">
37+
<HintPath>..\..\Dlls\Aspose.Slides.dll</HintPath>
38+
</Reference>
39+
<Reference Include="System" />
40+
<Reference Include="System.Core" />
41+
<Reference Include="System.Xml.Linq" />
42+
<Reference Include="System.Data.DataSetExtensions" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Data" />
45+
<Reference Include="System.Xml" />
46+
</ItemGroup>
47+
<ItemGroup>
48+
<Compile Include="Program.cs" />
49+
<Compile Include="Properties\AssemblyInfo.cs" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<None Include="App.config" />
53+
</ItemGroup>
54+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
55+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
56+
Other similar extension points exist, see Microsoft.Common.targets.
57+
<Target Name="BeforeBuild">
58+
</Target>
59+
<Target Name="AfterBuild">
60+
</Target>
61+
-->
62+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Aspose.Slides.Export;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Aspose.Slides
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
string presentationFile = @"E:\Aspose\Aspose Vs OpenXML\Aspose.Slides Vs OpenXML Presentation v1.1\Sample Files\My Sheet2.pptx";
15+
string themePresentation = @"E:\Aspose\Aspose Vs OpenXML\Aspose.Slides Vs OpenXML Presentation v1.1\Sample Files\My Theme.pptx";
16+
ApplyThemeToPresentation(themePresentation,presentationFile);
17+
}
18+
19+
public static void ApplyThemeToPresentation(string presentationFile, string outputFile)
20+
{
21+
//Instantiate Presentation class to load the source presentation file
22+
Presentation srcPres = new Presentation(presentationFile);
23+
24+
//Instantiate Presentation class for destination presentation (where slide is to be cloned)
25+
Presentation destPres = new Presentation(outputFile);
26+
27+
//Instantiate ISlide from the collection of slides in source presentation along with
28+
//master slide
29+
ISlide SourceSlide = srcPres.Slides[0];
30+
31+
//Clone the desired master slide from the source presentation to the collection of masters in the
32+
//destination presentation
33+
IMasterSlideCollection masters = destPres.Masters;
34+
IMasterSlide SourceMaster = SourceSlide.LayoutSlide.MasterSlide;
35+
36+
//Clone the desired master slide from the source presentation to the collection of masters in the
37+
//destination presentation
38+
IMasterSlide iSlide = masters.AddClone(SourceMaster);
39+
40+
//Clone the desired slide from the source presentation with the desired master to the end of the
41+
//collection of slides in the destination presentation
42+
ISlideCollection slds = destPres.Slides;
43+
slds.AddClone(SourceSlide, iSlide, true);
44+
45+
//Clone the desired master slide from the source presentation to the collection of masters in the//destination presentation
46+
//Save the destination presentation to disk
47+
destPres.Save(outputFile, SaveFormat.Pptx);
48+
}
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Aspose.Slides")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Aspose.Slides")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("45bb8990-423e-453d-ae88-3130cffd944e")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{295EB9B5-B3D9-4CEB-BAB2-459E3749FB4D}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>OpenXML_Presentation</RootNamespace>
11+
<AssemblyName>OpenXML Presentation</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Data.DataSetExtensions" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Xml" />
44+
<Reference Include="WindowsBase" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<Compile Include="Program.cs" />
48+
<Compile Include="Properties\AssemblyInfo.cs" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<None Include="App.config" />
52+
</ItemGroup>
53+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
55+
Other similar extension points exist, see Microsoft.Common.targets.
56+
<Target Name="BeforeBuild">
57+
</Target>
58+
<Target Name="AfterBuild">
59+
</Target>
60+
-->
61+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using DocumentFormat.OpenXml.Packaging;
2+
using DocumentFormat.OpenXml.Presentation;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace OpenXML_Presentation
10+
{
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
string presentationFile = @"E:\Aspose\Aspose Vs OpenXML\Aspose.Slides Vs OpenXML Presentation v1.1\Sample Files\My Sheet.pptx";
16+
string themePresentation = @"E:\Aspose\Aspose Vs OpenXML\Aspose.Slides Vs OpenXML Presentation v1.1\Sample Files\My Theme.pptx";
17+
ApplyThemeToPresentation(presentationFile, themePresentation);
18+
}
19+
// Apply a new theme to the presentation.
20+
public static void ApplyThemeToPresentation(string presentationFile, string themePresentation)
21+
{
22+
using (PresentationDocument themeDocument = PresentationDocument.Open(themePresentation, false))
23+
using (PresentationDocument presentationDocument = PresentationDocument.Open(presentationFile, true))
24+
{
25+
ApplyThemeToPresentation(presentationDocument, themeDocument);
26+
}
27+
}
28+
29+
// Apply a new theme to the presentation.
30+
public static void ApplyThemeToPresentation(PresentationDocument presentationDocument, PresentationDocument themeDocument)
31+
{
32+
if (presentationDocument == null)
33+
{
34+
throw new ArgumentNullException("presentationDocument");
35+
}
36+
if (themeDocument == null)
37+
{
38+
throw new ArgumentNullException("themeDocument");
39+
}
40+
41+
// Get the presentation part of the presentation document.
42+
PresentationPart presentationPart = presentationDocument.PresentationPart;
43+
44+
// Get the existing slide master part.
45+
SlideMasterPart slideMasterPart = presentationPart.SlideMasterParts.ElementAt(0);
46+
string relationshipId = presentationPart.GetIdOfPart(slideMasterPart);
47+
48+
// Get the new slide master part.
49+
SlideMasterPart newSlideMasterPart = themeDocument.PresentationPart.SlideMasterParts.ElementAt(0);
50+
51+
// Remove the existing theme part.
52+
presentationPart.DeletePart(presentationPart.ThemePart);
53+
54+
// Remove the old slide master part.
55+
presentationPart.DeletePart(slideMasterPart);
56+
57+
// Import the new slide master part, and reuse the old relationship ID.
58+
newSlideMasterPart = presentationPart.AddPart(newSlideMasterPart, relationshipId);
59+
60+
// Change to the new theme part.
61+
presentationPart.AddPart(newSlideMasterPart.ThemePart);
62+
63+
Dictionary<string, SlideLayoutPart> newSlideLayouts = new Dictionary<string, SlideLayoutPart>();
64+
65+
foreach (var slideLayoutPart in newSlideMasterPart.SlideLayoutParts)
66+
{
67+
newSlideLayouts.Add(GetSlideLayoutType(slideLayoutPart), slideLayoutPart);
68+
}
69+
70+
string layoutType = null;
71+
SlideLayoutPart newLayoutPart = null;
72+
73+
// Insert the code for the layout for this example.
74+
string defaultLayoutType = "Title and Content";
75+
76+
// Remove the slide layout relationship on all slides.
77+
foreach (var slidePart in presentationPart.SlideParts)
78+
{
79+
layoutType = null;
80+
81+
if (slidePart.SlideLayoutPart != null)
82+
{
83+
// Determine the slide layout type for each slide.
84+
layoutType = GetSlideLayoutType(slidePart.SlideLayoutPart);
85+
86+
// Delete the old layout part.
87+
slidePart.DeletePart(slidePart.SlideLayoutPart);
88+
}
89+
90+
if (layoutType != null && newSlideLayouts.TryGetValue(layoutType, out newLayoutPart))
91+
{
92+
// Apply the new layout part.
93+
slidePart.AddPart(newLayoutPart);
94+
}
95+
else
96+
{
97+
newLayoutPart = newSlideLayouts[defaultLayoutType];
98+
99+
// Apply the new default layout part.
100+
slidePart.AddPart(newLayoutPart);
101+
}
102+
}
103+
}
104+
105+
// Get the slide layout type.
106+
public static string GetSlideLayoutType(SlideLayoutPart slideLayoutPart)
107+
{
108+
CommonSlideData slideData = slideLayoutPart.SlideLayout.CommonSlideData;
109+
110+
// Remarks: If this is used in production code, check for a null reference.
111+
112+
return slideData.Name;
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)