Commit 4d96ffa1 authored by Tim Coates's avatar Tim Coates

Generalise file, include local libraries

parent 21135839
Unblock-File -Path .\lib\iTextSharp.dll
Add-Type -Path .\lib\itextsharp.dll
function Get-UIDFromPdf
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$Path
$Path,
[Parameter(Mandatory = $true)]
[string]
$SearchString
)
$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"
$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()
$output = ($lines | Where-Object { $_ -like ('*' + $SearchString + '*') }).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
$uid = Get-UIDFromPdf -Path $_.FullName -SearchString 'Student Id:'
$newname = $uid.Replace('Student Id:','').Trim()
if($uid.Length -eq 7){
$_ | Rename-Item -NewName "$uid.pdf"
$_ | Rename-Item -NewName "$newname.pdf"
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment