# PDF & Word to AI-ready Markdown (Japanese-ready) (`petipeti/japanese-document-to-markdown`) Actor

Turn PDF and Word (.docx) files into clean Markdown chunks tagged with page numbers for RAG and LLMs. Fixes vertical Japanese text, strips furigana, removes repeated headers/footers and page numbers, keeps tables.

- **URL**: https://apify.com/petipeti/japanese-document-to-markdown.md
- **Developed by:** [peti peti](https://apify.com/petipeti) (community)
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 page 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

## PDF & Word to AI-ready Markdown (Japanese-ready)

Turn **PDF and Word (.docx)** files into **clean Markdown chunks tagged with page numbers**, ready for RAG, embeddings, ChatGPT/Claude uploads and knowledge bases.

Generic converters break on Japanese documents. This one fixes the usual problems:

| Problem in typical output | What this Actor does |
|---|---|
| **Vertical text (縦書き) comes out scrambled** or with sideways punctuation (︒ ︑ ﹁ ﹂ ︵ ︶) | Reads columns right to left, top to bottom, and turns vertical punctuation back into 。、「」（） |
| **Furigana (ルビ) mixed into the text**: 東京とうきょうは… | Detects the small kana printed over / beside the base text and removes it (Word: keeps only the base text of ruby) |
| **Headers, footers and page numbers repeated on every page**: 社外秘 / 第3章 / - 12 - | Removes page numbers and lines that repeat at the top or bottom of many pages |
| **Tables flattened into a word soup** | Keeps tables as Markdown tables (Word: merged cells handled; PDF: aligned columns detected) |
| Japanese lines joined with stray spaces, English words split by hyphens | Joins Japanese lines without spaces, re-joins hyphenated English words |
| No way to cite the source page | Every chunk has `pageStart` / `pageEnd`, the heading path, and the full Markdown has `<!-- page N -->` markers |

Works for English and other languages too. **Nothing is sent anywhere**: the files you link are downloaded and converted inside the run – no external conversion API, no OCR service, no other website is contacted.

### Input

```json
{
  "fileUrls": [
    "https://example.com/files/manual.pdf",
    "https://example.com/files/規程.docx"
  ],
  "maxChunkChars": 1500
}
```

Use direct download links (a link that returns the file itself). Leave `fileUrls` empty to convert a small built-in Japanese sample and see the output.

### Output

One dataset item per chunk:

```json
{
  "file": "manual.pdf",
  "fileType": "pdf",
  "chunkIndex": 3,
  "pageStart": 4,
  "pageEnd": 5,
  "headings": ["第2章 操作方法", "2.1 初期設定"],
  "text": "## 2.1 初期設定\n\n電源を入れると…\n\n| 項目 | 初期値 |\n| --- | --- |\n| 言語 | 日本語 |",
  "chars": 412,
  "chunkCount": 18
}
```

Also stored in the key-value store:

- `markdown-1`, `markdown-2`, … – the full Markdown of each file (with page markers)
- `OUTPUT` – per file: pages, chunks, furigana and header/footer lines removed, number of vertical pages, warnings

### Options

| Option | Default | |
|---|---|---|
| `maxChunkChars` | 1500 | Chunks are cut at headings and paragraph ends; long paragraphs at sentence ends; long tables between rows, header row repeated |
| `removeFurigana` | true | Off: Word files write 東京（とうきょう） |
| `removeHeadersFooters` | true | PDF only (Word keeps them outside the body anyway) |
| `pageMarkers` | true | `<!-- page N -->` in the full Markdown |
| `maxPagesPerFile` | 500 | Pages beyond this are skipped and not charged |

### Limits

- **Scanned PDFs (images without a text layer) are not supported** – there is no OCR. The run reports a warning instead of empty output.
- Old binary `.doc` files: open in Word and save as `.docx`.
- PDF tables are detected from column alignment; tables drawn with very irregular spacing may come out as paragraphs. Multi-column horizontal layouts (two-column papers) are read row by row.
- Headings in PDFs are detected from font size; in Word from heading styles (見出し 1, Heading 1 …).
- Up to 100 MB per file.

### Pricing

Pay per event, platform usage included:

| Event | Price |
|---|---|
| Actor start | $0.01 per run |
| `page-processed` – one page converted | $3.00 per 1,000 pages ($0.003 per page) |

Example: a 120-page PDF costs $0.01 + $0.36 = $0.37. For Word files the page count Word saved in the file is used. Files that fail to convert and the built-in sample are not charged.

### 日本語での説明

PDF と Word（.docx）を、AI（RAG・ChatGPT・Claude など）にそのまま渡せる Markdown に変換し、ページ番号付きのチャンクに分けます。日本語の資料でよく起きる崩れを直します。

- 縦書き: 右の列から順に読み、縦書き用の句読点・かっこ（︒ ︑ ﹁ ﹂ ︵ ︶）を 。、「」（） に戻します
- ふりがな（ルビ）が本文に混ざるのを取り除きます（Word のルビは親文字だけ残します）
- 各ページの上下に繰り返される見出し・「社外秘」・ページ番号を取り除きます
- 表は Markdown の表として残します（Word の結合セルにも対応）
- 各チャンクに pageStart / pageEnd と見出しの階層が付くので、出典のページを示せます

指定したファイルをダウンロードして実行の中で変換するだけで、外部の変換サービスやほかのサイトにはアクセスしません。画像だけのスキャン PDF（文字情報がないもの）は OCR をしないため変換できません。

料金: 1回の実行ごとに $0.01、1ページあたり $0.003（1,000ページで $3）。変換に失敗したファイルとお試し用サンプルは課金しません。

# Actor input Schema

## `fileUrls` (type: `array`):

Direct download links to your PDF or Word .docx files, one per line – e.g. a file in your own storage, an Apify key-value store record URL, or a public link that downloads the file itself. Only these links are downloaded. Leave empty to convert a small Japanese sample PDF and see the output format.

## `maxChunkChars` (type: `integer`):

Chunks are cut at headings and paragraph ends; long paragraphs at sentence ends (。！？.!?), long tables between rows with the header row repeated.

## `removeFurigana` (type: `boolean`):

Drops reading aids such as とうきょう printed over 東京, so they do not get mixed into the text. Off: PDFs keep them as separate lines, Word files write 東京（とうきょう）.

## `removeHeadersFooters` (type: `boolean`):

Lines at the top or bottom of the page that are page numbers (12, - 12 -, 12/40, 12頁…) or that repeat on many pages (document title, 社外秘, chapter name) are removed. Word files keep headers and footers outside the body, so they never appear.

## `pageMarkers` (type: `boolean`):

Adds  comments to the full Markdown file. Chunks always carry pageStart / pageEnd.

## `maxPagesPerFile` (type: `integer`):

PDF pages beyond this are skipped (and not charged).

## Actor input object example

```json
{
  "maxChunkChars": 1500,
  "removeFurigana": true,
  "removeHeadersFooters": true,
  "pageMarkers": true,
  "maxPagesPerFile": 500
}
```

# Actor output Schema

## `chunks` (type: `string`):

One item per chunk: file, pageStart, pageEnd, heading path, Markdown text.

## `markdown` (type: `string`):

Each file's full Markdown is stored as markdown-1, markdown-2, … in the key-value store.

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

OUTPUT record: pages, chunks, furigana and header/footer lines removed, vertical pages, warnings.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("petipeti/japanese-document-to-markdown").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("petipeti/japanese-document-to-markdown").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 '{}' |
apify call petipeti/japanese-document-to-markdown --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,petipeti/japanese-document-to-markdown"
        }
    }
}
```

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/ldLu7K43JSEYWVP10/builds/vjgebGh2vCRf7u2FW/openapi.json
