Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Paragraphs/Fix-image-position/.NET/Fix-image-position.sln
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 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fix-image-position", "Fix-image-position\Fix-image-position.csproj", "{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA22BFD7-89F9-4F72-BECC-743931FBDFA6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ADDC6FEE-8718-4B00-B091-6C4DC0CBF62A}
EndGlobalSection
EndGlobal
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,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Fix_image_position</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Image.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

62 changes: 62 additions & 0 deletions Paragraphs/Fix-image-position/.NET/Fix-image-position/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;

namespace Fix_image_position
{
internal class Program
{
static void Main(string[] args)
{
// Open the Word document
using (WordDocument document = new WordDocument())
{
//Adds a section into Word document
IWSection section = document.AddSection();
//Adds a new table into Word document
IWTable table = section.AddTable();
//Specifies the total number of rows & columns
table.ResetCells(2, 2);
//Remove borders
table.TableFormat.Borders.BorderType = BorderStyle.None;

//Iterate through all rows
foreach (WTableRow row in table.Rows)
{
//Iterate through all cells
foreach (WTableCell cell in row.Cells)
{
//Add Image to the cell
AddImageToCell(cell);
}
}
// Save the modified document to a new file
using (FileStream docStream1 = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.Write))
{
document.Save(docStream1, FormatType.Docx);
}
}
}
///<summary>
///Add image to a table cell
///</summary>
static void AddImageToCell(WTableCell cell)
{
//Specifies the same padding as table option as false to preserve current cell padding
cell.CellFormat.SamePaddingsAsTable = false;
//Add cell paddings
cell.CellFormat.Paddings.Left = 10f;
cell.CellFormat.Paddings.Right = 10f;
cell.CellFormat.Paddings.Top = 20f;
cell.CellFormat.Paddings.Bottom = 20f;

//Adds the image into the cell.
FileStream imageStream = new FileStream(Path.GetFullPath(@"Data/Image.png"), FileMode.Open, FileAccess.ReadWrite);
IWPicture picture = cell.AddParagraph().AppendPicture(imageStream);
//Set height and width for the image
picture.Height = 220;
picture.Width = 220;
//Close the image stream
imageStream.Close();
}
}
}
Loading