Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPdf
LOCAL loJson
LOCAL loJsonOut
LOCAL loReader
LOCAL loInfo
lnSuccess = 0
* 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
loPdf = CreateObject('Chilkat.Pdf')
* Removing the encryption needs owner rights: load with the owner password.
loPdf.OwnerPassword = "owner-secret"
lnSuccess = loPdf.LoadFile("qa_data/pdf/encrypted_user_password.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
CANCEL
ENDIF
loJson = CreateObject('Chilkat.JsonObject')
loJsonOut = CreateObject('Chilkat.JsonObject')
lnSuccess = loPdf.Protection("getInfo",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "encrypted, as loaded: " + STR(loJsonOut.BoolOf("loaded.encrypted"))
? "algorithm: " + loJsonOut.StringOf("loaded.algorithm")
lnSuccess = loPdf.Protection("removeEncryption",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "will be saved encrypted: " + STR(loJsonOut.BoolOf("pending.encrypted"))
lnSuccess = loPdf.WriteFile("qa_output/minutes_unprotected.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
* The result is an ordinary PDF that opens without a password.
loReader = CreateObject('Chilkat.Pdf')
loInfo = CreateObject('Chilkat.JsonObject')
lnSuccess = loReader.PreLoadCheck("qa_output/minutes_unprotected.pdf",loInfo)
IF (lnSuccess = 0) THEN
? loReader.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loReader
RELEASE loInfo
CANCEL
ENDIF
? "encrypted: " + STR(loInfo.BoolOf("encrypted"))
lnSuccess = loReader.LoadFile("qa_output/minutes_unprotected.pdf")
IF (lnSuccess = 0) THEN
? loReader.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loReader
RELEASE loInfo
CANCEL
ENDIF
? "pages: " + STR(loReader.NumPages)
* Sample output:
* encrypted, as loaded: True
* algorithm: rc4-128
* will be saved encrypted: False
* encrypted: False
* pages: 1
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loReader
RELEASE loInfo