Skip to content

Commit adac703

Browse files
authored
Merge branch 'SyncfusionExamples:master' into master
2 parents 5122df1 + 4a71624 commit adac703

File tree

10 files changed

+293
-0
lines changed

10 files changed

+293
-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.4.33110.190
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Create-fillable-PDF-from-PPTX", "Create-fillable-PDF-from-PPTX\Create-fillable-PDF-from-PPTX.csproj", "{200E55BD-87C8-4D42-A14E-290C0AB1EF00}"
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+
{200E55BD-87C8-4D42-A14E-290C0AB1EF00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{200E55BD-87C8-4D42-A14E-290C0AB1EF00}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{200E55BD-87C8-4D42-A14E-290C0AB1EF00}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{200E55BD-87C8-4D42-A14E-290C0AB1EF00}.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 = {5944F990-AC83-4E81-AEB9-28E7F2EE876D}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Create_fillable_PDF_from_PPTX</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.PresentationRenderer.NET" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.pptx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Syncfusion.Pdf;
2+
using Syncfusion.Presentation;
3+
using Syncfusion.PresentationRenderer;
4+
5+
//Open the PowerPoint file stream.
6+
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
7+
{
8+
//Load an existing PowerPoint Presentation.
9+
using (IPresentation pptxDoc = Presentation.Open(fileStream))
10+
{
11+
// Create new instance for PresentationToPdfConverterSettings
12+
PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings();
13+
//Enables a flag to preserve form fields by converting shapes with names starting with 'FormField_' into editable text form fields in the PDF.
14+
settings.PreserveFormFields = true;
15+
//Convert PowerPoint into PDF document.
16+
using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc))
17+
{
18+
//Save the PDF file to file system.
19+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/PPTXToPDF.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
20+
{
21+
pdfDocument.Save(outputStream);
22+
}
23+
}
24+
}
25+
}
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 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Iterate-slide-elements", "Iterate-slide-elements\Iterate-slide-elements.csproj", "{38FB99D1-DB4A-4A3F-B90B-7135724337EF}"
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+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{38FB99D1-DB4A-4A3F-B90B-7135724337EF}.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 = {B75368E1-9546-4CD5-BE4C-5C905E8D16C2}
24+
EndGlobalSection
25+
EndGlobal
Binary file not shown.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Iterate_slide_elements</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.Presentation.NET" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\Template.pptx">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Output\.gitkeep">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
using Syncfusion.Presentation;
2+
using Syncfusion.OfficeChart;
3+
using System.IO;
4+
5+
class Program
6+
{
7+
public static void Main(string[] args)
8+
{
9+
// Load or open a PowerPoint presentation
10+
using (FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
11+
{
12+
using (IPresentation presentation = Presentation.Open(inputStream))
13+
{
14+
// Iterate through each slide in the presentation
15+
foreach (ISlide slide in presentation.Slides)
16+
{
17+
// Iterate through each shape in the master slide shapes.
18+
foreach (IShape shape in slide.LayoutSlide.MasterSlide.Shapes)
19+
{
20+
// Modify the shape properties (text, size, hyperlinks, etc.)
21+
ModifySlideElements(shape);
22+
}
23+
// Iterate through each shape in the layout slide shapes.
24+
foreach (IShape shape in slide.LayoutSlide.Shapes)
25+
{
26+
// Modify the shape properties (text, size, hyperlinks, etc.)
27+
ModifySlideElements(shape);
28+
}
29+
// Iterate through each shape in the slide
30+
foreach (IShape shape in slide.Shapes)
31+
{
32+
// Modify the shape properties (text, size, hyperlinks, etc.)
33+
ModifySlideElements(shape);
34+
}
35+
}
36+
37+
// Save the modified presentation to an output file
38+
using (FileStream outputStream = new(Path.GetFullPath(@"Output/Result.pptx"), FileMode.Create, FileAccess.ReadWrite))
39+
{
40+
presentation.Save(outputStream);
41+
}
42+
}
43+
}
44+
}
45+
46+
/// <summary>
47+
/// Modifies slide elements based on their type.
48+
/// </summary>
49+
private static void ModifySlideElements(IShape shape )
50+
{
51+
switch (shape.SlideItemType)
52+
{
53+
case SlideItemType.AutoShape:
54+
{
55+
// Modify text if present in the shape
56+
if (!string.IsNullOrEmpty(shape.TextBody.Text))
57+
{
58+
ModifyTextPart(shape.TextBody);
59+
}
60+
// If shape is a rectangle, add a hyperlink
61+
else if (shape.AutoShapeType == AutoShapeType.Rectangle)
62+
{
63+
shape.SetHyperlink("www.google.com");
64+
}
65+
break;
66+
}
67+
68+
case SlideItemType.ConnectionShape:
69+
{
70+
IConnector connector = shape as IConnector;
71+
// Modify the arrowhead style at the beginning of the connector line
72+
connector.LineFormat.BeginArrowheadStyle = ArrowheadStyle.ArrowDiamond;
73+
break;
74+
}
75+
76+
case SlideItemType.Placeholder:
77+
{
78+
// Modify text if present in the placeholder
79+
if (!string.IsNullOrEmpty(shape.TextBody.Text))
80+
{
81+
ModifyTextPart(shape.TextBody);
82+
}
83+
break;
84+
}
85+
86+
case SlideItemType.Picture:
87+
{
88+
// Resize the picture
89+
IPicture picture = shape as IPicture;
90+
picture.Height = 160;
91+
picture.Width = 130;
92+
break;
93+
}
94+
95+
case SlideItemType.Table:
96+
{
97+
// Get the table shape
98+
ITable table = shape as ITable;
99+
100+
// Iterate through rows and modify text in each cell
101+
foreach (IRow row in table.Rows)
102+
{
103+
foreach (ICell cell in row.Cells)
104+
{
105+
ModifyTextPart(cell.TextBody);
106+
}
107+
}
108+
break;
109+
}
110+
111+
case SlideItemType.GroupShape:
112+
{
113+
// Get the group shape and iterate through child shapes
114+
IGroupShape groupShape = shape as IGroupShape;
115+
foreach (IShape childShape in groupShape.Shapes)
116+
{
117+
ModifySlideElements(childShape);
118+
}
119+
break;
120+
}
121+
122+
case SlideItemType.Chart:
123+
{
124+
// Modify chart properties
125+
IPresentationChart chart = shape as IPresentationChart;
126+
chart.ChartTitle = "Purchase Details";
127+
chart.ChartTitleArea.Bold = true;
128+
chart.ChartTitleArea.Color = OfficeKnownColors.Red;
129+
chart.ChartTitleArea.Size = 20;
130+
break;
131+
}
132+
133+
case SlideItemType.SmartArt:
134+
{
135+
// Modify SmartArt content
136+
ISmartArt smartArt = shape as ISmartArt;
137+
//Traverse through all nodes inside SmartArt
138+
foreach (ISmartArtNode node in smartArt.Nodes)
139+
{
140+
ModifyTextPart(node.TextBody);
141+
}
142+
break;
143+
}
144+
145+
case SlideItemType.OleObject:
146+
{
147+
// Modify OLE object size
148+
IOleObject oleObject = shape as IOleObject;
149+
oleObject.Width = 300;
150+
break;
151+
}
152+
}
153+
}
154+
155+
/// <summary>
156+
/// Modifies the text content within a text body.
157+
/// </summary>
158+
private static void ModifyTextPart(ITextBody textBody)
159+
{
160+
// Iterate through paragraphs in the text body
161+
foreach (IParagraph paragraph in textBody.Paragraphs)
162+
{
163+
// Iterate through text parts and modify the text
164+
foreach (ITextPart textPart in paragraph.TextParts)
165+
{
166+
textPart.Text = "Adventure Works";
167+
}
168+
}
169+
}
170+
}

0 commit comments

Comments
 (0)