Classic ASP Requires Chilkat v11.7.0+
Classic ASP
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 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 pdf = Server.CreateObject("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 = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
set json = Server.CreateObject("Chilkat.JsonObject")
set jsonOut = Server.CreateObject("Chilkat.JsonObject")
success = pdf.Protection("getInfo",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "encrypted, as loaded: " & jsonOut.BoolOf("loaded.encrypted")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "algorithm: " & jsonOut.StringOf("loaded.algorithm")) & "</pre>"
success = pdf.Protection("removeEncryption",json,jsonOut)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "will be saved encrypted: " & jsonOut.BoolOf("pending.encrypted")) & "</pre>"
success = pdf.WriteFile("qa_output/minutes_unprotected.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
Response.End
End If
' The result is an ordinary PDF that opens without a password.
set reader = Server.CreateObject("Chilkat.Pdf")
set info = Server.CreateObject("Chilkat.JsonObject")
success = reader.PreLoadCheck("qa_output/minutes_unprotected.pdf",info)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( reader.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "encrypted: " & info.BoolOf("encrypted")) & "</pre>"
success = reader.LoadFile("qa_output/minutes_unprotected.pdf")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( reader.LastErrorText) & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "pages: " & reader.NumPages) & "</pre>"
' Sample output:
' encrypted, as loaded: True
' algorithm: rc4-128
' will be saved encrypted: False
' encrypted: False
' pages: 1
%>
</body>
</html>