-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
67 lines (57 loc) · 2.21 KB
/
Program.cs
File metadata and controls
67 lines (57 loc) · 2.21 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using Syncfusion.Pdf;
using Syncfusion.Pdf.Exporting;
using Syncfusion.Pdf.Parsing;
Syncfusion.Licensing.SyncfusionLicenseProvider
.RegisterLicense("<LICENSE-KEY>"); // TODO: Insert your license key here
List<string> filePathList = GetFilePathList(); // TODO: implement this method
// to retrieve a list of paths for the PDF files.
var allowedPdfExtensions = new[] { "pdf" };
foreach (var path in filePathList)
{
var pdfType = "undefined";
if (string.IsNullOrEmpty(path) || !File.Exists(path))
continue;
try
{
var ext = Path.GetExtension(path);
if (!string.IsNullOrEmpty(ext)
&& allowedPdfExtensions.Contains(ext.TrimStart('.'),
StringComparer.InvariantCultureIgnoreCase))
{
using var stream = new FileStream(path, FileMode.Open, FileAccess.Read);
var loadedDocument = new PdfLoadedDocument(stream);
var loadedPages = loadedDocument.Pages;
int charCount = 0;
int imageCount = 0;
foreach (PdfLoadedPage loadedPage in loadedPages)
{
var txt = loadedPage.ExtractText();
if (!string.IsNullOrEmpty(txt))
charCount += txt.Length;
var imagesInfo = loadedPage.GetImagesInfo();
if (imagesInfo != null)
imageCount += imagesInfo.Length;
}
loadedDocument.Close(true);
if (charCount > 0 && imageCount == 0)
pdfType = "text only";
else if (charCount == 0 && imageCount > 0)
pdfType = "images only";
else if (charCount > 0 && imageCount > 0)
pdfType = "text and images";
else
pdfType = "no text and no images";
}
else
pdfType = "non-PDF file";
}
catch (Exception e)
{
pdfType = $"error: {e.Message}";
}
DoSomething(pdfType); // TODO: do something with the [pdfType] variable
}
static List<string> GetFilePathList()
=> throw new NotSupportedException("TODO");
static List<string> DoSomething(string pdfType)
=> throw new NotSupportedException("TODO");