Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
Change the Permissions of an Encrypted PDF
See more PDF Protection Examples
Demonstrates the changePermissions operation, which changes what an encrypted PDF permits and keeps its passwords, algorithm and scope. The JSON takes the same permissions member as the encrypt operation, and a permission that is not mentioned is granted. The operation needs owner rights. For an AES-256 PDF, load with both passwords, because the user password cannot be recovered from the owner password alone.Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loPdf
LOCAL loJson
LOCAL loJsonOut
LOCAL loReader
LOCAL loEmpty
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')
* Changing the permissions needs owner rights. Both passwords are given here, which is what
* an AES-256 PDF requires for this operation.
loPdf.UserPassword = "secret"
loPdf.OwnerPassword = "owner-secret"
lnSuccess = loPdf.LoadFile("qa_data/pdf/encrypted_user_password.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
CANCEL
ENDIF
* No printing and no copying. Everything not mentioned is granted.
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("permissions.print","none")
loJson.UpdateBool("permissions.copy",0)
loJsonOut = CreateObject('Chilkat.JsonObject')
lnSuccess = loPdf.Protection("changePermissions",loJson,loJsonOut)
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
? "print: " + loJsonOut.StringOf("pending.permissions.print")
? "copy: " + STR(loJsonOut.BoolOf("pending.permissions.copy"))
? "modify: " + STR(loJsonOut.BoolOf("pending.permissions.modify"))
? "password still needed to open: " + STR(loJsonOut.BoolOf("pending.userPasswordRequired"))
lnSuccess = loPdf.WriteFile("qa_output/minutes_no_print.pdf")
IF (lnSuccess = 0) THEN
? loPdf.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
CANCEL
ENDIF
* The same user password opens the result, now with the new permissions.
loReader = CreateObject('Chilkat.Pdf')
loReader.UserPassword = "secret"
lnSuccess = loReader.LoadFile("qa_output/minutes_no_print.pdf")
IF (lnSuccess = 0) THEN
? loReader.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loReader
CANCEL
ENDIF
loEmpty = CreateObject('Chilkat.JsonObject')
loInfo = CreateObject('Chilkat.JsonObject')
lnSuccess = loReader.Protection("getInfo",loEmpty,loInfo)
IF (lnSuccess = 0) THEN
? loReader.LastErrorText
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loReader
RELEASE loEmpty
RELEASE loInfo
CANCEL
ENDIF
? "saved file, print: " + loInfo.StringOf("loaded.permissions.print")
? "saved file, copy: " + STR(loInfo.BoolOf("loaded.permissions.copy"))
* Sample output:
* print: none
* copy: False
* modify: True
* password still needed to open: True
* saved file, print: none
* saved file, copy: False
RELEASE loPdf
RELEASE loJson
RELEASE loJsonOut
RELEASE loReader
RELEASE loEmpty
RELEASE loInfo