Lock PDF API

Add Passwords and Restrict Permissions on PDF Files Programmatically.

hero banner

Code Examples in Popular Languages

Integrate our Lock PDF API easily into your apps with comprehensive code examples in popular languages to get started quickly.

CURL Request
curl --location 'https://theonlineconverter.com/api/v1/lock-pdf' \
--header 'Content-Type: application/json' \
--header 'x-api-key: enter_your_api_key' \
--form 'file=@"/D:/data/Document/pdf/file.pdf"' \
--form 'password="123"'
JavaScript Fetch
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "enter_your_api_key");

const formdata = new FormData();
formdata.append("file", fileInput.files[0], "/D:/data/Document/pdf/file.pdf");
formdata.append("password", "123");

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: formdata,
  redirect: "follow"
};

fetch("https://theonlineconverter.com/api/v1/lock-pdf", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
Ruby Net::HTTP
import requests
import json

url = "https://theonlineconverter.com/api/v1/lock-pdf"

payload = {'password': '123'}
files=[
  ('file',('file.pdf',open('/D:/data/Document/pdf/file.pdf','rb'),'application/pdf'))
]
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'enter_your_api_key'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
Python Requests
import requests
import json

url = "https://theonlineconverter.com/api/v1/lock-pdf"

payload = {'password': '123'}
files=[
  ('file',('file.pdf',open('/D:/data/Document/pdf/file.pdf','rb'),'application/pdf'))
]
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'enter_your_api_key'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
PHP Guzzle
<?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/json',
  'x-api-key' => 'enter_your_api_key'
];
$options = [
  'multipart' => [
    [
      'name' => 'file',
      'contents' => Utils::tryFopen('/D:/data/Document/pdf/file.pdf', 'r'),
      'filename' => '/D:/data/Document/pdf/file.pdf',
      'headers'  => [
        'Content-Type' => '<Content-type header>'
      ]
    ],
    [
      'name' => 'password',
      'contents' => '123'
    ]
]];
$request = new Request('POST', 'https://theonlineconverter.com/api/v1/lock-pdf', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();
Java HttpURLConnection
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
  .addFormDataPart("file","/D:/data/Document/pdf/file.pdf",
    RequestBody.create(MediaType.parse("application/octet-stream"),
    new File("/D:/data/Document/pdf/file.pdf")))
  .addFormDataPart("password","123")
  .build();
Request request = new Request.Builder()
  .url("https://theonlineconverter.com/api/v1/lock-pdf")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("x-api-key", "enter_your_api_key")
  .build();
Response response = client.newCall(request).execute();
Go net/http
package main

import (
  "fmt"
  "bytes"
  "mime/multipart"
  "os"
  "path/filepath"
  "net/http"
  "io"
)

func main() {

  url := "https://theonlineconverter.com/api/v1/lock-pdf"
  method := "POST"

  payload := &bytes.Buffer{}
  writer := multipart.NewWriter(payload)
  file, errFile1 := os.Open("/D:/data/Document/pdf/file.pdf")
  defer file.Close()
  part1,
         errFile1 := writer.CreateFormFile("file",filepath.Base("/D:/data/Document/pdf/file.pdf"))
  _, errFile1 = io.Copy(part1, file)
  if errFile1 != nil {
    fmt.Println(errFile1)
    return
  }
  _ = writer.WriteField("password", "123")
  err := writer.Close()
  if err != nil {
    fmt.Println(err)
    return
  }


  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("x-api-key", "enter_your_api_key")

  req.Header.Set("Content-Type", writer.FormDataContentType())
  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := io.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
C# HttpClient
var options = new RestClientOptions("https://theonlineconverter.com")
{
  MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("/api/v1/lock-pdf", Method.Post);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("x-api-key", "enter_your_api_key");
request.AlwaysMultipartFormData = true;
request.AddFile("file", "/D:/data/Document/pdf/file.pdf");
request.AddParameter("password", "123");
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);

Key Features & Capabilities

Our API is engineered with robust security features to give you full control over your PDF documents.

Simple User Interface

Strong AES-256 Encryption

Secure your documents with industry-standard 256-bit AES encryption, providing a powerful defense against unauthorized access.

Simple Data Format

User Password Protection

Set a primary "user password" that is required for anyone to open and view the contents of the PDF file.

Time

Granular Permission Controls

Set a separate "owner password" to restrict specific actions like printing, copying text and images, filling forms, and editing the document.

Secure Data

Automated Security Workflows

Easily integrate the API into your existing workflows to automatically secure documents like invoices, reports, or legal contracts as they are generated.

Universal Access

Fast & Scalable Performance

Our API is optimized for speed, allowing you to lock individual files or large batches of documents quickly and reliably.

Freedom

Secure & Confidential

All files are processed over encrypted connections. We guarantee confidentiality with a strict data privacy policy and do not store your files or passwords.

Frequently Asked Questions

Find answers to common questions about our Lock PDF API to understand how to best secure your documents.

A "user password" (or open password) is what a recipient needs to simply open and view the file. An "owner password" allows the holder to bypass any restrictions and change the security settings. You can set restrictions (like disabling printing) that apply to anyone who only has the user password.

We use 256-bit AES (Advanced Encryption Standard), which is a globally recognized and highly secure encryption algorithm used to protect sensitive data.

Due to the strength of the encryption, a forgotten password cannot be recovered by us or anyone else. The file will remain permanently inaccessible. Please store your passwords securely.

Yes, you can use our "Unlock PDF API" to remove password protection, but you must provide the correct current password to do so.

You can prevent or allow actions such as printing the document, copying text and images, modifying the content, and adding or modifying annotations and form fields.

Absolutely. All communication with our API, including the file data and passwords, is secured with end-to-end TLS encryption. We do not log or store the passwords you use.

Our API is designed to handle large PDF files. Specific size limits are based on your subscription plan and can be found in our documentation.