Skip to content

Commit

Permalink
Added line number and value to output of Search-PDFDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Nigel Tatschner authored and Nigel Tatschner committed Sep 21, 2023
1 parent 949b13e commit fbf08d1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
58 changes: 34 additions & 24 deletions Modules/Tatux.Utils/Public/Search-PDFDoc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ function Search-PDFDoc {
}
#Load File
$Props = [ordered]@{
Name = (Split-Path -Path $Path -Leaf)
Type = (Split-Path -Path $Path -Leaf).Split('.')[-1]
Query = 'N/A'
Page = 'N/A'
Path = $Path
Match = 'N/A'
Result = ""
Name = (Split-Path -Path $Path -Leaf)
Type = (Split-Path -Path $Path -Leaf).Split('.')[-1]
Query = 'N/A'
Page = 'N/A'
Line = 'N/A'
LineText = 'N/A'
Path = $Path
Match = 'N/A'
Result = ""
}
try {
$PDFReader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList $Path -ErrorAction Stop
Expand All @@ -75,7 +77,8 @@ function Search-PDFDoc {
}
catch {
$Obj = New-Object PSObject -Property $Props
$Obj.Result = "Failure-Document"
$Obj.Query = $Query
$Obj.Result = "Failure-Document: $($_.Exception.Message)"
}
}
PROCESS {
Expand All @@ -88,29 +91,36 @@ function Search-PDFDoc {
}
Catch {
$Obj = New-Object PSObject -Property $Props
$Obj.Result = "Failure-Search"
$Obj.Result = "Failure-Search: $($_.Exception.Message)"
$Obj.Query = $Q
$Obj.Page = $Page
$Obj
break
}
$Obj = New-Object PSObject -Property $Props
$Obj.Query = $Q
$Obj.Page = $Page
if ($PageText -match $Q) {
$Obj.Match = $true
$Obj.Result = "Success"
$Obj
break
}
else {
$Obj.Match = $false
if ($OnlyMatches -eq $false) {
$LineCount = 1
foreach ($line in $PageText) {
$Obj = New-Object PSObject -Property $Props
$Obj.Query = $Q
$Obj.Page = $Page
$Obj.Line = $LineCount
$LineCount++
if ($line -match $Q) {
$Obj.LineText = $line
$Obj.Match = $true
$Obj.Result = "Success"
$Obj
break
}
else {
$Obj.Match = $false
if ($OnlyMatches -eq $false) {
$Obj.Result = "Success"
$Obj
}
}
if ($Obj.Result) {
continue
}
}
if ($Obj.Result) {
continue
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Tatux.Utils/Tatux.Utils.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#RootModule = 'Tatux.Utils'

# Version number of this module.
ModuleVersion = '0.2.26'
ModuleVersion = '0.2.27'

# ID used to uniquely identify this module
GUID = '061256e7-9e17-4571-9481-baca2e0bc13e'
Expand Down Expand Up @@ -51,7 +51,7 @@ PrivateData = @{

PSData = @{
# ReleaseNotes of this module
ReleaseNotes = 'Fixed Search-PDFDoc function'
ReleaseNotes = 'Added line reference and return value to output of Search-PDFDoc'
} # End of PSData hashtable

} # End of PrivateData hashtable
Expand Down

0 comments on commit fbf08d1

Please sign in to comment.