Skip to content

Commit 756c5b7

Browse files
Merge pull request #284 from Suriya-Balamurugan/ES-900988-Caption-without-numbers
Added sample to add image captions without numbers in a Word document
2 parents 3240559 + abc87b5 commit 756c5b7

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-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 16
4+
VisualStudioVersion = 16.0.31911.196
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Caption-without-numbers", "Caption-without-numbers\Caption-without-numbers.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}"
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+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.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 = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Caption_without_numbers</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<None Update="Data\MountainCycle.jpg">
15+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
16+
</None>
17+
<None Update="Data\RoadCycle.jpg">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
<None Update="Output\.gitkeep">
21+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
22+
</None>
23+
</ItemGroup>
24+
25+
</Project>
20.2 KB
Loading
19.6 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using Syncfusion.DocIORenderer;
4+
using System.IO;
5+
6+
namespace Caption_without_numbers
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
//Creates a new Word document.
13+
using (WordDocument document = new WordDocument())
14+
{
15+
//Add a new section to the document.
16+
IWSection section = document.AddSection();
17+
//Create a new paragraph and append a Table of Contents (TOC).
18+
IWParagraph paragraph = section.AddParagraph();
19+
TableOfContent tableOfContent = paragraph.AppendTOC(1, 3);
20+
//Disable a flag to exclude heading style paragraphs in TOC entries.
21+
tableOfContent.UseHeadingStyles = false;
22+
//Set the name of SEQ field identifier for table of figures.
23+
tableOfContent.TableOfFiguresLabel = "Figure";
24+
25+
//Add a new paragraph for the first image.
26+
paragraph = section.AddParagraph();
27+
//Add the first image to the paragraph.
28+
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/MountainCycle.jpg"), FileMode.Open, FileAccess.ReadWrite);
29+
IWPicture picture = paragraph.AppendPicture(imageStream);
30+
//Add an image caption.
31+
paragraph = picture.AddCaption("Figure", CaptionNumberingFormat.Number, CaptionPosition.AfterImage);
32+
//Add text to the caption paragraph.
33+
paragraph.AppendText(" " + "Mountain-Cycle");
34+
//Apply formatting to the caption.
35+
paragraph.ParagraphFormat.BeforeSpacing = 8;
36+
paragraph.ParagraphFormat.AfterSpacing = 8;
37+
//Hide the caption numbering.
38+
WSeqField field = paragraph.ChildEntities[1] as WSeqField;
39+
field.HideResult = true;
40+
41+
//Add a new paragraph for the second image.
42+
paragraph = section.AddParagraph();
43+
//Add the second image to the paragraph.
44+
imageStream = new FileStream(Path.GetFullPath(@"Data/RoadCycle.jpg"), FileMode.Open, FileAccess.ReadWrite);
45+
picture = paragraph.AppendPicture(imageStream);
46+
//Add an image caption.
47+
paragraph = picture.AddCaption("Figure", CaptionNumberingFormat.Number, CaptionPosition.AfterImage);
48+
//Add text to the caption paragraph.
49+
paragraph.AppendText(" " + "Road-Cycle");
50+
//Apply formatting to the caption.
51+
paragraph.ParagraphFormat.BeforeSpacing = 8;
52+
paragraph.ParagraphFormat.AfterSpacing = 8;
53+
//Hide the caption numbering.
54+
field = paragraph.ChildEntities[1] as WSeqField;
55+
field.HideResult = true;
56+
57+
//Update the fields in the Word document.
58+
document.UpdateDocumentFields();
59+
//Update the Table of Contents (TOC).
60+
document.UpdateTableOfContents();
61+
//Create file stream.
62+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
63+
{
64+
//Save the Word document to file stream.
65+
document.Save(outputFileStream, FormatType.Docx);
66+
}
67+
}
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)