AutoIt Requires Chilkat v11.7.0+
AutoIt
Remove the Password and Encryption from a PDF
See more PDF Protection Examples
Demonstrates the removeEncryption operation, which saves the PDF with no encryption at all: no password, no restrictions. It needs owner rights, so the PDF is loaded with its owner password. As with every Protection operation, the change is applied when the file is written.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
; The PDF used in this example is available at encrypted_user_password.pdf
$oPdf = ObjCreate("Chilkat.Pdf")
; Removing the encryption needs owner rights: load with the owner password.
$oPdf.OwnerPassword = "owner-secret"
$bSuccess = $oPdf.LoadFile("qa_data/pdf/encrypted_user_password.pdf")
If ($bSuccess = False) Then
ConsoleWrite($oPdf.LastErrorText & @CRLF)
Exit
EndIf
$oJson = ObjCreate("Chilkat.JsonObject")
$oJsonOut = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oPdf.Protection("getInfo",$oJson,$oJsonOut)
If ($bSuccess = False) Then
ConsoleWrite($oPdf.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("encrypted, as loaded: " & $oJsonOut.BoolOf("loaded.encrypted") & @CRLF)
ConsoleWrite("algorithm: " & $oJsonOut.StringOf("loaded.algorithm") & @CRLF)
$bSuccess = $oPdf.Protection("removeEncryption",$oJson,$oJsonOut)
If ($bSuccess = False) Then
ConsoleWrite($oPdf.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("will be saved encrypted: " & $oJsonOut.BoolOf("pending.encrypted") & @CRLF)
$bSuccess = $oPdf.WriteFile("qa_output/minutes_unprotected.pdf")
If ($bSuccess = False) Then
ConsoleWrite($oPdf.LastErrorText & @CRLF)
Exit
EndIf
; The result is an ordinary PDF that opens without a password.
$oReader = ObjCreate("Chilkat.Pdf")
$oInfo = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oReader.PreLoadCheck("qa_output/minutes_unprotected.pdf",$oInfo)
If ($bSuccess = False) Then
ConsoleWrite($oReader.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("encrypted: " & $oInfo.BoolOf("encrypted") & @CRLF)
$bSuccess = $oReader.LoadFile("qa_output/minutes_unprotected.pdf")
If ($bSuccess = False) Then
ConsoleWrite($oReader.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("pages: " & $oReader.NumPages & @CRLF)
; Sample output:
; encrypted, as loaded: True
; algorithm: rc4-128
; will be saved encrypted: False
; encrypted: False
; pages: 1