# FormatForge — Document Converter & OCR (`kopachelli/formatforge`) Actor

Convert documents between formats and run OCR — PDF, DOCX, XLSX, HTML, Markdown and PNG/JPEG/TIFF images. Files come from a URL, a key-value-store record or base64; one dataset item per file, pay per event.

- **URL**: https://apify.com/kopachelli/formatforge.md
- **Developed by:** [Khristian Kopachelli](https://apify.com/kopachelli) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 file converteds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## FormatForge — Document Converter & OCR

Convert documents between formats and run OCR, in batch. Give the Actor a list of
files — each a public **HTTPS URL**, a **key-value-store record key**, or inline
**base64** — and a target format. Every file produces one dataset item; converted
output up to 64 KB is inline, larger output is stored in the run's key-value store.

Pure TypeScript/WASM — no LibreOffice, no macros, no shell-out. Your files are
parsed by maintained open-source libraries only.

### What it converts

| From | To `text` | To `markdown` | To `html` | To `json` | To `csv` |
|---|---|---|---|---|---|
| PDF (text layer) | ✓ | ✓ | — | — | — |
| PDF (scanned, no text layer) | `failed` — "no text layer" | `failed` — same | — | — | — |
| DOCX | ✓ | ✓ | ✓ | — | — |
| XLSX / XLS | — | — | — | ✓ | ✓ |
| HTML | ✓ | ✓ | — | — | — |
| Markdown / plain text | ✓ | ✓ | ✓ | — | — |
| PNG / JPEG / TIFF | ✓ (OCR) | — | — | — | — |

The `from` type is **sniffed from the bytes** — a renamed or mislabeled file is
detected correctly or reported `failed`, never guessed. The filename extension is
used only when the bytes are inconclusive, and never overrides a known type.

### Input

```json
{
    "files": [
        { "name": "report.pdf", "url": "https://example.com/files/report.pdf", "to": "text" },
        { "name": "sheet.xlsx", "keyValueStoreKey": "INPUT-sheet", "to": "csv" },
        { "name": "scan.png", "base64": "iVBORw0KGgo…", "to": "text" }
    ],
    "defaultTo": "text",
    "maxItems": 100,
    "fetchConcurrency": 2,
    "validateOnly": false
}
```

- **Exactly one source per file:** `url`, `keyValueStoreKey`, or `base64`.
- `url`: public **https** only, port 443, no credentials. Private, loopback,
  link-local and metadata addresses are refused after DNS resolution. Redirects
  are not followed.
- `keyValueStoreKey`: a record in this run's default key-value store — the way to
  feed files you uploaded with the run.
- `base64`: inline file content (encoded size ≤ 4 MB).
- `to`: `text`, `markdown`, `html`, `json` or `csv`. Falls back to `defaultTo`.
- `validateOnly`: check inputs without fetching, converting or charging.

### Output

One dataset item per file:

- `status`: `converted` · `ocr` · `failed` · `skipped`
- `source` — `url` / `keyValueStore` / `base64` (the URL itself is never stored)
- `detectedType`, `to`, `reason` (always populated — `ok` on success)
- `outputText` — the result inline (≤ 64 KB)
- `outputKey` + `outputBytes` — when the result is larger, it is stored in the
  run's key-value store under `output/<index>-<name>`
- `ocrPages`, `ocrConfidence` — for OCR results
- `fetchLatencyMs`, `convertLatencyMs`, `bytesIn`

A run summary is written to the `OUTPUT` key-value-store record.

### Limits (hard caps, never "unlimited")

| Limit | Value |
|---|---|
| Files per run | 100 |
| File size | 25 MB |
| Base64 source | 4 MB encoded |
| Per-file fetch | 60 s |
| Per-file conversion | 60 s |
| PDF pages per file | 500 |
| OCR images per file | single-page only (multi-page TIFF refused) |
| Inline output | 64 KB (larger → KVS, ≤ 8 MB) |

Exceeding a cap stops the run with a clear status — nothing is silently
truncated.

### Pricing

Pay per event:

- **`formatforge-file`** — per file that reached conversion: `converted`, `ocr`,
  or a converter `failed` (the work was done). Not charged for `skipped` inputs,
  fetch/sniff/unsupported-pair failures, or `validateOnly` runs.
- **`formatforge-ocr-page`** — per OCR'd page.

`validateOnly` runs are free. Final prices are set by the owner at publication.

### Honest limitations

- **Scanned PDFs are not OCR'd in v1.** A PDF with no text layer fails with a
  clear reason. OCR works on PNG/JPEG and single-page TIFF images — a
  multi-page TIFF is refused (split it first).
- **No PDF/DOCX generation** — this Actor extracts and converts *to* text-family
  formats, not back into office documents.
- **Password-protected and encrypted files are not supported.**
- **No browser-TLS impersonation.** A CDN that answers 403 gets an honest
  `failed` item with the HTTP status.
- **OCR downloads its language data once.** The first OCR run fetches
  `eng.traineddata` from the tesseract.js CDN; without network access OCR
  reports `failed` rather than hanging.
- XLS (legacy binary) is read as XLSX where possible; results vary — XLSX is the
  tested path.

### Notes for API users

- This Actor processes files **you** supply — it is not a crawler and stores
  nothing beyond the run's own storage (normal retention).
- It identifies itself with `FormatForge/1.0 (+https://apify.com/kopachelli/formatforge)`.
- State is checkpointed per file: an interrupted run resumes without
  re-processing finished files.

# Actor input Schema

## `files` (type: `array`):

The files to convert, one object per file: { "name": "report.pdf", "url": "https://…" } or { "keyValueStoreKey": "INPUT-file" } or { "base64": "…" }. Give exactly one source per file. Optional "to": text, markdown, html, json or csv (falls back to defaultTo).

## `defaultTo` (type: `string`):

Target format for files that do not set their own "to". pdf/docx/html/markdown/text convert to text, markdown or html; xlsx converts to json or csv; images (png, jpeg, tiff) convert to text via OCR.

## `validateOnly` (type: `boolean`):

Check the input structure without fetching, converting or charging. Every file reports status skipped.

## `maxItems` (type: `integer`):

The run stops after this many files. There is no "unlimited": the largest value is 100.

## `fetchConcurrency` (type: `integer`):

How many files are fetched and converted at the same time. Higher values finish faster but use more memory.

## Actor input object example

```json
{
  "files": [
    {
      "name": "smoke.md",
      "base64": "IyBGb3JtYXRGb3JnZQoKU21va2UgdGVzdDogdGhpcyBtYXJrZG93biBjb252ZXJ0cyB0byBIVE1MLgo=",
      "to": "html"
    },
    {
      "name": "sample.pdf",
      "url": "https://example.com/files/sample.pdf",
      "to": "text"
    },
    {
      "name": "sheet.xlsx",
      "keyValueStoreKey": "INPUT-sheet",
      "to": "csv"
    }
  ],
  "defaultTo": "text",
  "validateOnly": false,
  "maxItems": 100,
  "fetchConcurrency": 2
}
```

# Actor output Schema

## `items` (type: `string`):

One item per file: detected type, target format, status, inline output or the KVS key of the stored output, OCR stats and timings.

## `summary` (type: `string`):

How the run ended: files received, per-status counts, why it stopped.

# 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 = {
    "files": [
        {
            "name": "smoke.md",
            "base64": "IyBGb3JtYXRGb3JnZQoKU21va2UgdGVzdDogdGhpcyBtYXJrZG93biBjb252ZXJ0cyB0byBIVE1MLgo=",
            "to": "html"
        },
        {
            "name": "sample.pdf",
            "url": "https://example.com/files/sample.pdf",
            "to": "text"
        },
        {
            "name": "sheet.xlsx",
            "keyValueStoreKey": "INPUT-sheet",
            "to": "csv"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("kopachelli/formatforge").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 = { "files": [
        {
            "name": "smoke.md",
            "base64": "IyBGb3JtYXRGb3JnZQoKU21va2UgdGVzdDogdGhpcyBtYXJrZG93biBjb252ZXJ0cyB0byBIVE1MLgo=",
            "to": "html",
        },
        {
            "name": "sample.pdf",
            "url": "https://example.com/files/sample.pdf",
            "to": "text",
        },
        {
            "name": "sheet.xlsx",
            "keyValueStoreKey": "INPUT-sheet",
            "to": "csv",
        },
    ] }

# Run the Actor and wait for it to finish
run = client.actor("kopachelli/formatforge").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "files": [
    {
      "name": "smoke.md",
      "base64": "IyBGb3JtYXRGb3JnZQoKU21va2UgdGVzdDogdGhpcyBtYXJrZG93biBjb252ZXJ0cyB0byBIVE1MLgo=",
      "to": "html"
    },
    {
      "name": "sample.pdf",
      "url": "https://example.com/files/sample.pdf",
      "to": "text"
    },
    {
      "name": "sheet.xlsx",
      "keyValueStoreKey": "INPUT-sheet",
      "to": "csv"
    }
  ]
}' |
apify call kopachelli/formatforge --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,kopachelli/formatforge"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Y4xDXeVHXiQwdI97S/builds/QOM1PmhZp5c0arpLm/openapi.json
