Skip to content

Commit dbe4b84

Browse files
committed
Committed sample
1 parent 637f2eb commit dbe4b84

File tree

8 files changed

+316
-0
lines changed

8 files changed

+316
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.13.36105.23 d17.13
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert-Word-document-to-PPTX", "Convert-Word-document-to-PPTX\Convert-Word-document-to-PPTX.csproj", "{54B715A3-744B-460B-B50E-2506C6ED6B6D}"
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+
{54B715A3-744B-460B-B50E-2506C6ED6B6D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{54B715A3-744B-460B-B50E-2506C6ED6B6D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{54B715A3-744B-460B-B50E-2506C6ED6B6D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{54B715A3-744B-460B-B50E-2506C6ED6B6D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {8D3878F2-8F44-4CED-B36F-5DCD6D25668F}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Convert_Word_document_to_PPTX</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="*" />
14+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
15+
<PackageReference Include="Syncfusion.Presentation.Net.Core" Version="*" />
16+
</ItemGroup>
17+
<ItemGroup>
18+
<None Update="Data\Template.docx">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
<None Update="Output\.gitkeep">
22+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
23+
</None>
24+
</ItemGroup>
25+
26+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>Convert-Word-document-to-PPTX</ActiveDebugProfile>
5+
</PropertyGroup>
6+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
7+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
8+
</PropertyGroup>
9+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
2+
3+
# Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
4+
# For more information, please see https://aka.ms/containercompat
5+
6+
# This stage is used when running from VS in fast mode (Default for Debug configuration)
7+
FROM mcr.microsoft.com/dotnet/runtime:8.0-nanoserver-1809 AS base
8+
WORKDIR /app
9+
10+
11+
# This stage is used to build the service project
12+
FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-1809 AS build
13+
ARG BUILD_CONFIGURATION=Release
14+
WORKDIR /src
15+
COPY ["Convert-Word-document-to-PPTX/Convert-Word-document-to-PPTX.csproj", "Convert-Word-document-to-PPTX/"]
16+
RUN dotnet restore "./Convert-Word-document-to-PPTX/Convert-Word-document-to-PPTX.csproj"
17+
COPY . .
18+
WORKDIR "/src/Convert-Word-document-to-PPTX"
19+
RUN dotnet build "./Convert-Word-document-to-PPTX.csproj" -c %BUILD_CONFIGURATION% -o /app/build
20+
21+
# This stage is used to publish the service project to be copied to the final stage
22+
FROM build AS publish
23+
ARG BUILD_CONFIGURATION=Release
24+
RUN dotnet publish "./Convert-Word-document-to-PPTX.csproj" -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
25+
26+
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
27+
FROM base AS final
28+
WORKDIR /app
29+
COPY --from=publish /app/publish .
30+
ENTRYPOINT ["dotnet", "Convert-Word-document-to-PPTX.dll"]

Word-to-PPTX-Conversion/Convert-Word-document-to-PPTX/.NET/Convert-Word-document-to-PPTX/Output/.gitkeep

Whitespace-only changes.
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.Drawing;
3+
using Syncfusion.Presentation;
4+
5+
namespace Convert_Word_document_to_PPTX
6+
{
7+
class Program
8+
{
9+
private static IPresentation pptxDoc;
10+
static void Main(string[] args)
11+
{
12+
FileStream fileStreamPath = new FileStream("../../../Data/Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
13+
//Opens an existing document from file system through constructor of WordDocument class
14+
using (WordDocument document = new WordDocument(fileStreamPath, Syncfusion.DocIO.FormatType.Automatic))
15+
{
16+
pptxDoc = Presentation.Create();
17+
18+
foreach (WSection section in document.Sections)
19+
{
20+
//Accesses the Body of section where all the contents in document are apart
21+
WTextBody sectionBody = section.Body;
22+
AddTextBodyItems(sectionBody);
23+
}
24+
FileStream outputStream = new FileStream("../../../Output/DocxToPptx.pptx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
25+
pptxDoc.Save(outputStream);
26+
outputStream.Close();
27+
28+
}
29+
}
30+
31+
/// <summary>
32+
/// Adds the text body items to the Presentation document
33+
/// </summary>
34+
/// <param name="docTextBody"></param>
35+
private static void AddTextBodyItems(WTextBody docTextBody)
36+
{
37+
AddTextBodyItems(docTextBody, null);
38+
}
39+
40+
/// <summary>
41+
/// Iterates the text body items of Word document and creates slides and add textbox accordingly
42+
/// </summary>
43+
/// <param name="docTextBody"></param>
44+
/// <param name="powerPointTableCell"></param>
45+
private static void AddTextBodyItems(WTextBody docTextBody, ICell powerPointTableCell)
46+
{
47+
ISlide powerPointSlide = null;
48+
IShape powerPointShape = null;
49+
IParagraph powerPointParagraph = null;
50+
51+
//Iterates through each of the child items of WTextBody
52+
for (int i = 0; i < docTextBody.ChildEntities.Count; i++)
53+
{
54+
//IEntity is the basic unit in DocIO DOM.
55+
//Accesses the body items (should be either paragraph, table or block content control) as IEntity
56+
IEntity bodyItemEntity = docTextBody.ChildEntities[i];
57+
58+
//A Text body has 3 types of elements - Paragraph, Table and Block Content Control
59+
//Decides the element type by using EntityType
60+
switch (bodyItemEntity.EntityType)
61+
{
62+
case EntityType.Paragraph:
63+
WParagraph docParagraph = bodyItemEntity as WParagraph;
64+
if (docParagraph.ChildEntities.Count == 0)
65+
break;
66+
//Checkes whether the paragraph is list paragraph
67+
if (IsListParagraph(docParagraph))
68+
{
69+
if (docParagraph.ListFormat.ListType == Syncfusion.DocIO.DLS.ListType.NoList)
70+
{
71+
powerPointSlide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
72+
powerPointSlide.AddTextBox(50, 50, 756, 300);
73+
}
74+
powerPointShape = powerPointSlide.Shapes[0] as IShape;
75+
powerPointParagraph = powerPointShape.TextBody.AddParagraph(docParagraph.Text);
76+
//Checks whether the list type is numbered
77+
if (docParagraph.ListFormat.ListType == Syncfusion.DocIO.DLS.ListType.Numbered)
78+
ApplyListStyles(powerPointParagraph);
79+
}
80+
//Checks whether the paragraph is inside a cell
81+
else if (docParagraph.IsInCell && powerPointTableCell != null)
82+
{
83+
powerPointParagraph = powerPointTableCell.TextBody.AddParagraph();
84+
AddParagraphItems(docParagraph, powerPointParagraph, powerPointTableCell);
85+
}
86+
//Checks whether the paragraph is heading style
87+
else if (docParagraph.StyleName.Contains("Heading"))
88+
{
89+
powerPointSlide = pptxDoc.Slides.Add(SlideLayoutType.Title);
90+
powerPointSlide.Shapes.Remove(powerPointSlide.Shapes[1]);
91+
powerPointShape = powerPointSlide.Shapes[0] as IShape;
92+
powerPointParagraph = powerPointShape.TextBody.AddParagraph();
93+
94+
AddParagraphItems(docParagraph, powerPointParagraph);
95+
}
96+
else
97+
{
98+
powerPointSlide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
99+
powerPointShape = powerPointSlide.AddTextBox(50, 50, 800, 300);
100+
powerPointParagraph = powerPointShape.TextBody.AddParagraph();
101+
powerPointParagraph.FirstLineIndent = 30;
102+
103+
AddParagraphItems(docParagraph, powerPointParagraph);
104+
}
105+
break;
106+
107+
case EntityType.Table:
108+
//Table is a collection of rows and cells
109+
//Iterates through table's DOM
110+
//Iterates the row collection in a table and creates a new slide for each row
111+
WTable table = bodyItemEntity as WTable;
112+
foreach (WTableRow row in table.Rows)
113+
{
114+
powerPointSlide = pptxDoc.Slides.Add(SlideLayoutType.Blank);
115+
ITable powerPointTable = powerPointSlide.Shapes.AddTable(1, row.Cells.Count, 200, 140, 500, 220);
116+
powerPointTable.BuiltInStyle = BuiltInTableStyle.None;
117+
//Iterates the cell collection in a table row
118+
for (int j = 0; j < row.Cells.Count; j++)
119+
{
120+
WTableCell cell = row.Cells[j];
121+
//Table cell is derived from (also a) TextBody
122+
//Reusing the code meant for iterating TextBody
123+
AddTextBodyItems(cell as WTextBody, powerPointTable.Rows[0].Cells[j]);
124+
}
125+
}
126+
break;
127+
128+
case EntityType.BlockContentControl:
129+
BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl;
130+
//Iterates to the body items of Block Content Control.
131+
AddTextBodyItems(blockContentControl.TextBody);
132+
break;
133+
}
134+
}
135+
}
136+
137+
/// <summary>
138+
/// Applies the Numbered list style
139+
/// </summary>
140+
/// <param name="powerPointParagraph"></param>
141+
private static void ApplyListStyles(IParagraph powerPointParagraph)
142+
{
143+
powerPointParagraph.ListFormat.Type = Syncfusion.Presentation.ListType.Numbered;
144+
powerPointParagraph.ListFormat.NumberStyle = NumberedListStyle.ArabicPeriod;
145+
powerPointParagraph.ListFormat.StartValue = 1;
146+
// Sets the hanging value
147+
powerPointParagraph.FirstLineIndent = -20;
148+
// Sets the bullet character size. Here, 100 means 100% of its text. Possible values can range from 25 to 400.
149+
powerPointParagraph.ListFormat.Size = 100;
150+
powerPointParagraph.IndentLevelNumber = 1;
151+
}
152+
153+
/// <summary>
154+
/// Adds the paragraph items to the Presentation document
155+
/// </summary>
156+
/// <param name="docParagraph"></param>
157+
/// <param name="powerPointParagraph"></param>
158+
private static void AddParagraphItems(WParagraph docParagraph, IParagraph powerPointParagraph)
159+
{
160+
AddParagraphItems(docParagraph, powerPointParagraph, null);
161+
}
162+
163+
/// <summary>
164+
/// Iterates the paragraph and adds the paragraph items to the Presentation document
165+
/// </summary>
166+
/// <param name="docParagraph"></param>
167+
/// <param name="powerPointParagraph"></param>
168+
/// <param name="powerPointTableCell"></param>
169+
private static void AddParagraphItems(WParagraph docParagraph, IParagraph powerPointParagraph, ICell powerPointTableCell)
170+
{
171+
for (int i = 0; i < docParagraph.Items.Count; i++)
172+
{
173+
Entity entity = docParagraph.Items[i];
174+
//A paragraph can have child elements such as text, image, hyperlink, symbols, etc.,
175+
//Decides the element type by using EntityType
176+
switch (entity.EntityType)
177+
{
178+
case EntityType.TextRange:
179+
WTextRange textRange = entity as WTextRange;
180+
ITextPart textPart = powerPointParagraph.AddTextPart(textRange.Text);
181+
//Checks whether th paragraph is not in cell
182+
if (!docParagraph.IsInCell)
183+
{
184+
//Checks whether the paragraph is heading style paragraph
185+
if (docParagraph.StyleName.Contains("Heading"))
186+
textPart.Font.Bold = true;
187+
else
188+
{
189+
textPart.Font.Color.SystemColor = Color.Black;
190+
textPart.Font.FontSize = 32;
191+
}
192+
}
193+
break;
194+
195+
case EntityType.Picture:
196+
//Checks whether the image is inside a cell
197+
if (docParagraph.IsInCell && powerPointTableCell != null)
198+
powerPointTableCell.Fill.PictureFill.ImageBytes = (entity as WPicture).ImageBytes;
199+
break;
200+
}
201+
}
202+
}
203+
204+
/// <summary>
205+
/// Checks whether the paragraph is list paragraph
206+
/// </summary>
207+
/// <param name="paragraph"></param>
208+
/// <returns></returns>
209+
private static bool IsListParagraph(WParagraph paragraph)
210+
{
211+
return paragraph.NextSibling is WParagraph && paragraph.PreviousSibling is WParagraph &&
212+
((paragraph.NextSibling as WParagraph).ListFormat.ListType != Syncfusion.DocIO.DLS.ListType.NoList
213+
|| (paragraph.PreviousSibling as WParagraph).ListFormat.ListType != Syncfusion.DocIO.DLS.ListType.NoList);
214+
}
215+
}
216+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"profiles": {
3+
"Convert-Word-document-to-PPTX": {
4+
"commandName": "Project"
5+
},
6+
"Container (Dockerfile)": {
7+
"commandName": "Docker"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)