Skip to content

Commit b614bfb

Browse files
Merge branch 'SyncfusionExamples:main' into main
2 parents 343bef1 + b78a969 commit b614bfb

File tree

10 files changed

+478
-219
lines changed

10 files changed

+478
-219
lines changed

Getting-Started/.NET/Create-Word-document/Create-Word-document.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,22 @@
1212
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
1313
</ItemGroup>
1414

15+
<ItemGroup>
16+
<None Update="Data\AdventureCycle.jpg">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Data\Mountain-200.jpg">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Data\Mountain-300.jpg">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
<None Update="Data\Road-550-W.jpg">
26+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
27+
</None>
28+
<None Update="Output\.gitkeep">
29+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
30+
</None>
31+
</ItemGroup>
32+
1533
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

136 KB
Binary file not shown.

Getting-Started/.NET/Create-Word-document/Program.cs

Lines changed: 215 additions & 219 deletions
Large diffs are not rendered by default.
Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
# Create Word document using C#
2+
3+
The Syncfusion&reg; [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) empowers you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **create Word document** using C#.
4+
5+
## Steps to create Word document programmatically
6+
7+
Step 1: Create a new .NET Core console application project.
8+
9+
Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).
10+
11+
Step 3: Include the following namespaces in the Program.cs file.
12+
13+
```csharp
14+
using Syncfusion.DocIO.DLS;
15+
using Syncfusion.DocIO;
16+
```
17+
18+
Step 4: Add the following code snippet in Program.cs file to split Word document by bookmarks.
19+
20+
```csharp
21+
// Creating a new document.
22+
WordDocument document = new WordDocument();
23+
//Adding a new section to the document.
24+
WSection section = document.AddSection() as WSection;
25+
//Set Margin of the section
26+
section.PageSetup.Margins.All = 72;
27+
//Set page size of the section
28+
section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792);
29+
30+
//Create Paragraph styles
31+
WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle;
32+
style.CharacterFormat.FontName = "Calibri";
33+
style.CharacterFormat.FontSize = 11f;
34+
style.ParagraphFormat.BeforeSpacing = 0;
35+
style.ParagraphFormat.AfterSpacing = 8;
36+
style.ParagraphFormat.LineSpacing = 13.8f;
37+
38+
style = document.AddParagraphStyle("Heading 1") as WParagraphStyle;
39+
style.ApplyBaseStyle("Normal");
40+
style.CharacterFormat.FontName = "Calibri Light";
41+
style.CharacterFormat.FontSize = 16f;
42+
style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181);
43+
style.ParagraphFormat.BeforeSpacing = 12;
44+
style.ParagraphFormat.AfterSpacing = 0;
45+
style.ParagraphFormat.Keep = true;
46+
style.ParagraphFormat.KeepFollow = true;
47+
style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1;
48+
49+
IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
50+
// Get the image stream.
51+
FileStream imageStream = new FileStream(@Path.GetFullPath("Data/AdventureCycle.jpg"), FileMode.Open, FileAccess.Read);
52+
IWPicture picture = paragraph.AppendPicture(imageStream);
53+
picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
54+
picture.VerticalOrigin = VerticalOrigin.Margin;
55+
picture.VerticalPosition = -45;
56+
picture.HorizontalOrigin = HorizontalOrigin.Column;
57+
picture.HorizontalPosition = 263.5f;
58+
picture.WidthScale = 20;
59+
picture.HeightScale = 15;
60+
61+
paragraph.ApplyStyle("Normal");
62+
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
63+
WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange;
64+
textRange.CharacterFormat.FontSize = 12f;
65+
textRange.CharacterFormat.FontName = "Calibri";
66+
textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red;
67+
68+
//Append paragraph.
69+
paragraph = section.AddParagraph();
70+
paragraph.ApplyStyle("Heading 1");
71+
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
72+
textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange;
73+
textRange.CharacterFormat.FontSize = 18f;
74+
textRange.CharacterFormat.FontName = "Calibri";
75+
76+
//Append paragraph.
77+
paragraph = section.AddParagraph();
78+
paragraph.ParagraphFormat.FirstLineIndent = 36;
79+
paragraph.BreakCharacterFormat.FontSize = 12f;
80+
textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.") as WTextRange;
81+
textRange.CharacterFormat.FontSize = 12f;
82+
83+
//Append paragraph.
84+
paragraph = section.AddParagraph();
85+
paragraph.ParagraphFormat.FirstLineIndent = 36;
86+
paragraph.BreakCharacterFormat.FontSize = 12f;
87+
textRange = paragraph.AppendText("In 2000, AdventureWorks Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the AdventureWorks Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.") as WTextRange;
88+
textRange.CharacterFormat.FontSize = 12f;
89+
90+
paragraph = section.AddParagraph();
91+
paragraph.ApplyStyle("Heading 1");
92+
paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
93+
textRange = paragraph.AppendText("Product Overview") as WTextRange;
94+
textRange.CharacterFormat.FontSize = 16f;
95+
textRange.CharacterFormat.FontName = "Calibri";
96+
97+
//Append table.
98+
IWTable table = section.AddTable();
99+
table.ResetCells(3, 2);
100+
table.TableFormat.Borders.BorderType = BorderStyle.None;
101+
table.TableFormat.IsAutoResized = true;
102+
//Append paragraph.
103+
paragraph = table[0, 0].AddParagraph();
104+
paragraph.ParagraphFormat.AfterSpacing = 0;
105+
paragraph.BreakCharacterFormat.FontSize = 12f;
106+
//Append picture to the paragraph.
107+
FileStream image1 = new FileStream(Path.GetFullPath(@"Data/Mountain-200.jpg"), FileMode.Open, FileAccess.Read);
108+
picture = paragraph.AppendPicture(image1);
109+
picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom;
110+
picture.VerticalOrigin = VerticalOrigin.Paragraph;
111+
picture.VerticalPosition = 4.5f;
112+
picture.HorizontalOrigin = HorizontalOrigin.Column;
113+
picture.HorizontalPosition = -2.15f;
114+
picture.WidthScale = 79;
115+
picture.HeightScale = 79;
116+
117+
//Append paragraph.
118+
paragraph = table[0, 1].AddParagraph();
119+
paragraph.ApplyStyle("Heading 1");
120+
paragraph.ParagraphFormat.AfterSpacing = 0;
121+
paragraph.ParagraphFormat.LineSpacing = 12f;
122+
paragraph.AppendText("Mountain-200");
123+
//Append paragraph.
124+
paragraph = table[0, 1].AddParagraph();
125+
paragraph.ParagraphFormat.AfterSpacing = 0;
126+
paragraph.ParagraphFormat.LineSpacing = 12f;
127+
paragraph.BreakCharacterFormat.FontSize = 12f;
128+
paragraph.BreakCharacterFormat.FontName = "Times New Roman";
129+
textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange;
130+
textRange.CharacterFormat.FontSize = 12f;
131+
textRange.CharacterFormat.FontName = "Times New Roman";
132+
textRange = paragraph.AppendText("Size: 38\r") as WTextRange;
133+
textRange.CharacterFormat.FontSize = 12f;
134+
textRange.CharacterFormat.FontName = "Times New Roman";
135+
textRange = paragraph.AppendText("Weight: 25\r") as WTextRange;
136+
textRange.CharacterFormat.FontSize = 12f;
137+
textRange.CharacterFormat.FontName = "Times New Roman";
138+
textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange;
139+
textRange.CharacterFormat.FontSize = 12f;
140+
textRange.CharacterFormat.FontName = "Times New Roman";
141+
//Append paragraph.
142+
paragraph = table[0, 1].AddParagraph();
143+
paragraph.ParagraphFormat.AfterSpacing = 0;
144+
paragraph.ParagraphFormat.LineSpacing = 12f;
145+
paragraph.BreakCharacterFormat.FontSize = 12f;
146+
147+
//Append paragraph.
148+
paragraph = table[1, 0].AddParagraph();
149+
paragraph.ApplyStyle("Heading 1");
150+
paragraph.ParagraphFormat.AfterSpacing = 0;
151+
paragraph.ParagraphFormat.LineSpacing = 12f;
152+
paragraph.AppendText("Mountain-300 ");
153+
//Append paragraph.
154+
paragraph = table[1, 0].AddParagraph();
155+
paragraph.ParagraphFormat.AfterSpacing = 0;
156+
paragraph.ParagraphFormat.LineSpacing = 12f;
157+
paragraph.BreakCharacterFormat.FontSize = 12f;
158+
paragraph.BreakCharacterFormat.FontName = "Times New Roman";
159+
textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange;
160+
textRange.CharacterFormat.FontSize = 12f;
161+
textRange.CharacterFormat.FontName = "Times New Roman";
162+
textRange = paragraph.AppendText("Size: 35\r") as WTextRange;
163+
textRange.CharacterFormat.FontSize = 12f;
164+
textRange.CharacterFormat.FontName = "Times New Roman";
165+
textRange = paragraph.AppendText("Weight: 22\r") as WTextRange;
166+
textRange.CharacterFormat.FontSize = 12f;
167+
textRange.CharacterFormat.FontName = "Times New Roman";
168+
textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange;
169+
textRange.CharacterFormat.FontSize = 12f;
170+
textRange.CharacterFormat.FontName = "Times New Roman";
171+
//Append paragraph.
172+
paragraph = table[1, 0].AddParagraph();
173+
paragraph.ParagraphFormat.AfterSpacing = 0;
174+
paragraph.ParagraphFormat.LineSpacing = 12f;
175+
paragraph.BreakCharacterFormat.FontSize = 12f;
176+
177+
//Append paragraph.
178+
paragraph = table[1, 1].AddParagraph();
179+
paragraph.ApplyStyle("Heading 1");
180+
paragraph.ParagraphFormat.LineSpacing = 12f;
181+
//Append picture to the paragraph.
182+
FileStream image2 = new FileStream(Path.GetFullPath(@"Data/Mountain-300.jpg"), FileMode.Open, FileAccess.Read);
183+
picture = paragraph.AppendPicture(image2);
184+
picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom;
185+
picture.VerticalOrigin = VerticalOrigin.Paragraph;
186+
picture.VerticalPosition = 8.2f;
187+
picture.HorizontalOrigin = HorizontalOrigin.Column;
188+
picture.HorizontalPosition = -14.95f;
189+
picture.WidthScale = 75;
190+
picture.HeightScale = 75;
191+
192+
//Append paragraph.
193+
paragraph = table[2, 0].AddParagraph();
194+
paragraph.ApplyStyle("Heading 1");
195+
paragraph.ParagraphFormat.LineSpacing = 12f;
196+
//Append picture to the paragraph.
197+
FileStream image3 = new FileStream(Path.GetFullPath(@"Data/Road-550-W.jpg"), FileMode.Open, FileAccess.Read);
198+
picture = paragraph.AppendPicture(image3);
199+
picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom;
200+
picture.VerticalOrigin = VerticalOrigin.Paragraph;
201+
picture.VerticalPosition = 3.75f;
202+
picture.HorizontalOrigin = HorizontalOrigin.Column;
203+
picture.HorizontalPosition = -5f;
204+
picture.WidthScale = 92;
205+
picture.HeightScale = 92;
206+
207+
//Append paragraph.
208+
paragraph = table[2, 1].AddParagraph();
209+
paragraph.ApplyStyle("Heading 1");
210+
paragraph.ParagraphFormat.AfterSpacing = 0;
211+
paragraph.ParagraphFormat.LineSpacing = 12f;
212+
paragraph.AppendText("Road-150 ");
213+
//Append paragraph.
214+
paragraph = table[2, 1].AddParagraph();
215+
paragraph.ParagraphFormat.AfterSpacing = 0;
216+
paragraph.ParagraphFormat.LineSpacing = 12f;
217+
paragraph.BreakCharacterFormat.FontSize = 12f;
218+
paragraph.BreakCharacterFormat.FontName = "Times New Roman";
219+
textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange;
220+
textRange.CharacterFormat.FontSize = 12f;
221+
textRange.CharacterFormat.FontName = "Times New Roman";
222+
textRange = paragraph.AppendText("Size: 44\r") as WTextRange;
223+
textRange.CharacterFormat.FontSize = 12f;
224+
textRange.CharacterFormat.FontName = "Times New Roman";
225+
textRange = paragraph.AppendText("Weight: 14\r") as WTextRange;
226+
textRange.CharacterFormat.FontSize = 12f;
227+
textRange.CharacterFormat.FontName = "Times New Roman";
228+
textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange;
229+
textRange.CharacterFormat.FontSize = 12f;
230+
textRange.CharacterFormat.FontName = "Times New Roman";
231+
//Append paragraph.
232+
section.AddParagraph();
233+
234+
//Save the Word document to FileStream
235+
using FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create);
236+
document.Save(outputStream, FormatType.Docx);
237+
```
238+
239+
More information about Create a Word document can be refer in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-word-document) section.

Word-to-PDF-Conversion/Convert-Word-document-to-PDF/Docker/Alpine/WordToPDFDockerSample/WordToPDFDockerSample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
1212
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.116.1" />
13+
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.0.1" />
1314
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
1415
</ItemGroup>
1516

Word-to-PDF-Conversion/Convert-Word-document-to-PDF/Docker/CentOS/WordToPDFDockerSample/WordToPDFDockerSample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.14" />
1212
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.116.1" />
13+
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.0.1" />
1314
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
1415
</ItemGroup>
1516

Word-to-PDF-Conversion/Convert-Word-document-to-PDF/Docker/Debian/WordToPDFDockerSample/WordToPDFDockerSample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
1212
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.116.1" />
13+
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.0.1" />
1314
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
1415
</ItemGroup>
1516

Word-to-PDF-Conversion/Convert-Word-document-to-PDF/Docker/Fedora/WordToPDFDockerSample/WordToPDFDockerSample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.14" />
1212
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.116.1" />
13+
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.0.1" />
1314
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
1415
</ItemGroup>
1516

Word-to-PDF-Conversion/Convert-Word-document-to-PDF/Docker/Ubuntu/WordToPDFDockerSample/WordToPDFDockerSample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.14" />
1212
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="3.116.1" />
13+
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.0.1" />
1314
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
1415
</ItemGroup>
1516

0 commit comments

Comments
 (0)