Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
Rename-PDFByContent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
Rename-PDFByContent
Commits
4d96ffa1
Commit
4d96ffa1
authored
May 15, 2019
by
Tim Coates
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generalise file, include local libraries
parent
21135839
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
Rename-PDFByContent.ps1
Rename-PDFByContent.ps1
+13
-7
No files found.
Rename-PDFByContent.ps1
View file @
4d96ffa1
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"
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment