Created
June 10, 2024 11:34
-
-
Save bjoerntx/e08cc7bb1c53a3418f2aa6243f201fc5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Drawing; | |
using System.Text.RegularExpressions; | |
using TXTextControl.DocumentServer.PDF.Contents; | |
Lines pdfLines = new Lines("invoice.pdf"); | |
List<ContentLine> contentLines = | |
pdfLines.Find(new RectangleF(462, 376, 400, 400), true); | |
foreach (ContentLine line in contentLines) | |
{ | |
float fTotal = ExtractFloatFromString(line.Text); | |
Console.WriteLine("Found value on page {0} (X: {1}, Y: {2}): {3}", | |
line.Page.ToString(), | |
line.X.ToString(), | |
line.Y.ToString(), | |
fTotal.ToString()); | |
} | |
static float ExtractFloatFromString(string input) | |
{ | |
// Regular expression to match a floating-point number | |
string pattern = @"[-+]?[0-9]*\.?[0-9]+"; | |
// Match the pattern in the input string | |
Match match = Regex.Match(input, pattern); | |
if (match.Success) | |
{ | |
// Convert the matched value to float | |
return float.Parse(match.Value); | |
} | |
// If no match found, return 0.0 or you can throw an exception or handle it as needed | |
return 0.0f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment