diff --git a/Paragraphs/Fix-image-position/.NET/Fix-image-position.sln b/Paragraphs/Fix-image-position/.NET/Fix-image-position.sln new file mode 100644 index 000000000..0f3dbd6ff --- /dev/null +++ b/Paragraphs/Fix-image-position/.NET/Fix-image-position.sln @@ -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 diff --git a/Paragraphs/Fix-image-position/.NET/Fix-image-position/Data/Image.png b/Paragraphs/Fix-image-position/.NET/Fix-image-position/Data/Image.png new file mode 100644 index 000000000..c9832cc63 Binary files /dev/null and b/Paragraphs/Fix-image-position/.NET/Fix-image-position/Data/Image.png differ diff --git a/Paragraphs/Fix-image-position/.NET/Fix-image-position/Fix-image-position.csproj b/Paragraphs/Fix-image-position/.NET/Fix-image-position/Fix-image-position.csproj new file mode 100644 index 000000000..abff4c2a1 --- /dev/null +++ b/Paragraphs/Fix-image-position/.NET/Fix-image-position/Fix-image-position.csproj @@ -0,0 +1,24 @@ + + + + Exe + net8.0 + Fix_image_position + enable + enable + + + + + + + + + Always + + + Always + + + + diff --git a/Paragraphs/Fix-image-position/.NET/Fix-image-position/Output/.gitkeep b/Paragraphs/Fix-image-position/.NET/Fix-image-position/Output/.gitkeep new file mode 100644 index 000000000..5f282702b --- /dev/null +++ b/Paragraphs/Fix-image-position/.NET/Fix-image-position/Output/.gitkeep @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Paragraphs/Fix-image-position/.NET/Fix-image-position/Program.cs b/Paragraphs/Fix-image-position/.NET/Fix-image-position/Program.cs new file mode 100644 index 000000000..78a7cd568 --- /dev/null +++ b/Paragraphs/Fix-image-position/.NET/Fix-image-position/Program.cs @@ -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); + } + } + } + /// + ///Add image to a table cell + /// + 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(); + } + } +}