> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pdf.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Make Text Unsearchable

> This method converts PDF files into a "text unsearchable" version by converting your PDF into a "scanned" PDF file which is effectively a flat image.

## `POST /v1/pdf/makeunsearchable`

## Attributes

<Note>Attributes are case-sensitive and should be inside JSON for POST request. for example: `{ "url": "https://example.com/file1.pdf" }`</Note>

| Attribute                          | Type                          | Required | Default   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ---------------------------------- | ----------------------------- | -------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`                              | string                        | *Yes*    | -         | URL to the source file [`url` attribute](/api-reference/url-input-and-request-limits#supported-file-sources)                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `callback`                         | string                        | *No*     | -         | The callback URL (or Webhook) used to receive the POST data. see [Webhooks & Callbacks](/api-reference/webhooks). This is only applicable when `async` is set to `true`.                                                                                                                                                                                                                                                                                                                                                                                                           |
| `httpusername`                     | string                        | *No*     | -         | HTTP auth user name if required to access source URL.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `httppassword`                     | string                        | *No*     | -         | HTTP auth password if required to access source URL.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `pages`                            | string                        | *No*     | all pages | Specify page indices as comma-separated values or ranges to process (e.g. "0, 1, 2-" or "1, 2, 3-7"). The first-page index is 0. Use "!" before a number for inverted page numbers (e.g. "!0" for the last page). If not specified, the default configuration processes all pages. The input must be in string format.                                                                                                                                                                                                                                                             |
| `password`                         | string                        | *No*     | -         | Password for the PDF file.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `async`                            | boolean                       | *No*     | `false`   | Set `async` to `true` for long processes to run in the background, API will then return a `jobId` which you can use with the [Background Job Check endpoint](/api-reference/job-check). Also see [Webhooks & Callbacks](/api-reference/webhooks)                                                                                                                                                                                                                                                                                                                                   |
| `name`                             | string                        | *No*     | -         | File name for the generated output, the input must be in string format.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `expiration`                       | integer                       | *No*     | `60`      | Set the expiration time for the output link in minutes. After this specified duration, any generated output file(s) will be automatically deleted from [PDF.co Temporary Files Storage](/api-reference/file-upload/overview). The maximum duration for link expiration varies based on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf templates, documents) consider using [PDF.co Built-In Files Storage](https://app.pdf.co/tools/files).                                                                                            |
| `profiles`                         | object                        | *No*     | -         | See [Profiles](/api-reference/profiles) for more information.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
|     `outputDataFormat`             | string                        | *No*     | -         | If you require your output as `base64` format, set this to `base64`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
|     `OCRMode`                      | string                        | *No*     | Auto      | Specifies how OCR (Optical Character Recognition) should process input content, offering various modes to tailor text extraction based on content type such as images, fonts, and vector graphics. For more information, see [OCR Extraction Modes](/api-reference/profiles#ocr-extraction-modes).                                                                                                                                                                                                                                                                                 |
|     `OCRResolution`                | integer                       | *No*     | 300       | Use this parameter to change the OCR resolution from the default 300 dpi. The range is from `72` to `1200` dpi.                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
|     `RotationAngle`                | integer                       | *No*     | -         | Use manual rotation to handle PDFs with vertically drawn text. Normally, OCR automatically detects page rotation in PDFs and extracts text accurately. However, in some cases, the PDF might not have an actual rotated page  ---  Rather, the text itself is drawn vertically. In such scenarios, auto-detection may fail. You can use this parameter to manually set the page rotation. The available angles are: `0`, `1`, `2`, `3`.                                                                                                                                            |
|     `LineGroupingMode`             | string                        | *No*     | None      | Controls line grouping in PDF text extraction. Modes: `None` (no grouping), `GroupByRows` (merge rows if all cells align), `GroupByColumns` (merge cells by column), `JoinOrphanedRows` (merge single-cell rows to above if no separator).                                                                                                                                                                                                                                                                                                                                         |
|     `ConsiderFontColors`           | boolean                       | *No*     | `false`   | Controls whether font colors should be considered when detecting table structure and merging text objects during PDF extraction. Set to true to consider font colors.                                                                                                                                                                                                                                                                                                                                                                                                              |
|     `DetectNewColumnBySpacesRatio` | string                        | *No*     | 1.2       | Controls how spaces between words are interpreted for column detection in PDF text extraction. It defines the ratio of space width that determines when text should be treated as being in separate columns.                                                                                                                                                                                                                                                                                                                                                                       |
|     `AutoAlignColumnsToHeader`     | boolean                       | *No*     | `true`    | Controls how columns are detected and aligned during table extraction from PDF documents. It affects both table structure detection and text extraction with formatting preservation. Set to true to automatically align columns to the header row. When set to true (default), the row with the most columns is used as the header, and all other rows are aligned to this structure --- ideal for well-structured tables. When set to false, columns are analyzed independently across all rows to build the structure, which works better for inconsistent or irregular tables. |
|     `OCRImagePreprocessingFilters` | object                        | *No*     | -         | Image preprocessing filters for OCR. Refer to [OCRImagePreprocessingFilters](#ocrimagepreprocessingfilters) for usage examples.                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
|         `.AddGrayscale`            | boolean                       | *No*     | `false`   | Converts to grayscale before OCR.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
|         `.AddGammaCorrection`      | array\[string (float format)] | *No*     | \["1.4"]  | Adds a gamma correction filter.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
|     `DataEncryptionAlgorithm`      | string                        | *No*     | -         | Controls the encryption algorithm used for data encryption. See [User-Controlled Encryption](/knowledgebase/user-controlled-encryption) for more information. The available algorithms are: `AES128`, `AES192`, `AES256`.                                                                                                                                                                                                                                                                                                                                                          |
|     `DataEncryptionKey`            | string                        | *No*     | -         | Controls the encryption key used for data encryption. See [User-Controlled Encryption](/knowledgebase/user-controlled-encryption) for more information.                                                                                                                                                                                                                                                                                                                                                                                                                            |
|     `DataEncryptionIV`             | string                        | *No*     | -         | Controls the encryption IV used for data encryption. See [User-Controlled Encryption](/knowledgebase/user-controlled-encryption) for more information.                                                                                                                                                                                                                                                                                                                                                                                                                             |
|     `DataDecryptionAlgorithm`      | string                        | *No*     | -         | Controls the decryption algorithm used for data decryption. See [User-Controlled Encryption](/knowledgebase/user-controlled-encryption) for more information. The available algorithms are: `AES128`, `AES192`, `AES256`.                                                                                                                                                                                                                                                                                                                                                          |
|     `DataDecryptionKey`            | string                        | *No*     | -         | Controls the decryption key used for data decryption. See [User-Controlled Encryption](/knowledgebase/user-controlled-encryption) for more information.                                                                                                                                                                                                                                                                                                                                                                                                                            |
|     `DataDecryptionIV`             | string                        | *No*     | -         | Controls the decryption IV used for data decryption. See [User-Controlled Encryption](/knowledgebase/user-controlled-encryption) for more information.                                                                                                                                                                                                                                                                                                                                                                                                                             |

## Query parameters

*No query parameters accepted.*

## Responses

| Parameter             | Type    | Description                                                                                                                  |
| --------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `url`                 | string  | Direct URL to the final PDF file stored in S3.                                                                               |
| `outputLinkValidTill` | string  | Timestamp indicating when the output link will expire                                                                        |
| `pageCount`           | integer | Number of pages in the PDF document.                                                                                         |
| `error`               | boolean | Indicates whether an error occurred (`false` means success)                                                                  |
| `status`              | string  | Status code of the request (200, 404, 500, etc.). For more information, see [Response Codes](/api-reference/response-codes). |
| `name`                | string  | Name of the output file                                                                                                      |
| `credits`             | integer | Number of credits consumed by the request                                                                                    |
| `remainingCredits`    | integer | Number of credits remaining in the account                                                                                   |
| `duration`            | integer | Time taken for the operation in milliseconds                                                                                 |

## `Example` Payload

<Note>To see the request size limits, please refer to the [Request Size Limits](/api-reference/url-input-and-request-limits#pdf-co-request-size).</Note>

```json theme={null}
{
  "url": "pdfco-test-files.s3.us-west-2.amazonaws.compdf-to-text/sample.pdf",
  "pages": "",
  "name": "result.pdf",
  "password": "",
  "async": "false",
  "profiles": ""
}
```

## `Example` Response

<Note>To see the main response codes, please refer to the [Response Codes](/api-reference/response-codes) page.</Note>

```json theme={null}
{
  "url": "https://pdf-temp-files.s3.amazonaws.com/6b755238963a472abf67fd5e7ffafd79/result.pdf",
  "pageCount": 1,
  "error": false,
  "status": 200,
  "name": "result.pdf",
  "remainingCredits": 327244,
  "credits": 35
}
```

<Note>
  **Inconsistent URL Encoding in cURL Output:** When using cURL to make API requests, the output JSON may show URL characters encoded as Unicode escape sequences. For example, the ampersand character (`&`) may appear as `\u0026` in the cURL output. This is normal JSON encoding behavior and does not affect the validity of the URL. The URL will function correctly when used, as JSON parsers automatically decode these escape sequences. If you're parsing the response programmatically, your JSON parser will handle this conversion automatically.
</Note>

## Code Samples

<Tabs>
  <Tab title="CURL">
    ```bash theme={null}
    curl --location --request POST 'https://api.pdf.co/v1/pdf/makeunsearchable' \
    --header 'x-api-key: *******************' \
    --header 'Content-Type: application/json' \
    --data-raw '{
    "url": "pdfco-test-files.s3.us-west-2.amazonaws.compdf-to-text/sample.pdf",
    "pages": "",
    "name": "result.pdf",
    "password": "",
    "async": "false",
    "profiles": ""
    }'
    ```
  </Tab>

  <Tab title="JavaScript/Node.js">
    ```javascript theme={null}
    var https = require("https");
    var path = require("path");
    var fs = require("fs");

    // `request` module is required for file upload.
    // Use "npm install request" command to install.
    var request = require("request");

    // The authentication key (API Key).
    // Get your own by registering at https://app.pdf.co
    const API_KEY = "***********************************";


    // Source PDF file
    const SourceFile = "./sample.pdf";
    // Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
    const Pages = "";
    // PDF document password. Leave empty for unprotected documents.
    const Password = "";
    // Destination PDF file name
    const DestinationFile = "./result.pdf";


    // 1. RETRIEVE PRESIGNED URL TO UPLOAD FILE.
    getPresignedUrl(API_KEY, SourceFile)
        .then(([uploadUrl, uploadedFileUrl]) => {
            // 2. UPLOAD THE FILE TO CLOUD.
            uploadFile(API_KEY, SourceFile, uploadUrl)
                .then(() => {
                    // 3. MAKE UPLOADED PDF FILE UNSEARCHABLE
                    makePdfUnSearchable(API_KEY, uploadedFileUrl, Password, Pages, DestinationFile);
                })
                .catch(e => {
                    console.log(e);
                });
        })
        .catch(e => {
            console.log(e);
        });


    function getPresignedUrl(apiKey, localFile) {
        return new Promise(resolve => {
            // Prepare request to `Get Presigned URL` API endpoint
            let queryPath = `/v1/file/upload/get-presigned-url?contenttype=application/octet-stream&name=${path.basename(SourceFile)}`;
            let reqOptions = {
                host: "api.pdf.co",
                path: encodeURI(queryPath),
                headers: { "x-api-key": API_KEY }
            };
            // Send request
            https.get(reqOptions, (response) => {
                response.on("data", (d) => {
                    let data = JSON.parse(d);
                    if (data.error == false) {
                        // Return presigned url we received
                        resolve([data.presignedUrl, data.url]);
                    }
                    else {
                        // Service reported error
                        console.log("getPresignedUrl(): " + data.message);
                    }
                });
            })
                .on("error", (e) => {
                    // Request error
                    console.log("getPresignedUrl(): " + e);
                });
        });
    }

    function uploadFile(apiKey, localFile, uploadUrl) {
        return new Promise(resolve => {
            fs.readFile(SourceFile, (err, data) => {
                request({
                    method: "PUT",
                    url: uploadUrl,
                    body: data,
                    headers: {
                        "Content-Type": "application/octet-stream"
                    }
                }, (err, res, body) => {
                    if (!err) {
                        resolve();
                    }
                    else {
                        console.log("uploadFile() request error: " + e);
                    }
                });
            });
        });
    }

    function makePdfUnSearchable(apiKey, uploadedFileUrl, password, pages, destinationFile) {
        // Prepare request to `Make UnSearchable PDF` API endpoint
        var queryPath = `/v1/pdf/makeunsearchable`;

        // JSON payload for api request
        var jsonPayload = JSON.stringify({
            name: path.basename(destinationFile), password: password, pages: pages, url: uploadedFileUrl, async: true
        });

        var reqOptions = {
            host: "api.pdf.co",
            method: "POST",
            path: queryPath,
            headers: {
                "x-api-key": apiKey,
                "Content-Type": "application/json",
                "Content-Length": Buffer.byteLength(jsonPayload, 'utf8')
            }
        };
        // Send request
        var postRequest = https.request(reqOptions, (response) => {
            response.on("data", (d) => {
                response.setEncoding("utf8");
                // Parse JSON response
                let data = JSON.parse(d);
                if (data.error == false) {
                    console.log(`Job #${data.jobId} has been created!`);
                    checkIfJobIsCompleted(data.jobId, data.url, destinationFile);
                }
                else {
                    // Service reported error
                    console.log("makePdfUnSearchable(): " + data.message);
                }
            });
        })
            .on("error", (e) => {
                // Request error
                console.log("makePdfUnSearchable(): " + e);
            });


        // Write request data
        postRequest.write(jsonPayload);
        postRequest.end();
    }


    function checkIfJobIsCompleted(jobId, resultFileUrl, destinationFile) {
        let queryPath = `/v1/job/check`;

        // JSON payload for api request
        let jsonPayload = JSON.stringify({
            jobid: jobId
        });

        let reqOptions = {
            host: "api.pdf.co",
            path: queryPath,
            method: "POST",
            headers: {
                "x-api-key": API_KEY,
                "Content-Type": "application/json",
                "Content-Length": Buffer.byteLength(jsonPayload, 'utf8')
            }
        };

        // Send request
        var postRequest = https.request(reqOptions, (response) => {
            response.on("data", (d) => {
                response.setEncoding("utf8");

                // Parse JSON response
                let data = JSON.parse(d);
                console.log(`Checking Job #${jobId}, Status: ${data.status}, Time: ${new Date().toLocaleString()}`);

                if (data.status == "working") {
                    // Check again after 3 seconds
                    setTimeout(function () { checkIfJobIsCompleted(jobId, resultFileUrl, destinationFile); }, 3000);
                }
                else if (data.status == "success") {
                    // Download PDF file
                    var file = fs.createWriteStream(destinationFile);
                    https.get(resultFileUrl, (response2) => {
                        response2.pipe(file)
                            .on("close", () => {
                                console.log(`Generated PDF file saved as "${destinationFile}" file.`);
                            });
                    });
                }
                else {
                    console.log(`Operation ended with status: "${data.status}".`);
                }
            })
        });

        // Write request data
        postRequest.write(jsonPayload);
        postRequest.end();
    }
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests
    import json

    # The authentication key (API Key).
    # Get your own by registering at https://app.pdf.co
    API_KEY = "*****************************************"

    # Base URL for PDF.co Web API requests
    BASE_URL = "https://api.pdf.co/v1"

    fileName = "https://pdfco-test-files.s3.us-west-2.amazonaws.com/document-parser/sample-invoice.pdf"

    url = "{}/pdf/makeunsearchable?url={}".format(BASE_URL, fileName)

    # Execute request and get response as JSON
    response = requests.get(url, headers={"x-api-key": API_KEY})
    if (response.status_code == 200):
      json = response.json()

      if json["error"] == False:
          # URL of unsearchable PDF
          unsearchableFile = json["url"]
          print(unsearchableFile)
    ```
  </Tab>

  <Tab title="PHP">
    ```php theme={null}
    <?
      $apiKey = "***************";
      $fileName = "https://pdfco-test-files.s3.us-west-2.amazonaws.com/document-parser/sample-invoice.pdf";
      $url = "https://api.pdf.co/v1/pdf/makeunsearchable?url=" . $fileName);

      // Create request
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-api-key: " . $apiKey));
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
      // Execute request
      $result = curl_exec($curl);
    ?>
    ```
  </Tab>
</Tabs>
