-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathProgram.cs
More file actions
45 lines (42 loc) · 1.68 KB
/
Copy pathProgram.cs
File metadata and controls
45 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using System;
using System.Diagnostics;
class Program
{
static void Main()
{
Stopwatch stopwatch = Stopwatch.StartNew();
try
{
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
// Open an existing Word document
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
using (DocIORenderer renderer = new DocIORenderer())
{
//Convert the entire Word document to images.
Stream[] imageStreams = document.RenderAsImages();
for (int i = 0; i < imageStreams.Length; i++)
{
//Save the image stream as file.
string imagePath = Path.Combine(Path.GetFullPath(@"Output/Images"), $"WordToImage_{i + 1}.jpg");
using (FileStream fileStreamOutput = new(imagePath, FileMode.Create, FileAccess.Write))
{
imageStreams[i].CopyTo(fileStreamOutput);
}
}
}
}
stopwatch.Stop();
Console.WriteLine($"Word To Image processed in {stopwatch.Elapsed.TotalSeconds} seconds");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error processing Word to Image: {ex.Message}");
}
}
}