Reputation: 19
In a windows directory I have about 100 pdf-files, some are password protected, some are not. Is there an easy way (in the command-line or maybe with a freeware tool) to find the ones which are password protected without opening each of them in a pdf-reader?
Upvotes: 0
Views: 3025
Reputation: 1237
Since you are on Windows, you can use the iTextSharp library to accomplish this.
First, extract itextsharp.dll, which is inside the itextsharp-dll-core archive.
Then, use the following PowerShell script:
Add-Type -Path .\itextsharp.dll
Get-ChildItem -Filter *.pdf |
ForEach-Object {
$filename = $_.Name
Try {
$pdf = New-Object iTextSharp.text.pdf.PdfReader($_.FullName)
If ($pdf.IsEncrypted()) {
$filename
}
}
Catch {
$filename
}
}
The output will be the name of each PDF which is secured or encrypted.
Upvotes: 1
Reputation: 1202
You could use the script of is it possible to check if pdf is password protected using ghostscript? and extend it to iterate over a bunch of files and eg. move all non-password protected files into a subdirectory.
Upvotes: 0