mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-04-05 20:55:01 +08:00
actions build and test v003
also adds a console runner for testing arbitrary files
This commit is contained in:
parent
d5be096130
commit
3437b48925
2
.github/workflows/build_and_test.yml
vendored
2
.github/workflows/build_and_test.yml
vendored
@ -11,7 +11,7 @@ jobs:
|
||||
- name: Set up dotnet core
|
||||
uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: "2.0.x"
|
||||
dotnet-version: "2.1.x"
|
||||
|
||||
- name: Add msbuild to PATH
|
||||
uses: microsoft/setup-msbuild@v1.0.2
|
||||
|
73
tools/ConsoleRunner/Program.cs
Normal file
73
tools/ConsoleRunner/Program.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Console = System.Console;
|
||||
|
||||
namespace UglyToad.PdfPig.ConsoleRunner
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
{
|
||||
Console.WriteLine("Only 1 argument, path to test file directory, may be provided.");
|
||||
return 7;
|
||||
}
|
||||
|
||||
var path = args[0];
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Console.WriteLine($"The provided path is not a valid directory: {path}.");
|
||||
return 7;
|
||||
}
|
||||
|
||||
var hasError = false;
|
||||
var errorBuilder = new StringBuilder();
|
||||
var fileList = Directory.GetFiles(path, "*.pdf");
|
||||
|
||||
foreach (var file in fileList)
|
||||
{
|
||||
try
|
||||
{
|
||||
var numWords = 0;
|
||||
var numPages = 0;
|
||||
using (var pdfDocument = PdfDocument.Open(file))
|
||||
{
|
||||
foreach (var page in pdfDocument.GetPages())
|
||||
{
|
||||
numPages++;
|
||||
foreach (var word in page.GetWords())
|
||||
{
|
||||
if (word != null)
|
||||
{
|
||||
numWords++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Read {numWords} words on {numPages} pages in document {file}.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
hasError = true;
|
||||
errorBuilder.AppendLine($"Parsing document {file} failed due to an error.")
|
||||
.Append(ex)
|
||||
.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
if (hasError)
|
||||
{
|
||||
Console.WriteLine(errorBuilder.ToString());
|
||||
return 5;
|
||||
}
|
||||
|
||||
Console.WriteLine("Complete! :)");
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
12
tools/ConsoleRunner/UglyToad.PdfPig.ConsoleRunner.csproj
Normal file
12
tools/ConsoleRunner/UglyToad.PdfPig.ConsoleRunner.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\UglyToad.PdfPig\UglyToad.PdfPig.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
31
tools/ConsoleRunner/UglyToad.PdfPig.ConsoleRunner.sln
Normal file
31
tools/ConsoleRunner/UglyToad.PdfPig.ConsoleRunner.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30907.101
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UglyToad.PdfPig.ConsoleRunner", "UglyToad.PdfPig.ConsoleRunner.csproj", "{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UglyToad.PdfPig", "..\..\src\UglyToad.PdfPig\UglyToad.PdfPig.csproj", "{4E37F4FA-4127-48C8-9151-235307C820E1}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0C3AEF4B-BEEA-44E5-89F6-12108AC3FE9F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4E37F4FA-4127-48C8-9151-235307C820E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4E37F4FA-4127-48C8-9151-235307C820E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4E37F4FA-4127-48C8-9151-235307C820E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4E37F4FA-4127-48C8-9151-235307C820E1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {500F0DF0-D180-446D-9981-BC320C17DC7A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
Loading…
Reference in New Issue
Block a user