mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-20 03:17:57 +08:00
add examples directory and first example
This commit is contained in:
51
examples/Program.cs
Normal file
51
examples/Program.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
namespace UglyToad.Examples
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("Welcome to the PdfPig examples gallery!");
|
||||
|
||||
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
var filesDirectory = Path.Combine(baseDirectory, "..", "..", "..", "..", "src", "UglyToad.PdfPig.Tests", "Integration", "Documents");
|
||||
|
||||
var examples = new Dictionary<int, (string name, Action action)>
|
||||
{
|
||||
{1,
|
||||
("Extract Words with newline detection",
|
||||
() => OpenDocumentAndExtractWords.Run(Path.Combine(filesDirectory, "Two Page Text Only - from libre office.pdf")))
|
||||
}
|
||||
};
|
||||
|
||||
var choices = string.Join(Environment.NewLine, examples.Select(x => $"{x.Key}: {x.Value.name}"));
|
||||
|
||||
Console.WriteLine(choices);
|
||||
Console.WriteLine();
|
||||
|
||||
do
|
||||
{
|
||||
Console.Write("Enter a number to pick an example (enter 'q' to exit):");
|
||||
|
||||
var val = Console.ReadLine();
|
||||
|
||||
if (!int.TryParse(val, out var opt) || !examples.TryGetValue(opt, out var act))
|
||||
{
|
||||
if (string.Equals(val, "q", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine($"No option with value: {val}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
act.action.Invoke();
|
||||
} while (true);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user