Skip to content

Commit 563b6f5

Browse files
Merge pull request #509 from GOPINATH-SF4767/main
992090-How to convert a Word document to a thumbnail image without using any third-party NuGet packages.
2 parents 8233c28 + bb84296 commit 563b6f5

5 files changed

Lines changed: 89 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.36908.2 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert_Word_to_Thumbnail-Image", "Convert_Word_to_Thumbnail-Image\Convert_Word_to_Thumbnail-Image.csproj", "{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}"
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+
{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}.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 = {ABE93116-3AB5-4CD8-87C0-8C646A6CDC8C}
24+
EndGlobalSection
25+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Convert_Word_to_Thumbnail_Image</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
13+
<PackageReference Include="System.Drawing.Common" Version="*" />
14+
</ItemGroup>
15+
<ItemGroup>
16+
<None Update="Data\Input.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Output\.gitkeep">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
</ItemGroup>
23+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Syncfusion.DocIO;
2+
using Syncfusion.DocIO.DLS;
3+
using Syncfusion.DocIORenderer;
4+
using System.Drawing;
5+
6+
namespace Convert_Word_document_to_Thumbnail_Image
7+
{
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
//Open the Word document file stream.
13+
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open))
14+
{
15+
//Loads an existing Word document.
16+
using (WordDocument wordDocument = new WordDocument(fileStream, FormatType.Automatic))
17+
{
18+
//Creates an instance of DocIORenderer.
19+
using (DocIORenderer renderer = new DocIORenderer())
20+
{
21+
//Convert the first page of the Word document into an image.
22+
Stream imageStream = wordDocument.RenderAsImages(0, ExportImageFormat.Png);
23+
//Reset the stream position.
24+
imageStream.Position = 0;
25+
26+
//Resize image to thumbnail size.
27+
Image image = Image.FromStream(imageStream);
28+
Image thumbnail = image.GetThumbnailImage(600, 700, () => false, IntPtr.Zero);
29+
30+
//Save the image.
31+
thumbnail.Save(Path.GetFullPath(@"Output/Image1.png"), System.Drawing.Imaging.ImageFormat.Png);
32+
thumbnail.Dispose();
33+
imageStream.Dispose();
34+
image.Dispose();
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)