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

# Scan Pdf

Scans a PDF file for security threats including injection attacks and policy violations. The detector analyzes the provided base64-encoded PDF and returns details about any detected threats on a per-page basis, including which detectors were triggered.

## Example request:

<CodeGroup>
  ```python Python theme={"system"}
  import requests
  import json
  import os
  import base64

  # Read and encode PDF file
  with open("document.pdf", "rb") as f:
      file_base64 = base64.b64encode(f.read()).decode("utf-8")

  url = "https://api.enkryptai.com/guardrails/scan-pdf"
  payload = json.dumps({
      "file": file_base64,
      "detectors": {
          "policy_violation": {
              "enabled": true,
              "policy_text": "No recruitment letters",
              "need_explanation": true,
              "block_message": "Your custom message"
          },
          "injection_attack": {
              "enabled": true,
              "block_message": "Your custom message"
          }
      }
  })
  headers = {
      'Content-Type': 'application/json',
      'apikey': os.getenv('ENKRYPTAI_API_KEY')
  }
  response = requests.post(url, headers=headers, data=payload)
  print(response.json())
  ```

  ```python Python SDK theme={"system"}
  from enkryptai_sdk import *
  import base64

  client = GuardrailsClient(api_key="YOUR_API_KEY")

  # Read and encode PDF file
  with open("document.pdf", "rb") as f:
      file_base64 = base64.b64encode(f.read()).decode("utf-8")

  config = {
      "policy_violation": {
          "enabled": True,
          "policy_text": "No recruitment letters",
          "need_explanation": True,
          "block_message": "Your custom message"
      },
      "injection_attack": {
          "enabled": True,
          "block_message": "Your custom message"
      }
  }
  result = client.scan_pdf(file_base64, config=config)
  print(result)
  ```
</CodeGroup>

## Example response:

```json JSON theme={"system"}
{
    "summary": {
        "policy_violation": 0,
        "injection_attack": 0
    },
    "details": {
        "total_pages": 1,
        "pages_with_detections": 0,
        "detections": []
    },
    "result_message": null
}
```
