Skip to content
Snippets Groups Projects
Commit 93b63dbb authored by Tim Coates's avatar Tim Coates
Browse files

Update Rename-PDFByContent.ps1

parent 9813822e
No related branches found
No related tags found
No related merge requests found
function Get-UIDFromPdf
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$Path
)
$Path = $PSCmdlet.GetUnresolvedProviderPathFromPSPath($Path)
$reader = New-Object iTextSharp.text.pdf.pdfreader -ArgumentList $Path
$lines = [iTextSharp.text.pdf.parser.PdfTextExtractor]::GetTextFromPage($reader, 1) -split "\r?\n"
$output = ($lines | Where-Object { $_ -like 'CC Student Id:*' }).Replace('CC Student Id:','').Trim()
$reader.Close()
return $output
}
Unblock-File -Path C:\Scripts\itextsharp\iTextSharp.dll
Add-Type -Path C:\Scripts\itextsharp\itextsharp.dll
$files = Get-ChildItem -Filter '*.pdf' -File
$files | ForEach-Object {
$uid = Get-UIDFromPdf -Path $_.FullName
if($uid.Length -eq 7){
$_ | Rename-Item -NewName "$uid.pdf"
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment