-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from Suriya-Balamurugan/ES-900988-Caption-wit…
…hout-numbers Added sample to add image captions without numbers in a Word document
- Loading branch information
Showing
6 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
Table-Of-Contents/Caption-without-numbers/.NET/Caption-without-numbers.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31911.196 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Caption-without-numbers", "Caption-without-numbers\Caption-without-numbers.csproj", "{C17B90BC-F559-456B-B189-90B53FF6CDD4}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C17B90BC-F559-456B-B189-90B53FF6CDD4}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {EF357FC6-E9E5-4E3C-B932-43F727BE1DE4} | ||
EndGlobalSection | ||
EndGlobal |
25 changes: 25 additions & 0 deletions
25
...tents/Caption-without-numbers/.NET/Caption-without-numbers/Caption-without-numbers.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<RootNamespace>Caption_without_numbers</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="Data\MountainCycle.jpg"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Data\RoadCycle.jpg"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="Output\.gitkeep"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
Binary file added
BIN
+20.2 KB
...nts/Caption-without-numbers/.NET/Caption-without-numbers/Data/MountainCycle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+19.6 KB
...ontents/Caption-without-numbers/.NET/Caption-without-numbers/Data/RoadCycle.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
Table-Of-Contents/Caption-without-numbers/.NET/Caption-without-numbers/Output/.gitkeep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
70 changes: 70 additions & 0 deletions
70
Table-Of-Contents/Caption-without-numbers/.NET/Caption-without-numbers/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using Syncfusion.DocIO; | ||
using Syncfusion.DocIO.DLS; | ||
using Syncfusion.DocIORenderer; | ||
using System.IO; | ||
|
||
namespace Caption_without_numbers | ||
{ | ||
class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
//Creates a new Word document. | ||
using (WordDocument document = new WordDocument()) | ||
{ | ||
//Add a new section to the document. | ||
IWSection section = document.AddSection(); | ||
//Create a new paragraph and append a Table of Contents (TOC). | ||
IWParagraph paragraph = section.AddParagraph(); | ||
TableOfContent tableOfContent = paragraph.AppendTOC(1, 3); | ||
//Disable a flag to exclude heading style paragraphs in TOC entries. | ||
tableOfContent.UseHeadingStyles = false; | ||
//Set the name of SEQ field identifier for table of figures. | ||
tableOfContent.TableOfFiguresLabel = "Figure"; | ||
|
||
//Add a new paragraph for the first image. | ||
paragraph = section.AddParagraph(); | ||
//Add the first image to the paragraph. | ||
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/MountainCycle.jpg"), FileMode.Open, FileAccess.ReadWrite); | ||
IWPicture picture = paragraph.AppendPicture(imageStream); | ||
//Add an image caption. | ||
paragraph = picture.AddCaption("Figure", CaptionNumberingFormat.Number, CaptionPosition.AfterImage); | ||
//Add text to the caption paragraph. | ||
paragraph.AppendText(" " + "Mountain-Cycle"); | ||
//Apply formatting to the caption. | ||
paragraph.ParagraphFormat.BeforeSpacing = 8; | ||
paragraph.ParagraphFormat.AfterSpacing = 8; | ||
//Hide the caption numbering. | ||
WSeqField field = paragraph.ChildEntities[1] as WSeqField; | ||
field.HideResult = true; | ||
|
||
//Add a new paragraph for the second image. | ||
paragraph = section.AddParagraph(); | ||
//Add the second image to the paragraph. | ||
imageStream = new FileStream(Path.GetFullPath(@"Data/RoadCycle.jpg"), FileMode.Open, FileAccess.ReadWrite); | ||
picture = paragraph.AppendPicture(imageStream); | ||
//Add an image caption. | ||
paragraph = picture.AddCaption("Figure", CaptionNumberingFormat.Number, CaptionPosition.AfterImage); | ||
//Add text to the caption paragraph. | ||
paragraph.AppendText(" " + "Road-Cycle"); | ||
//Apply formatting to the caption. | ||
paragraph.ParagraphFormat.BeforeSpacing = 8; | ||
paragraph.ParagraphFormat.AfterSpacing = 8; | ||
//Hide the caption numbering. | ||
field = paragraph.ChildEntities[1] as WSeqField; | ||
field.HideResult = true; | ||
|
||
//Update the fields in the Word document. | ||
document.UpdateDocumentFields(); | ||
//Update the Table of Contents (TOC). | ||
document.UpdateTableOfContents(); | ||
//Create file stream. | ||
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite)) | ||
{ | ||
//Save the Word document to file stream. | ||
document.Save(outputFileStream, FormatType.Docx); | ||
} | ||
} | ||
} | ||
} | ||
} |