Skip to content

Commit

Permalink
Merge pull request #284 from Suriya-Balamurugan/ES-900988-Caption-wit…
Browse files Browse the repository at this point in the history
…hout-numbers

Added sample to add image captions without numbers in a Word document
  • Loading branch information
MohanaselvamJothi authored Oct 30, 2024
2 parents 3240559 + abc87b5 commit 756c5b7
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 0 deletions.
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
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>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

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);
}
}
}
}
}

0 comments on commit 756c5b7

Please sign in to comment.