Sample code for 30+ languages & platforms
Classic ASP Requires Chilkat v11.7.0+

Remove the Restrictions from a PDF

See more PDF Protection Examples

Demonstrates the removeRestrictions operation, which grants every permission. A PDF that needs a password to open stays encrypted and keeps that password. A PDF with no user password, like the one here, has nothing left to protect and is saved unencrypted, the same as removeEncryption. The operation needs owner rights, so the PDF is loaded with its owner password.

Chilkat Classic ASP Downloads

Classic ASP
<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 no_copy_permission.pdf

set pdf = Server.CreateObject("Chilkat.Pdf")

'  This PDF opens without a password, but copying text from it is not permitted.
'  Removing the restrictions needs owner rights: load with the owner password.
pdf.OwnerPassword = "owner-secret"
success = pdf.LoadFile("qa_data/pdf/no_copy_permission.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( "may copy, before: " & jsonOut.BoolOf("loaded.permissions.copy")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "password needed to open: " & jsonOut.BoolOf("loaded.userPasswordRequired")) & "</pre>"

success = pdf.Protection("removeRestrictions",json,jsonOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

'  With no user password and nothing restricted there is nothing left to protect, so the PDF
'  will be saved unencrypted.  A PDF that needs a password to open would stay encrypted and
'  keep its password.
Response.Write "<pre>" & Server.HTMLEncode( "will be saved encrypted: " & jsonOut.BoolOf("pending.encrypted")) & "</pre>"

success = pdf.WriteFile("qa_output/leaflet_unrestricted.pdf")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( pdf.LastErrorText) & "</pre>"
    Response.End
End If

'  Anyone can now extract the text.
set reader = Server.CreateObject("Chilkat.Pdf")
success = reader.LoadFile("qa_output/leaflet_unrestricted.pdf")
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( reader.LastErrorText) & "</pre>"
    Response.End
End If

set opts = Server.CreateObject("Chilkat.JsonObject")
set extractOut = Server.CreateObject("Chilkat.JsonObject")
set sb = Server.CreateObject("Chilkat.StringBuilder")
success = reader.ExtractTextSb("text",opts,sb,extractOut)
If (success = 0) Then
    Response.Write "<pre>" & Server.HTMLEncode( reader.LastErrorText) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "characters extracted: " & sb.Length) & "</pre>"

'  Sample output:

'  may copy, before: False
'  password needed to open: False
'  will be saved encrypted: False
'  characters extracted: 216

%>
</body>
</html>