Encrypt and protect PDF

If you find any problem with API, please make an issue at GitHub


4.1 How to encrypt a PDF document and set permissions using API Rest


URL

To encrypt a PDF using our API Rest is necessary to perform a POST call to the following URL (ENDPOINT):

https://getoutpdf.com/api/tool/encrypt-pdf


GET Parameters

Our Rest API does not have operations via GET parameters


POST Parameters

  • api_keyApi key generated for your license. You can see your api key
    (string, required)
  • pdf_inSource PDF encoded in base64
    (string, required)
  • user_passwordUser password to encrypt the PDF
    (string, required)
  • owner_passwordOwner password to encrypt the PDF. This parameter will only take effect if the parameter "user_password" is present
    (string, required)
  • assembleCan assemble document
    (boolean, optional, default: true)
  • copyCan extract content
    (boolean, optional, default: true)
  • copy_accessibilityCan extract content for accessibility
    (boolean, optional, default: true)
  • fillCan fill in forms
    (boolean, optional, default: true)
  • modifyCan modify document
    (boolean, optional, default: true)
  • modify_annotationsCan modify annotations in documents
    (boolean, optional, default: true)
  • printCan print document
    (boolean, optional, default: true)
  • print_degradedCan print degraded document
    (boolean, optional, default: true)

You can make a POST call using the HTML Header application/x-www-form-urlencoded, with the parameters described above.

Or you can send parameters via the JSON format, using the HTML Header application/json:

{
    "api_key" : "...",                  // string, required
    "pdf_in" : "...",                   // string, required
    "user_password" : "...",            // string, required
    "owner_password" : "...",           // string, required
    "assemble": "...",                  // boolean, optional, default: true
    "copy": "...",                      // boolean, optional, default: true
    "copy_accessibility": "...",        // boolean, optional, default: true
    "fill": "...",                      // boolean, optional, default: true
    "modify": "...",                    // boolean, optional, default: true
    "modify_annotations": "...",        // boolean, optional, default: true
    "print": "...",                     // boolean, optional, default: true
    "print_degraded": "...",            // boolean, optional, default: true
}

Example

{
    "api_key" : "64b5d1054b69e676b9984d8406c5209a6ba78...",
    "pdf_in" : "JVBERi0xLjQNJeLjz9MNCjYgMCBvYmo8PC9I...",
    "user_password" : "userpassword",
    "owner_password" : "ownerpassword",
    "assemble": true,
    "copy": false,
    "copy_accessibility": true,
    "fill": true,
    "modify": true,
    "modify_annotations": true,
    "print": false,
    "print_degraded": true
}

Response

If the operation is successful the response is a JSON with the following structure:

{
    "api_key": "...",       // string - Api key used for your license
    "pdf_base64": "...",    // string - PDF file encoded in base64
    "tokens_used": "...",   // integer - Tokens used in operation
    "tokens_left": "..."    // integer - Tokens left
}

Errors

If an error in sending parameters occurs, the response is a JSON with the following structure:

{
    "errors": {
        "param1": [     // string - Parameter name that generated the error
            "message"   // string - Error description
        ],
        "param2": [
            "message"
        ],
        ...
        "paramN": [
            "message"
        ]
    }
}

If a operation error occurs, the answer will be a JSON with the following structure:

{
    "errors": [
        "message1",
        "message2",
        ...
        "messageN"
    ]
}