Skip to content

Commit b574d47

Browse files
1012751: FT Ink samples added
1 parent c85bfe6 commit b574d47

File tree

14 files changed

+309
-0
lines changed

14 files changed

+309
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Create-ink-sample/Create-ink-sample.csproj" />
3+
</Solution>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Create_ink_sample</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Output\Result.docx">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
</ItemGroup>
26+
27+
</Project>
858 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

899 KB
Binary file not shown.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using Syncfusion.Drawing;
4+
using Syncfusion.Office;
5+
6+
namespace Create_ink
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
13+
{
14+
//Open a existing Word document.
15+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
16+
{
17+
// Get the last paragraph of document.
18+
WParagraph paragraph = document.LastParagraph;
19+
// Append an ink object to the paragraph.
20+
WInk inkObj = paragraph.AppendInk(80, 20);
21+
// Get the traces collection from the ink object (traces represent the drawing strokes).
22+
IOfficeInkTraces traces = inkObj.Traces;
23+
// Retrieve an array of points that define the path of the ink stroke.
24+
PointF[] tracePoints = new PointF[]
25+
{
26+
new PointF(15f,35f), new PointF(32f,14f), new PointF(42f,12f), new PointF(52f,28f), new PointF(46f,45f),
27+
new PointF(52f,36f), new PointF(67f,40f), new PointF(69f,48f), new PointF(61f,42f), new PointF(81f,40f),
28+
new PointF(88f,52f), new PointF(107f,38f), new PointF(125f,45f), new PointF(138f,54f), new PointF(123f,49f),
29+
new PointF(133f,25f), new PointF(170f,43f), new PointF(190f,47f), new PointF(85f,56f), new PointF(8f,44f)
30+
};
31+
// Add a new trace (stroke) to the traces collection using the retrieved points.
32+
IOfficeInkTrace trace = traces.Add(tracePoints);
33+
// Configure the appearance of the ink.
34+
// Get the brush object associated with the trace to configure its appearance.
35+
IOfficeInkBrush brush = trace.Brush;
36+
// Set the ink effect type to None (Pen effect applied).
37+
brush.InkEffect = OfficeInkEffectType.None;
38+
// Set the color of the ink stroke.
39+
brush.Color = Color.Black;
40+
// Set the size (thickness) of the ink stroke to 1.5 units.
41+
brush.Size = new SizeF(1.5f, 1.5f);
42+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
43+
{
44+
//Saves the Word document to file stream.
45+
document.Save(outputFileStream, FormatType.Docx);
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Create Ink in a Word document using C#
2+
3+
The Syncfusion&reg; [.NET Word Library](https://www.syncfusion.com/document-processing/word-framework/net/word-library) (DocIO) empowers you to create, read, and edit Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can **create Ink elements in a Word document** using C#.
4+
5+
## Steps to create Ink elements in a Word document programmatically
6+
7+
Step 1: Create a new .NET Core console application project.
8+
9+
Step 2: Install the [Syncfusion.DocIO.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIO.Net.Core) NuGet package as a reference to your project from [NuGet.org](https://www.nuget.org/).
10+
11+
Step 3: Include the following namespaces in the Program.cs file.
12+
13+
```csharp
14+
using Syncfusion.DocIO;
15+
using Syncfusion.DocIO.DLS;
16+
using Syncfusion.Drawing;
17+
using Syncfusion.Office;
18+
```
19+
20+
Step 4: Add the following code snippet in Program.cs file to create ink in a Word document.
21+
22+
```csharp
23+
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
24+
{
25+
//Open a existing Word document.
26+
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
27+
{
28+
// Get the last paragraph of document.
29+
WParagraph paragraph = document.LastParagraph;
30+
// Append an ink object to the paragraph.
31+
WInk inkObj = paragraph.AppendInk(80, 20);
32+
// Get the traces collection from the ink object (traces represent the drawing strokes).
33+
IOfficeInkTraces traces = inkObj.Traces;
34+
// Retrieve an array of points that define the path of the ink stroke.
35+
PointF[] tracePoints = new PointF[]
36+
{
37+
new PointF(15f,35f), new PointF(32f,14f), new PointF(42f,12f), new PointF(52f,28f), new PointF(46f,45f),
38+
new PointF(52f,36f), new PointF(67f,40f), new PointF(69f,48f), new PointF(61f,42f), new PointF(81f,40f),
39+
new PointF(88f,52f), new PointF(107f,38f), new PointF(125f,45f), new PointF(138f,54f), new PointF(123f,49f),
40+
new PointF(133f,25f), new PointF(170f,43f), new PointF(190f,47f), new PointF(85f,56f), new PointF(8f,44f)
41+
};
42+
// Add a new trace (stroke) to the traces collection using the retrieved points.
43+
IOfficeInkTrace trace = traces.Add(tracePoints);
44+
// Configure the appearance of the ink.
45+
// Get the brush object associated with the trace to configure its appearance.
46+
IOfficeInkBrush brush = trace.Brush;
47+
// Set the ink effect type to None (Pen effect applied).
48+
brush.InkEffect = OfficeInkEffectType.None;
49+
// Set the color of the ink stroke.
50+
brush.Color = Color.Black;
51+
// Set the size (thickness) of the ink stroke to 1.5 units.
52+
brush.Size = new SizeF(1.5f, 1.5f);
53+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
54+
{
55+
//Saves the Word document to file stream.
56+
document.Save(outputFileStream, FormatType.Docx);
57+
}
58+
}
59+
}
60+
```
61+
62+
More information about Create ink in a Word document can be refer in this [documentation](https://help.syncfusion.com/document-processing/word/word-library/net/working-with-ink) section.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="Edit-ink-sample/Edit-ink-sample.csproj" />
3+
</Solution>
1.63 MB
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Edit_ink_sample</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\Template.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Output\Result.docx">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
</ItemGroup>
26+
27+
</Project>

0 commit comments

Comments
 (0)