-
Notifications
You must be signed in to change notification settings - Fork 309
/
Program.cs
103 lines (82 loc) · 3.69 KB
/
Program.cs
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Copyright (c) Microsoft. All rights reserved.
using Microsoft.KernelMemory.DataFormats;
using Microsoft.KernelMemory.DataFormats.Office;
using Microsoft.KernelMemory.DataFormats.Pdf;
using Microsoft.KernelMemory.Pipeline;
FileContent content = new(MimeTypes.PlainText);
// ===================================================================================================================
// MS Word example
Console.WriteLine("===============================");
Console.WriteLine("=== Text in mswordfile.docx ===");
Console.WriteLine("===============================");
var msWordDecoder = new MsWordDecoder();
content = await msWordDecoder.DecodeAsync("mswordfile.docx");
foreach (FileSection section in content.Sections)
{
Console.WriteLine($"Page: {section.Number}/{content.Sections.Count}");
Console.WriteLine(section.Content);
Console.WriteLine("-----");
}
Console.WriteLine("============================");
Console.WriteLine("Press a Enter to continue...");
Console.ReadLine();
// ===================================================================================================================
// MS PowerPoint example
Console.WriteLine("===============================");
Console.WriteLine("=== Text in mspowerpointfile.pptx ===");
Console.WriteLine("===============================");
var msPowerPointDecoder = new MsPowerPointDecoder();
content = await msPowerPointDecoder.DecodeAsync("mspowerpointfile.pptx");
foreach (FileSection section in content.Sections)
{
Console.WriteLine($"Slide: {section.Number}/{content.Sections.Count}");
Console.WriteLine(section.Content);
Console.WriteLine("-----");
}
Console.WriteLine("============================");
Console.WriteLine("Press a Enter to continue...");
Console.ReadLine();
// ===================================================================================================================
// MS Excel example
Console.WriteLine("===============================");
Console.WriteLine("=== Text in msexcelfile.xlsx ===");
Console.WriteLine("===============================");
var msExcelDecoder = new MsExcelDecoder();
content = await msExcelDecoder.DecodeAsync("msexcelfile.xlsx");
foreach (FileSection section in content.Sections)
{
Console.WriteLine($"Worksheet: {section.Number}/{content.Sections.Count}");
Console.WriteLine(section.Content);
Console.WriteLine("-----");
}
Console.WriteLine("============================");
Console.WriteLine("Press a Enter to continue...");
Console.ReadLine();
// ===================================================================================================================
// PDF example 1, short document
Console.WriteLine("=========================");
Console.WriteLine("=== Text in file1.pdf ===");
Console.WriteLine("=========================");
var pdfDecoder = new PdfDecoder();
content = await pdfDecoder.DecodeAsync("file1.pdf");
foreach (FileSection section in content.Sections)
{
Console.WriteLine($"Page: {section.Number}/{content.Sections.Count}");
Console.WriteLine(section.Content);
Console.WriteLine("-----");
}
Console.WriteLine("============================");
Console.WriteLine("Press a Enter to continue...");
Console.ReadLine();
// ===================================================================================================================
// PDF example 2, scanned book
Console.WriteLine("=========================");
Console.WriteLine("=== Text in file2.pdf ===");
Console.WriteLine("=========================");
content = await pdfDecoder.DecodeAsync("file2.pdf");
foreach (FileSection section in content.Sections)
{
Console.WriteLine($"Page: {section.Number}/{content.Sections.Count}");
Console.WriteLine(section.Content);
Console.WriteLine("-----");
}