Skip to content

Commit 72cad48

Browse files
Added sample
1 parent 122d5fe commit 72cad48

6 files changed

Lines changed: 88 additions & 0 deletions

File tree

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 17
4+
VisualStudioVersion = 17.14.37216.2 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Fit_an_Image_Inside_a_Rectangle_Shape", "Fit_an_Image_Inside_a_Rectangle_Shape\Fit_an_Image_Inside_a_Rectangle_Shape.csproj", "{AF30512B-BF73-E738-E1D6-179374198043}"
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+
{AF30512B-BF73-E738-E1D6-179374198043}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{AF30512B-BF73-E738-E1D6-179374198043}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{AF30512B-BF73-E738-E1D6-179374198043}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{AF30512B-BF73-E738-E1D6-179374198043}.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 = {49E18A89-A198-41B2-9245-2940167C1CA3}
24+
EndGlobalSection
25+
EndGlobal
20.2 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<None Update="Output\.gitkeep">
16+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
17+
</None>
18+
</ItemGroup>
19+
20+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
4+
5+
namespace Fit_an_Image_Inside_a_Rectangle_Shape
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
//Create a new Word document
12+
using (WordDocument document = new WordDocument())
13+
{
14+
//Add a new section
15+
WSection section = document.AddSection() as WSection;
16+
//Add a new paragraph to the section.
17+
WParagraph paragraph = section.AddParagraph() as WParagraph;
18+
//Add a new rectangle shape
19+
Shape rectangle = paragraph.AppendShape(AutoShapeType.Rectangle, 150, 100);
20+
//Format the rectangle shape
21+
rectangle.VerticalPosition = 72;
22+
rectangle.HorizontalPosition = 72;
23+
//Add a new paragraph to a rectangle shape
24+
WParagraph para = rectangle.TextBody.AddParagraph() as WParagraph;
25+
//Append the picture to the paragraph
26+
WPicture picture = para.AppendPicture(File.ReadAllBytes("../../../Data/Mountain-200.jpg")) as WPicture;
27+
//Resize the picture according to rectangle shape
28+
picture.Width = rectangle.Width;
29+
picture.Height = rectangle.Height;
30+
picture.VerticalPosition = rectangle.VerticalPosition;
31+
picture.HorizontalPosition = rectangle.HorizontalPosition;
32+
//document.Settings.ResizeImageToFitInContainer = true;
33+
//Creates file stream.
34+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../Output/Result.docx"), FileMode.Create))
35+
{
36+
//Saves the Word document to file stream.
37+
document.Save(outputStream, FormatType.Docx);
38+
}
39+
}
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)