diff --git a/Modules/Tatux.Utils/Public/Search-PDFDoc.ps1 b/Modules/Tatux.Utils/Public/Search-PDFDoc.ps1 index db49f13..7ad2e2b 100644 --- a/Modules/Tatux.Utils/Public/Search-PDFDoc.ps1 +++ b/Modules/Tatux.Utils/Public/Search-PDFDoc.ps1 @@ -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 @@ -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 { @@ -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 } } } diff --git a/Modules/Tatux.Utils/Tatux.Utils.psd1 b/Modules/Tatux.Utils/Tatux.Utils.psd1 index a6f1cea..f1fa92d 100644 --- a/Modules/Tatux.Utils/Tatux.Utils.psd1 +++ b/Modules/Tatux.Utils/Tatux.Utils.psd1 @@ -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' @@ -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