# Fast Pdf Processor (`contemporary_fruit/pdf-processor-actor`) Actor

This API is a PDF Processing Service allowing users to upload a PDF to:

Extract Text: Reads all text from the PDF and returns it as structured JSON data per page.
Merge Pages: Creates a new PDF containing only the specific pages selected by the user. (260 characters)

- **URL**: https://apify.com/contemporary\_fruit/pdf-processor-actor.md
- **Developed by:** [Andric](https://apify.com/contemporary_fruit) (community)
- **Categories:** Developer tools, Automation, Other
- **Stats:** 3 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$4.99/month + usage

To use this Actor, you pay a monthly rental fee to the developer. The rent is subtracted from your prepaid usage every month after the free trial period.You also pay for the Apify platform usage, which gets cheaper the higher Apify subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#rental-actors

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## PDF Processor - Apify Actor Deployment Guide

### Overview
This PDF Processor provides four main operations via Apify Actor:
1. **Extract Text** - Extract text content from all PDF pages
2. **Merge Pages** - Create new PDFs with selected pages only
3. **HTML to PDF** - Convert HTML content to PDF using Playwright
4. **URL to PDF** - Convert web pages to PDF using Playwright

### Files Structure

````

pdf-processor-actor/
├── main.py                    # Apify Actor wrapper (main entry point)
├── requirements.txt           # Dependencies for Apify deployment
├── requirements\_apify.txt     # Alternative requirements file
├── Dockerfile                 # Docker configuration for Apify
├── actor.json                 # Apify Actor configuration
├── INPUT\_SCHEMA.json          # Input schema definition
├── apify\_input\_schema.json   # Legacy input schema
├── apify\_output\_schema.json  # Output schema definition
├── sample\_inputs.json         # Example inputs for testing
├── test\_local.py              # Local testing script
├── n8n\_workflow\_example.json  # n8n integration example
├── n8n\_direct\_api\_workflow.json # n8n direct API workflow
├── QUICK\_START.md            # Quick start guide
├── apify.json                # Apify configuration
├── actor/                    # Actor configuration directory
│   ├── actor.json
│   └── dataset\_schema.json
└── README.md                  # This file

````

### Deployment Steps

#### 1. Prepare Your Repository

```bash
## Create a new directory for your actor
mkdir pdf-processor-actor
cd pdf-processor-actor

## Copy all the provided files
cp /path/to/main.py .
cp /path/to/app.py .
cp /path/to/requirements_apify.txt .
cp /path/to/Dockerfile .
cp /path/to/actor.json .
cp /path/to/apify_input_schema.json .
cp /path/to/apify_output_schema.json .
cp /path/to/sample_inputs.json .
````

#### 2. Deploy to Apify

##### Option A: Using Apify CLI

```bash
## Install Apify CLI
npm install -g apify-cli

## Login to your Apify account
apify login

## Initialize the actor
apify init

## Push to Apify platform
apify push
```

##### Option B: Using GitHub Integration

1. Push your code to a GitHub repository
2. Go to [Apify Console](https://console.apify.com)
3. Click "Actors" → "Create new"
4. Choose "From GitHub repository"
5. Connect your GitHub repo
6. Apify will automatically build and deploy

#### 3. Configure the Actor

In Apify Console:

1. Navigate to your actor
2. Go to "Settings" tab
3. Set the following:
   - **Build tag**: `latest`
   - **Memory**: `512 MB` (minimum, increase for complex webpages or large PDFs)
   - **Timeout**: `300 seconds` (adjust based on PDF size and webpage complexity)

#### 4. Test Your Actor

1. Go to the "Input" tab
2. Use one of the sample inputs:

**Extract Text:**

```json
{
  "action": "extract-text",
  "pdfUrl": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
}
```

**Merge Pages:**

```json
{
  "action": "merge-pages",
  "pdfUrl": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf",
  "pageNumbers": [0, 2, 4]
}
```

**HTML to PDF:**

```json
{
  "action": "html-to-pdf",
  "html": "<html><body><h1>Hello World</h1><p>This is a test PDF.</p></body></html>"
}
```

**URL to PDF:**

```json
{
  "action": "url-to-pdf",
  "pdfUrl": "https://example.com"
}
```

3. Click "Run"
4. Check the output in the "Dataset" tab

### Usage Examples

#### Via Apify API

```python
from apify_client import ApifyClient

client = ApifyClient('YOUR_API_TOKEN')
actor = client.actor('YOUR_USERNAME/pdf-processor')

## Extract text
run = actor.call(run_input={
    "action": "extract-text",
    "pdfUrl": "https://example.com/document.pdf"
})

## HTML to PDF
run = actor.call(run_input={
    "action": "html-to-pdf",
    "html": "<html><body><h1>Invoice</h1><p>Amount: $100</p></body></html>"
})

## URL to PDF
run = actor.call(run_input={
    "action": "url-to-pdf",
    "pdfUrl": "https://example.com"
})

## Get results
dataset = client.dataset(run['defaultDatasetId'])
results = list(dataset.iterate_items())
```

#### Via REST API

```bash
## Extract text
curl -X POST https://api.apify.com/v2/acts/YOUR_USERNAME~pdf-processor/runs \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -d '{
    "action": "extract-text",
    "pdfUrl": "https://example.com/document.pdf"
  }'

## HTML to PDF
curl -X POST https://api.apify.com/v2/acts/YOUR_USERNAME~pdf-processor/runs \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -d '{
    "action": "html-to-pdf",
    "html": "<html><body><h1>Invoice</h1></body></html>"
  }'

## URL to PDF
curl -X POST https://api.apify.com/v2/acts/YOUR_USERNAME~pdf-processor/runs \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -d '{
    "action": "url-to-pdf", 
    "pdfUrl": "https://example.com"
  }'
```

### Monitoring

- Check logs in the "Runs" tab for debugging
- Monitor performance in the "Analytics" tab
- Set up webhooks for run completion notifications

### Cost Estimation

- **Compute Units**:
  - Text extraction: ~0.001 CU per page
  - Page merging: ~0.002 CU per page
  - HTML/URL to PDF: ~0.005-0.02 CU (depends on complexity and load time)
- **Storage**: Minimal for text, ~1 MB per 100 pages for generated PDFs
- **Bandwidth**: Depends on PDF/webpage size (input + output)

### Limitations

- Maximum PDF size: 100 MB (configurable)
- Maximum pages to process: 1000 (configurable)
- Timeout: 5 minutes default (configurable)
- HTML/URL to PDF: Requires Playwright/Chrome (included in Docker image)
- Complex JavaScript sites may need additional wait time

### Support

For issues or questions:

1. Check the actor logs for error details
2. Verify PDF URL is publicly accessible
3. Ensure page numbers are within valid range

### License

MIT

# Actor input Schema

## `action` (type: `string`):

Choose which operation to perform.

## `pdfUrl` (type: `string`):

Direct URL to a PDF (for extraction/merge) OR a Website URL (for url-to-pdf).

## `html` (type: `string`):

Raw HTML string to convert to PDF. (Required only for html-to-pdf action)

## `pdfBase64` (type: `string`):

Base64-encoded PDF data (alternative to pdfUrl for binary uploads).

## `pageNumbers` (type: `array`):

List of page indices (0-based) to extract and merge.

## `saveToKeyValueStore` (type: `boolean`):

Whether to save the output PDF to Apify's Key-Value Store (generates download URL).

## Actor input object example

```json
{
  "action": "extract-text",
  "pdfUrl": "https://raw.githubusercontent.com/mozilla/pdf.js/master/web/compressed.tracemonkey-pldi-09.pdf",
  "pageNumbers": [
    0,
    1
  ],
  "saveToKeyValueStore": true
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "pdfUrl": "https://raw.githubusercontent.com/mozilla/pdf.js/master/web/compressed.tracemonkey-pldi-09.pdf"
};

// Run the Actor and wait for it to finish
const run = await client.actor("contemporary_fruit/pdf-processor-actor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "pdfUrl": "https://raw.githubusercontent.com/mozilla/pdf.js/master/web/compressed.tracemonkey-pldi-09.pdf" }

# Run the Actor and wait for it to finish
run = client.actor("contemporary_fruit/pdf-processor-actor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "pdfUrl": "https://raw.githubusercontent.com/mozilla/pdf.js/master/web/compressed.tracemonkey-pldi-09.pdf"
}' |
apify call contemporary_fruit/pdf-processor-actor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=contemporary_fruit/pdf-processor-actor",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Fast Pdf Processor",
        "description": "This API is a PDF Processing Service allowing users to upload a PDF to:\n\nExtract Text: Reads all text from the PDF and returns it as structured JSON data per page.\nMerge Pages: Creates a new PDF containing only the specific pages selected by the user. (260 characters)",
        "version": "0.0",
        "x-build-id": "keC9OrZ2NCsCffZrt"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/contemporary_fruit~pdf-processor-actor/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-contemporary_fruit-pdf-processor-actor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/contemporary_fruit~pdf-processor-actor/runs": {
            "post": {
                "operationId": "runs-sync-contemporary_fruit-pdf-processor-actor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/contemporary_fruit~pdf-processor-actor/run-sync": {
            "post": {
                "operationId": "run-sync-contemporary_fruit-pdf-processor-actor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "action"
                ],
                "properties": {
                    "action": {
                        "title": "Action",
                        "enum": [
                            "extract-text",
                            "merge-pages",
                            "html-to-pdf",
                            "url-to-pdf"
                        ],
                        "type": "string",
                        "description": "Choose which operation to perform.",
                        "default": "extract-text"
                    },
                    "pdfUrl": {
                        "title": "PDF / Target URL",
                        "type": "string",
                        "description": "Direct URL to a PDF (for extraction/merge) OR a Website URL (for url-to-pdf)."
                    },
                    "html": {
                        "title": "HTML Content",
                        "type": "string",
                        "description": "Raw HTML string to convert to PDF. (Required only for html-to-pdf action)"
                    },
                    "pdfBase64": {
                        "title": "PDF Base64 Data",
                        "type": "string",
                        "description": "Base64-encoded PDF data (alternative to pdfUrl for binary uploads)."
                    },
                    "pageNumbers": {
                        "title": "Page Numbers (Merge Only)",
                        "type": "array",
                        "description": "List of page indices (0-based) to extract and merge.",
                        "items": {
                            "type": "integer"
                        },
                        "default": [
                            0,
                            1
                        ]
                    },
                    "saveToKeyValueStore": {
                        "title": "Save to Key-Value Store",
                        "type": "boolean",
                        "description": "Whether to save the output PDF to Apify's Key-Value Store (generates download URL).",
                        "default": true
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
