-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.vb
More file actions
209 lines (189 loc) · 7.94 KB
/
Program.vb
File metadata and controls
209 lines (189 loc) · 7.94 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
Imports DevExpress.Docs
Imports DevExpress.Docs.Presentation
Imports DevExpress.Drawing
Namespace ExtractPresentationContent
Public Class Program
Public Shared Sub Main(ByVal underscore() As String)
Dim presentation As 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: ")
Dim input As String = Console.ReadLine()
Select Case input
Case "1"
SlideText(presentation, 1)
Case "2"
SlidesText(presentation)
Case "3"
ParagraphText(presentation)
Case "4"
SlideNoteText(presentation,0)
Case "5"
SlideNoteBodyText(presentation, 0)
Case "6"
SlidesNoteText(presentation)
Case "7"
SaveSlidePictures(presentation, 1)
Case "8"
SaveSlidesPictures(presentation)
Case Else
Console.WriteLine("Invalid option.")
End Select
End Sub
Public Shared Function SlideText(ByVal presentation As Presentation, ByVal slideNumber As Integer) As String
' Extract text from the second slide
Dim slidesText As String = ""
' #Region "Sort shapes"
Dim sortedShapes = presentation.Slides(slideNumber).Shapes.Where(Function(shape) TypeOf shape Is Shape AndAlso CType(shape, Shape).TextArea IsNot Nothing).OrderBy(Function(shape) shape.Y).ThenBy(Function(shape) shape.X)
' #End Region
For Each shape In sortedShapes
Dim tempVar As Boolean = TypeOf shape Is Shape
Dim textShape As Shape = If(tempVar, CType(shape, Shape), Nothing)
If tempVar Then
Dim shapeText As String = textShape.TextArea.Text
' #Region "Filter shapes"
If textShape.PlaceholderSettings?.Type = PlaceholderType.SlideNumber OrElse String.IsNullOrWhiteSpace(shapeText) Then
Continue For
End If
' #End Region
slidesText &= shapeText & vbCrLf
End If
Next shape
Return slidesText
End Function
Public Shared Function SlidesText(ByVal presentation As Presentation) As String
' Extract text from all slides
Dim slideNumber As Integer = 0
Dim slidesText_Conflict As String = ""
For Each slide In presentation.Slides
' #Region "Sort shapes"
Dim sortedShapes = slide.Shapes.Where(Function(shape) TypeOf shape Is Shape AndAlso CType(shape, Shape).TextArea IsNot Nothing).OrderBy(Function(shape) shape.Y).ThenBy(Function(shape) shape.X)
' #End Region
For Each shape In sortedShapes
Dim tempVar As Boolean = TypeOf shape Is Shape
Dim textShape As Shape = If(tempVar, CType(shape, Shape), Nothing)
If tempVar Then
Dim shapeText As String = textShape.TextArea.Text
' #Region "Filter shapes"
If textShape.PlaceholderSettings?.Type = PlaceholderType.SlideNumber OrElse String.IsNullOrWhiteSpace(shapeText) Then
Continue For
End If
' #End Region
slidesText_Conflict &= shapeText & vbCrLf
End If
Next shape
slideNumber += 1
Next slide
Return slidesText_Conflict
End Function
Public Shared Function ParagraphText(ByVal presentation As Presentation) As String
'Extract text from the specific shape's paragraph
Dim paraText As String = ""
Dim shape As Shape = presentation.Slides(0).Shapes.Find(Of Shape)(Function(s) s.Name = "TextBox 3")
paraText = shape.TextArea.Paragraphs(1).Text
Return paraText
End Function
Public Shared Function SlideNoteText(ByVal presentation As Presentation, ByVal slideNumber As Integer) As String
' Extract note text from the first slide
Dim slideNoteText_Conflict As String = ""
For Each noteShape In presentation.Slides(slideNumber).Notes.Shapes
Dim tempVar As Boolean = TypeOf noteShape Is Shape
Dim textNoteShape As Shape = If(tempVar, CType(noteShape, Shape), Nothing)
If tempVar Then
Dim noteShapeText As String = textNoteShape.TextArea.Text
' #Region "Filter shapes"
If textNoteShape.PlaceholderSettings?.Type = PlaceholderType.SlideNumber OrElse String.IsNullOrWhiteSpace(noteShapeText) Then
Continue For
End If
' #End Region
slideNoteText_Conflict &= noteShapeText & vbCrLf
End If
Next noteShape
Return slideNoteText_Conflict
End Function
Public Shared Function SlideNoteBodyText(ByVal presentation As Presentation, ByVal slideNumber As Integer) As String
Dim notesText As String = ""
For Each noteShape In presentation.Slides(slideNumber).Notes.Shapes
Dim tempVar As Boolean = TypeOf noteShape Is Shape
Dim textNoteShape As Shape = If(tempVar, CType(noteShape, Shape), Nothing)
If tempVar AndAlso textNoteShape.PlaceholderSettings.Type = PlaceholderType.Body Then
Dim noteShapeText As String = textNoteShape.TextArea.Text
' #Region "Filter shapes"
If textNoteShape.PlaceholderSettings?.Type = PlaceholderType.SlideNumber OrElse String.IsNullOrWhiteSpace(noteShapeText) Then
Continue For
End If
notesText &= noteShapeText & vbCrLf
' #End Region
End If
Next noteShape
Return notesText
End Function
Public Shared Function SlidesNoteText(ByVal presentation As Presentation) As String
Dim notesText As String = ""
For Each slide In presentation.Slides
If slide.Notes.Shapes.Any() Then
' #Region "Sort shapes"
Dim sortedNoteShapes = slide.Notes.Shapes.Where(Function(shape) TypeOf shape Is Shape AndAlso CType(shape, Shape).TextArea IsNot Nothing).OrderBy(Function(shape) shape.Y).ThenBy(Function(shape) shape.X)
' #End Region
For Each noteShape In sortedNoteShapes
Dim tempVar As Boolean = TypeOf noteShape Is Shape
Dim textNoteShape As Shape = If(tempVar, CType(noteShape, Shape), Nothing)
If tempVar Then
Dim noteShapeText As String = textNoteShape.TextArea.Text
' #Region "Filter shapes"
If textNoteShape.PlaceholderSettings?.Type = PlaceholderType.SlideNumber OrElse String.IsNullOrWhiteSpace(noteShapeText) Then
Continue For
End If
notesText &= noteShapeText & vbCrLf
' #End Region
End If
Next noteShape
End If
Next slide
Return notesText
End Function
Public Shared Sub SaveSlidePictures(ByVal presentation As Presentation, ByVal slideNumber As Integer)
' Extract pictures from the second slide
' #Region "Sort shapes"
Dim sortedShapes = presentation.Slides(slideNumber).Shapes.Where(Function(shape) TypeOf shape Is PictureShape).OrderBy(Function(shape) shape.Y).ThenBy(Function(shape) shape.X)
' #End Region
Dim imageCount As Byte = 0
For Each pictureShape As PictureShape In sortedShapes
If pictureShape.Image.Type = OfficeImageType.Image Then
Dim innerImage As OfficeImage = CType(pictureShape.Image, OfficeImage)
If innerImage IsNot Nothing Then
innerImage.DXImage.Save("Slide2_Picture" & imageCount & ".png", DXImageFormat.Png)
imageCount += 1
End If
End If
Next pictureShape
End Sub
Public Shared Sub SaveSlidesPictures(ByVal presentation As Presentation)
' Extract pictures from all slides
Dim slideNumber As Integer = 0
For Each slide In presentation.Slides
' #Region "Sort shapes"
Dim sortedShapes = slide.Shapes.Where(Function(shape) TypeOf shape Is PictureShape).OrderBy(Function(shape) shape.Y).ThenBy(Function(shape) shape.X)
' #End Region
Dim imageCount As Byte = 0
For Each pictureShape As PictureShape In sortedShapes
If pictureShape.Image.Type = OfficeImageType.Image Then
Dim innerImage As OfficeImage = CType(pictureShape.Image, OfficeImage)
If innerImage IsNot Nothing Then
innerImage.DXImage.Save("Slide" & slideNumber & "_Picture" & imageCount & ".png", DXImageFormat.Png)
imageCount += 1
End If
End If
Next pictureShape
slideNumber += 1
Next slide
End Sub
End Class
End Namespace