Skip to content

Commit ebdfe24

Browse files
Extract-images-from-Word-document-Net
1 parent 0753d20 commit ebdfe24

File tree

7 files changed

+187
-0
lines changed

7 files changed

+187
-0
lines changed
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.9.34622.214
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Extract-images-from-Word-document", "Extract-images-from-Word-document\Extract-images-from-Word-document.csproj", "{C586B837-80B6-481B-A4CD-B9C1D1375DE7}"
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+
{C586B837-80B6-481B-A4CD-B9C1D1375DE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C586B837-80B6-481B-A4CD-B9C1D1375DE7}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C586B837-80B6-481B-A4CD-B9C1D1375DE7}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C586B837-80B6-481B-A4CD-B9C1D1375DE7}.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 = {FEDBF663-E057-4930-9801-2198B6F072BA}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{C586B837-80B6-481B-A4CD-B9C1D1375DE7}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>Extract_images_from_Word_document</RootNamespace>
10+
<AssemblyName>Extract-images-from-Word-document</AssemblyName>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
14+
<Deterministic>true</Deterministic>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="Syncfusion.Compression.Base, Version=26.2462.7.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
37+
<HintPath>..\packages\Syncfusion.Compression.Base.26.2.7\lib\net462\Syncfusion.Compression.Base.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Syncfusion.DocIO.Base, Version=26.2462.7.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
40+
<HintPath>..\packages\Syncfusion.DocIO.WinForms.26.2.7\lib\net462\Syncfusion.DocIO.Base.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Syncfusion.Licensing, Version=26.2462.7.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Syncfusion.Licensing.26.2.7\lib\net462\Syncfusion.Licensing.dll</HintPath>
44+
</Reference>
45+
<Reference Include="Syncfusion.OfficeChart.Base, Version=26.2462.7.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
46+
<HintPath>..\packages\Syncfusion.OfficeChart.Base.26.2.7\lib\net462\Syncfusion.OfficeChart.Base.dll</HintPath>
47+
</Reference>
48+
<Reference Include="System" />
49+
<Reference Include="System.Core" />
50+
<Reference Include="System.Xml.Linq" />
51+
<Reference Include="System.Data.DataSetExtensions" />
52+
<Reference Include="Microsoft.CSharp" />
53+
<Reference Include="System.Data" />
54+
<Reference Include="System.Net.Http" />
55+
<Reference Include="System.Xml" />
56+
</ItemGroup>
57+
<ItemGroup>
58+
<Compile Include="Program.cs" />
59+
<Compile Include="Properties\AssemblyInfo.cs" />
60+
</ItemGroup>
61+
<ItemGroup>
62+
<None Include="App.config" />
63+
<None Include="packages.config" />
64+
</ItemGroup>
65+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
66+
</Project>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Extract_images_from_Word_document
11+
{
12+
internal class Program
13+
{
14+
static void Main(string[] args)
15+
{
16+
// Open the file as a stream.
17+
using (FileStream docStream = new FileStream(Path.GetFullPath(@"../../Data/Template.docx"), FileMode.Open, FileAccess.Read))
18+
{
19+
// Load the file stream into a Word document.
20+
using (WordDocument document = new WordDocument(docStream, FormatType.Docx))
21+
{
22+
// Find all pictures by EntityType in the Word document.
23+
List<Entity> pictures = document.FindAllItemsByProperty(EntityType.Picture, null, null);
24+
25+
// Iterate through the pictures and save each one as an image file.
26+
for (int i = 0; i < pictures.Count; i++)
27+
{
28+
WPicture image = pictures[i] as WPicture;
29+
30+
// Use a MemoryStream to handle the image bytes from the picture.
31+
using (MemoryStream memoryStream = new MemoryStream(image.ImageBytes))
32+
{
33+
// Define the path where the image will be saved.
34+
string imagePath = Path.GetFullPath(@"../../Image-" + i + ".jpeg");
35+
36+
// Create a FileStream to write the image to the specified path.
37+
using (FileStream filestream = new FileStream(imagePath, FileMode.Create, FileAccess.Write))
38+
{
39+
memoryStream.CopyTo(filestream);
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Extract-images-from-Word-document")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("Extract-images-from-Word-document")]
13+
[assembly: AssemblyCopyright("Copyright © 2024")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("c586b837-80b6-481b-a4cd-b9c1d1375de7")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Syncfusion.Compression.Base" version="26.2.7" targetFramework="net48" />
4+
<package id="Syncfusion.DocIO.WinForms" version="26.2.7" targetFramework="net48" />
5+
<package id="Syncfusion.Licensing" version="26.2.7" targetFramework="net48" />
6+
<package id="Syncfusion.OfficeChart.Base" version="26.2.7" targetFramework="net48" />
7+
</packages>

0 commit comments

Comments
 (0)