Xojo Plugin Requires Chilkat v11.7.0+
Xojo Plugin
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 Xojo Plugin Downloads
Dim success As Boolean
success = 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
Dim pdf As New Chilkat.Pdf
// Removing the encryption needs owner rights: load with the owner password.
pdf.OwnerPassword = "owner-secret"
success = pdf.LoadFile("qa_data/pdf/encrypted_user_password.pdf")
If (success = False) Then
System.DebugLog(pdf.LastErrorText)
Return
End If
Dim json As New Chilkat.JsonObject
Dim jsonOut As New Chilkat.JsonObject
success = pdf.Protection("getInfo",json,jsonOut)
If (success = False) Then
System.DebugLog(pdf.LastErrorText)
Return
End If
System.DebugLog("encrypted, as loaded: " + Str(jsonOut.BoolOf("loaded.encrypted")))
System.DebugLog("algorithm: " + jsonOut.StringOf("loaded.algorithm"))
success = pdf.Protection("removeEncryption",json,jsonOut)
If (success = False) Then
System.DebugLog(pdf.LastErrorText)
Return
End If
System.DebugLog("will be saved encrypted: " + Str(jsonOut.BoolOf("pending.encrypted")))
success = pdf.WriteFile("qa_output/minutes_unprotected.pdf")
If (success = False) Then
System.DebugLog(pdf.LastErrorText)
Return
End If
// The result is an ordinary PDF that opens without a password.
Dim reader As New Chilkat.Pdf
Dim info As New Chilkat.JsonObject
success = reader.PreLoadCheck("qa_output/minutes_unprotected.pdf",info)
If (success = False) Then
System.DebugLog(reader.LastErrorText)
Return
End If
System.DebugLog("encrypted: " + Str(info.BoolOf("encrypted")))
success = reader.LoadFile("qa_output/minutes_unprotected.pdf")
If (success = False) Then
System.DebugLog(reader.LastErrorText)
Return
End If
System.DebugLog("pages: " + Str(reader.NumPages))
// Sample output:
// encrypted, as loaded: True
// algorithm: rc4-128
// will be saved encrypted: False
// encrypted: False
// pages: 1