File tree Expand file tree Collapse file tree 4 files changed +84
-0
lines changed
Expand file tree Collapse file tree 4 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 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" , "{99837ED5-36ED-4095-8A53-9D922F06FF32}"
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+ {99837ED5-36ED-4095-8A53-9D922F06FF32} .Debug| Any CPU .ActiveCfg = Debug| Any CPU
15+ {99837ED5-36ED-4095-8A53-9D922F06FF32} .Debug| Any CPU .Build .0 = Debug| Any CPU
16+ {99837ED5-36ED-4095-8A53-9D922F06FF32} .Release| Any CPU .ActiveCfg = Release| Any CPU
17+ {99837ED5-36ED-4095-8A53-9D922F06FF32} .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 = {04411ABE-09D0-42C8-B555-9D64AA5C1646}
24+ EndGlobalSection
25+ EndGlobal
Original file line number Diff line number Diff line change 1+ <Project Sdk =" Microsoft.NET.Sdk" >
2+
3+ <PropertyGroup >
4+ <OutputType >Exe</OutputType >
5+ <TargetFramework >net8.0</TargetFramework >
6+ <RootNamespace >Extract_images_from_Word_document</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+ </Project >
Original file line number Diff line number Diff line change 1+ using Syncfusion . DocIO ;
2+ using Syncfusion . DocIO . DLS ;
3+ using System ;
4+ using System . Collections . Generic ;
5+ using System . IO ;
6+
7+ namespace Extract_images_from_Word_document
8+ {
9+ internal class Program
10+ {
11+ static void Main ( string [ ] args )
12+ {
13+ // Open the file as a stream.
14+ using ( FileStream docStream = new FileStream ( Path . GetFullPath ( @"../../../Data/Template.docx" ) , FileMode . Open , FileAccess . Read ) )
15+ {
16+ // Load the file stream into a Word document.
17+ using ( WordDocument document = new WordDocument ( docStream , FormatType . Docx ) )
18+ {
19+ // Find all pictures by EntityType in the Word document.
20+ List < Entity > pictures = document . FindAllItemsByProperty ( EntityType . Picture , null , null ) ;
21+
22+ // Iterate through the pictures and save each one as an image file.
23+ for ( int i = 0 ; i < pictures . Count ; i ++ )
24+ {
25+ WPicture image = pictures [ i ] as WPicture ;
26+
27+ // Use a MemoryStream to handle the image bytes from the picture.
28+ using ( MemoryStream memoryStream = new MemoryStream ( image . ImageBytes ) )
29+ {
30+ // Define the path where the image will be saved.
31+ string imagePath = Path . GetFullPath ( @"../../../Image-" + i + ".jpeg" ) ;
32+
33+ // Create a FileStream to write the image to the specified path.
34+ using ( FileStream filestream = new FileStream ( imagePath , FileMode . Create , FileAccess . Write ) )
35+ {
36+ memoryStream . CopyTo ( filestream ) ;
37+ }
38+ }
39+ }
40+ }
41+ }
42+ }
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments