Skip to content

Commit bf4cbad

Browse files
Aspose.SLides for OpenXML Presentations
1 parent e65ecca commit bf4cbad

File tree

91 files changed

+4037
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+4037
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2012
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenXml Presentation", "OpenXml Presentation\OpenXml Presentation.csproj", "{E64F771A-0F93-4538-BA1C-3B07138FEB7A}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Aspose Slides", "Aspose Slides\Aspose Slides.csproj", "{07037BF2-9D01-4EF0-AEE0-A679E59DC177}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E64F771A-0F93-4538-BA1C-3B07138FEB7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E64F771A-0F93-4538-BA1C-3B07138FEB7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E64F771A-0F93-4538-BA1C-3B07138FEB7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E64F771A-0F93-4538-BA1C-3B07138FEB7A}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{07037BF2-9D01-4EF0-AEE0-A679E59DC177}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{07037BF2-9D01-4EF0-AEE0-A679E59DC177}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{07037BF2-9D01-4EF0-AEE0-A679E59DC177}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{07037BF2-9D01-4EF0-AEE0-A679E59DC177}.Release|Any CPU.Build.0 = Release|Any CPU
22+
EndGlobalSection
23+
GlobalSection(SolutionProperties) = preSolution
24+
HideSolutionNode = FALSE
25+
EndGlobalSection
26+
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" />
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="4.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>{07037BF2-9D01-4EF0-AEE0-A679E59DC177}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Aspose_Slides</RootNamespace>
11+
<AssemblyName>Aspose Slides</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="Aspose.Slides">
36+
<HintPath>..\..\..\Dlls\Aspose.Slides.dll</HintPath>
37+
</Reference>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Drawing" />
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,34 @@
1+
// Copyright (c) Aspose 2002-2014. All Rights Reserved.
2+
3+
using System;
4+
using System.Drawing;
5+
using Aspose.Slides.Pptx;
6+
7+
namespace Aspose_Slides
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
14+
using (PresentationEx pres = new PresentationEx())
15+
{
16+
//Adding Empty slide
17+
pres.Slides.AddEmptySlide(pres.LayoutSlides[0]);
18+
19+
//Adding Autthor
20+
CommentAuthorEx author = pres.CommentAuthors.AddAuthor("Zeeshan", "MZ");
21+
22+
//Position of comments
23+
24+
PointF point = new PointF();
25+
point.X = 1;
26+
point.Y = 1;
27+
28+
//Adding slide comment for an author on slide
29+
author.Comments.AddComment("Hello Zeeshan, this is slide comment", pres.Slides[0], point, DateTime.Now);
30+
pres.Write("Comments.pptx");
31+
}
32+
}
33+
}
34+
}
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 © 2014")]
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("f45bc068-c1a9-4e47-8d9b-304a6ea2e69c")]
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" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.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>{E64F771A-0F93-4538-BA1C-3B07138FEB7A}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>OpenXml_Presentation</RootNamespace>
11+
<AssemblyName>OpenXml Presentation</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
36+
<SpecificVersion>False</SpecificVersion>
37+
<HintPath>C:\Users\MZeeshan\Downloads\DocumentFormat.OpenXml.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+
<Reference Include="WindowsBase" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<Compile Include="Program.cs" />
50+
<Compile Include="Properties\AssemblyInfo.cs" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<None Include="App.config" />
54+
</ItemGroup>
55+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
56+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
57+
Other similar extension points exist, see Microsoft.Common.targets.
58+
<Target Name="BeforeBuild">
59+
</Target>
60+
<Target Name="AfterBuild">
61+
</Target>
62+
-->
63+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Copyright (c) Aspose 2002-2014. All Rights Reserved.
2+
3+
using System;
4+
using System.Linq;
5+
using DocumentFormat.OpenXml.Packaging;
6+
using DocumentFormat.OpenXml.Presentation;
7+
8+
namespace OpenXml_Presentation
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
AddCommentToPresentation("Sample.pptx",
15+
"Zeeshan", "MZ",
16+
"This is my programmatically added comment.");
17+
18+
}
19+
// Adds a comment to the first slide of the presentation document.
20+
// The presentation document must contain at least one slide.
21+
private static void AddCommentToPresentation(string file, string initials, string name, string text)
22+
{
23+
using (PresentationDocument doc = PresentationDocument.Open(file, true))
24+
{
25+
26+
// Declare a CommentAuthorsPart object.
27+
CommentAuthorsPart authorsPart;
28+
29+
// Verify that there is an existing comment authors part.
30+
if (doc.PresentationPart.CommentAuthorsPart == null)
31+
{
32+
// If not, add a new one.
33+
authorsPart = doc.PresentationPart.AddNewPart<CommentAuthorsPart>();
34+
}
35+
else
36+
{
37+
authorsPart = doc.PresentationPart.CommentAuthorsPart;
38+
}
39+
40+
// Verify that there is a comment author list in the comment authors part.
41+
if (authorsPart.CommentAuthorList == null)
42+
{
43+
// If not, add a new one.
44+
authorsPart.CommentAuthorList = new CommentAuthorList();
45+
}
46+
47+
// Declare a new author ID.
48+
uint authorId = 0;
49+
CommentAuthor author = null;
50+
51+
// If there are existing child elements in the comment authors list...
52+
if (authorsPart.CommentAuthorList.HasChildren)
53+
{
54+
// Verify that the author passed in is on the list.
55+
var authors = authorsPart.CommentAuthorList.Elements<CommentAuthor>().Where(a => a.Name == name && a.Initials == initials);
56+
57+
// If so...
58+
if (authors.Any())
59+
{
60+
// Assign the new comment author the existing author ID.
61+
author = authors.First();
62+
authorId = author.Id;
63+
}
64+
65+
// If not...
66+
if (author == null)
67+
{
68+
// Assign the author passed in a new ID
69+
authorId = authorsPart.CommentAuthorList.Elements<CommentAuthor>().Select(a => a.Id.Value).Max();
70+
}
71+
}
72+
73+
// If there are no existing child elements in the comment authors list.
74+
if (author == null)
75+
{
76+
77+
authorId++;
78+
79+
// Add a new child element(comment author) to the comment author list.
80+
author = authorsPart.CommentAuthorList.AppendChild<CommentAuthor>
81+
(new CommentAuthor()
82+
{
83+
Id = authorId,
84+
Name = name,
85+
Initials = initials,
86+
ColorIndex = 0
87+
});
88+
}
89+
90+
// Get the first slide, using the GetFirstSlide method.
91+
SlidePart slidePart1 = GetFirstSlide(doc);
92+
93+
// Declare a comments part.
94+
SlideCommentsPart commentsPart;
95+
96+
// Verify that there is a comments part in the first slide part.
97+
if (slidePart1.GetPartsOfType<SlideCommentsPart>().Count() == 0)
98+
{
99+
// If not, add a new comments part.
100+
commentsPart = slidePart1.AddNewPart<SlideCommentsPart>();
101+
}
102+
else
103+
{
104+
// Else, use the first comments part in the slide part.
105+
commentsPart = slidePart1.GetPartsOfType<SlideCommentsPart>().First();
106+
}
107+
108+
// If the comment list does not exist.
109+
if (commentsPart.CommentList == null)
110+
{
111+
// Add a new comments list.
112+
commentsPart.CommentList = new CommentList();
113+
}
114+
115+
// Get the new comment ID.
116+
uint commentIdx = author.LastIndex == null ? 1 : author.LastIndex + 1;
117+
author.LastIndex = commentIdx;
118+
119+
// Add a new comment.
120+
Comment comment = commentsPart.CommentList.AppendChild<Comment>(
121+
new Comment()
122+
{
123+
AuthorId = authorId,
124+
Index = commentIdx,
125+
DateTime = DateTime.Now
126+
});
127+
128+
// Add the position child node to the comment element.
129+
comment.Append(
130+
new Position() { X = 100, Y = 200 },
131+
new Text() { Text = text });
132+
133+
// Save the comment authors part.
134+
authorsPart.CommentAuthorList.Save();
135+
136+
// Save the comments part.
137+
commentsPart.CommentList.Save();
138+
}
139+
}
140+
// Get the slide part of the first slide in the presentation document.
141+
private static SlidePart GetFirstSlide(PresentationDocument presentationDocument)
142+
{
143+
// Get relationship ID of the first slide
144+
PresentationPart part = presentationDocument.PresentationPart;
145+
SlideId slideId = part.Presentation.SlideIdList.GetFirstChild<SlideId>();
146+
string relId = slideId.RelationshipId;
147+
148+
// Get the slide part by the relationship ID.
149+
SlidePart slidePart = (SlidePart)part.GetPartById(relId);
150+
151+
return slidePart;
152+
}
153+
154+
}
155+
}

0 commit comments

Comments
 (0)