Classic ASP Requires Chilkat v11.7.0+
Classic ASP
PDF Owner Password vs. User Password
See more PDF Protection Examples
Demonstrates the difference between the two passwords of an encrypted PDF. Either one opens the file. The user password gives the rights the permissions grant. The owner password gives owner rights: no restriction applies, and it is the only one that lets the security be changed or removed. Every Protection operation except getInfo needs owner rights, and Chilkat does not offer a way around that.Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 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
set json = Server.CreateObject("Chilkat.JsonObject")
set jsonOut = Server.CreateObject("Chilkat.JsonObject")
' Opened with the user password.
set user = Server.CreateObject("Chilkat.Pdf")
user.UserPassword = "secret"
success = user.LoadFile("qa_data/pdf/encrypted_user_password.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( user.LastErrorText) & "</pre>"
Response.End
End If
success = user.Protection("getInfo",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( user.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "opened with: " & jsonOut.StringOf("loaded.openedWith")) & "</pre>"
' Changing the security needs owner rights, so this is refused.
success = user.Protection("removeEncryption",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "removeEncryption was refused: the PDF was not opened with its owner password.") & "</pre>"
End If
' Opened with the owner password.
set owner = Server.CreateObject("Chilkat.Pdf")
owner.OwnerPassword = "owner-secret"
success = owner.LoadFile("qa_data/pdf/encrypted_user_password.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( owner.LastErrorText) & "</pre>"
Response.End
End If
success = owner.Protection("getInfo",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( owner.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "opened with: " & jsonOut.StringOf("loaded.openedWith")) & "</pre>"
' Now it is allowed.
success = owner.Protection("removeEncryption",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( owner.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "removeEncryption succeeded; will be saved encrypted: " & jsonOut.BoolOf("pending.encrypted")) & "</pre>"
' Sample output:
' opened with: user
' removeEncryption was refused: the PDF was not opened with its owner password.
' opened with: owner
' removeEncryption succeeded; will be saved encrypted: False
%>
</body>
</html>