-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
224 lines (203 loc) · 8.32 KB
/
Program.cs
File metadata and controls
224 lines (203 loc) · 8.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
using DevExpress.Docs;
using DevExpress.Docs.Presentation;
using DevExpress.Drawing;
namespace ExtractPresentationContent;
public class Program {
public static void Main(string[] _) {
Presentation presentation = new Presentation(File.ReadAllBytes(@"data\Sample.pptx"));
Console.WriteLine("Choose what to extract:");
Console.WriteLine("1. Slide text");
Console.WriteLine("2. Text from all slides");
Console.WriteLine("3. Text from a specific paragraph");
Console.WriteLine("4. Slide notes");
Console.WriteLine("5. Slide note body text");
Console.WriteLine("6. Notes from all slides");
Console.WriteLine("7. Slide pictures");
Console.WriteLine("8. Pictures from all slides");
Console.Write("Enter option number: ");
string? input = Console.ReadLine();
switch (input)
{
case "1":
SlideText(presentation, 1);
break;
case "2":
SlidesText(presentation);
break;
case "3":
ParagraphText(presentation);
break;
case "4":
SlideNoteText(presentation,0);
break;
case "5":
SlideNoteBodyText(presentation, 0);
break;
case "6":
SlidesNoteText(presentation);
break;
case "7":
SaveSlidePictures(presentation, 1);
break;
case "8":
SaveSlidesPictures(presentation);
break;
default:
Console.WriteLine("Invalid option.");
break;
}
}
public static string SlideText(Presentation presentation, int slideNumber) {
// Extract text from the second slide
string slidesText = "";
#region Sort shapes
var sortedShapes = presentation.Slides[slideNumber].Shapes
.Where(shape => shape is Shape && ((Shape)shape).TextArea != null)
.OrderBy(shape => shape.Y)
.ThenBy(shape => shape.X);
#endregion
foreach (var shape in sortedShapes)
{
if (shape is Shape textShape)
{
string shapeText = textShape.TextArea.Text;
#region Filter shapes
if (textShape.PlaceholderSettings?.Type == PlaceholderType.SlideNumber
|| string.IsNullOrWhiteSpace(shapeText)) continue;
#endregion
slidesText += shapeText + "\r\n";
}
}
return slidesText;
}
public static string SlidesText(Presentation presentation) {
// Extract text from all slides
int slideNumber = 0;
string slidesText = "";
foreach (var slide in presentation.Slides) {
#region Sort shapes
var sortedShapes = slide.Shapes
.Where(shape => shape is Shape && ((Shape)shape).TextArea != null)
.OrderBy(shape => shape.Y)
.ThenBy(shape => shape.X);
#endregion
foreach (var shape in sortedShapes) {
if (shape is Shape textShape) {
string shapeText = textShape.TextArea.Text;
#region Filter shapes
if (textShape.PlaceholderSettings?.Type == PlaceholderType.SlideNumber
|| string.IsNullOrWhiteSpace(shapeText)) continue;
#endregion
slidesText += shapeText + "\r\n";
}
}
slideNumber++;
}
return slidesText;
}
public static string ParagraphText(Presentation presentation) {
//Extract text from the specific shape's paragraph
string paraText = "";
Shape shape = presentation.Slides[0].Shapes.Find<Shape>(s => s.Name == "TextBox 3");
return paraText = shape.TextArea.Paragraphs[1].Text;
}
public static string SlideNoteText(Presentation presentation, int slideNumber) {
// Extract note text from the first slide
string slideNoteText = "";
foreach (var noteShape in presentation.Slides[slideNumber].Notes.Shapes) {
if (noteShape is Shape textNoteShape) {
string noteShapeText = textNoteShape.TextArea.Text;
#region Filter shapes
if (textNoteShape.PlaceholderSettings?.Type == PlaceholderType.SlideNumber
|| string.IsNullOrWhiteSpace(noteShapeText)) continue;
#endregion
slideNoteText += noteShapeText + "\r\n";
}
}
return slideNoteText;
}
public static string SlideNoteBodyText(Presentation presentation, int slideNumber) {
string notesText = "";
foreach (var noteShape in presentation.Slides[slideNumber].Notes.Shapes) {
if (noteShape is Shape textNoteShape
&& textNoteShape.PlaceholderSettings.Type == PlaceholderType.Body) {
string noteShapeText = textNoteShape.TextArea.Text;
#region Filter shapes
if (textNoteShape.PlaceholderSettings?.Type == PlaceholderType.SlideNumber
|| string.IsNullOrWhiteSpace(noteShapeText)) continue;
notesText += noteShapeText + "\r\n";
#endregion
}
}
return notesText;
}
public static string SlidesNoteText(Presentation presentation) {
string notesText = "";
foreach (var slide in presentation.Slides) {
if (slide.Notes.Shapes.Any()) {
#region Sort shapes
var sortedNoteShapes = slide.Notes.Shapes
.Where(shape => shape is Shape && ((Shape)shape).TextArea != null)
.OrderBy(shape => shape.Y)
.ThenBy(shape => shape.X);
#endregion
foreach (var noteShape in sortedNoteShapes) {
if (noteShape is Shape textNoteShape) {
string noteShapeText = textNoteShape.TextArea.Text;
#region Filter shapes
if (textNoteShape.PlaceholderSettings?.Type == PlaceholderType.SlideNumber
|| string.IsNullOrWhiteSpace(noteShapeText)) continue;
notesText += noteShapeText + "\r\n";
#endregion
}
}
}
}
return notesText;
}
public static void SaveSlidePictures(Presentation presentation, int slideNumber) {
// Extract pictures from the second slide
#region Sort shapes
var sortedShapes = presentation.Slides[slideNumber].Shapes
.Where(shape => shape is PictureShape)
.OrderBy(shape => shape.Y)
.ThenBy(shape => shape.X);
#endregion
byte imageCount = 0;
foreach (PictureShape pictureShape in sortedShapes) {
if (pictureShape.Image.Type == OfficeImageType.Image) {
OfficeImage innerImage = (OfficeImage)pictureShape.Image;
if (innerImage != null)
{
innerImage.DXImage.Save("Slide2_Picture" + imageCount + ".png", DXImageFormat.Png);
imageCount++;
}
}
}
}
public static void SaveSlidesPictures(Presentation presentation) {
// Extract pictures from all slides
int slideNumber = 0;
foreach (var slide in presentation.Slides)
{
#region Sort shapes
var sortedShapes = slide.Shapes
.Where(shape => shape is PictureShape)
.OrderBy(shape => shape.Y)
.ThenBy(shape => shape.X);
#endregion
byte imageCount = 0;
foreach (PictureShape pictureShape in sortedShapes) {
if (pictureShape.Image.Type == OfficeImageType.Image) {
OfficeImage innerImage = (OfficeImage)pictureShape.Image;
if (innerImage != null)
{
innerImage.DXImage.Save("Slide" + slideNumber + "_Picture" + imageCount + ".png", DXImageFormat.Png);
imageCount++;
}
}
slideNumber++;
}
}
}
}