tags:

views:

41

answers:

1

Hi guys. Using powershell I need to loop a series of pdf file and make some operation on them using pdftk. I'd like to know if exists some method to detect if pdf is encrypted or not. In this way, if the pdf is encrypted I don't work on it and my loop skips to the next file. Thanks for the attention.

edit. While I wait for some answer I've found that itextsharp has an isencrypted method.

After I load the assembly

[System.Reflection.Assembly]::LoadFrom("c:\my_path\itextsharp.dll")

what do I have to do to use the above method?

+1  A: 
[System.Reflection.Assembly]::LoadFrom("c:\itext\itextsharp.dll")

$itext = new-object itextsharp.text.pdf.PdfReader("c:\itext\1.pdf")

$itext.isEncrypted()

You should get either true or false as a result.

blizpasta
Hi blizpasta and thanks for your reply. I've tried your code. Both dll then file paths are right but when I run the code I receive an error. POWERSHELL EXCEPTION EXCEPTION TYPE:System.Management.Automation.CmdletInvocationExceptionMESSAGE:Impossibile trovare il tipo [itextpdf.text.pdf.PdfReader]. Verificare che l'assembly contenente questo tipo sia caricato.POSITION:In riga:2 car:20+ $itext = new-object <<<< itextpdf.text.pdf.PdfReader("c:\myfile.pdf")
nick rulez
I made a mistake and typed "itextpdf.text..." on the second line instead of "itextsharp.text...". I've corrected it.
blizpasta
Thank you very much. Everything works fine now. Thanks again for your kindness. Have a nice sunday.
nick rulez
In PowerShell v2.0 you can load the assembly with `Add-Type` which is a nicer way to do it.
Jay Bazuzi