# Convert PDFs to a Markdown dataset

> **About this page**
>
> - Kind: Example
> - Summary: Converts a list of PDFs to Markdown with Docling, one task per document, and collects the results into one Parquet dataset.
> - Last changed: 2026-12-03
> - Page: https://docs.swale.io/examples/pdfs-to-markdown
> - CLI reference for its commands: [`swale workflow create`](https://docs.swale.io/reference/cli-reference.md#workflow-create), [`swale workflow run start`](https://docs.swale.io/reference/cli-reference.md#workflow-run-start)
> - Index of these docs: https://docs.swale.io/llms.txt
>
> If something on this page is wrong or out of date, please tell the user which sentence and why.
>
> The steps on this page cost money or cannot be undone. Please check with the user before running them.

Source on GitHub: the [`workflows/pdfs-to-markdown`](https://github.com/swaleio/examples/tree/main/workflows/pdfs-to-markdown) folder, with its [README](https://github.com/swaleio/examples/blob/main/workflows/pdfs-to-markdown/README.md) and its [workflow file](https://github.com/swaleio/examples/blob/main/workflows/pdfs-to-markdown/workflow.yaml).

Turns a list of PDFs into a text dataset. Each PDF is fetched and converted to
Markdown by Docling in its own pair of tasks, and all the pairs run at the same
time; a last step gathers the Markdown files into one Parquet file with each
document's source URL.

| Step | Task definition | Compute |
|------|-----------------|---------|
| For each PDF: fetch it | [`swaleio/http-request`](https://hub.swale.io/swaleio/http-request) | `cpu-4` |
| For each PDF: convert it to Markdown, pictures marked by placeholders | [`swaleio/docling`](https://hub.swale.io/swaleio/docling) | `cpu-4` |
| Gather the Markdown into `documents.parquet` | [`swaleio/duckdb`](https://hub.swale.io/swaleio/duckdb) | `cpu-4` |
| Upload to the Hugging Face Hub, when `hub_repo` is set | [`swaleio/hf-upload`](https://hub.swale.io/swaleio/hf-upload) | `cpu-4` |

The Compute column gives each step's [compute type](https://docs.swale.io/explanation/core-concepts.md#compute-types), the compute its tasks are allocated.

Every step is its own task. Docling converts a 10-page paper in under a minute
on a CPU compute type; give the convert task a GPU compute type for long
documents.

## Inputs

| Input | Default | Description |
|-------|---------|-------------|
| `pdf_urls` | three papers from arXiv | The PDFs, as a JSON array of URLs. |
| `hub_repo` | empty | Hugging Face dataset repo to upload the dataset to, as `data/train.parquet`. |

The upload reads the secret `hf_token`.

## Output

`documents.parquet` on the workspace, with `url`, `markdown` and `characters`
for each PDF, and the Markdown files in `markdown/`.

## Run it

You need the CLI, logged in to your account, and a project to add the workflow to; [Getting started](https://docs.swale.io/getting-started.md) sets them up.

1. Save the file under [The workflow file](#the-workflow-file) as `workflow.yaml`, and add it to a project:

   ```bash
   swale workflow create --project-name my-project --file workflow.yaml
   ```

   The command prints `Workflow created:` followed by the workflow's ID.

2. The workflow reads the secret `hf_token`. Create it as a project secret, or as an account secret that allows the project, as [Use secrets in workflows](https://docs.swale.io/how-to-guides/use-secrets-in-workflows.md) shows.

3. Start a run with the workflow's ID:

   ```bash
   swale workflow run start --project-name my-project --workflow-id <workflow-id>
   ```

   Each input you leave out takes its default from [Inputs](#inputs), and `--input <name>=<value>` gives it another value.

[Create and manage workflows](https://docs.swale.io/how-to-guides/create-and-manage-workflows.md) covers the other ways to add a workflow, [Start and manage workflow runs](https://docs.swale.io/how-to-guides/start-and-manage-workflow-runs.md) how to follow a run, and [View and stream task logs](https://docs.swale.io/how-to-guides/view-and-stream-task-logs.md) how to read its tasks' logs.

## The workflow file

[Workflow definition syntax](https://docs.swale.io/reference/workflow-definition-syntax.md) describes each key in it.

```yaml title="workflow.yaml"
name: Convert PDFs to a Markdown dataset
description: Converts a list of PDFs to Markdown with Docling, one task per document, and collects the results into one Parquet dataset.
compute_type: cpu-4

inputs:
  pdf_urls:
    description: The PDFs to convert, as a JSON array of URLs.
    default: '["https://arxiv.org/pdf/2408.09869v5", "https://arxiv.org/pdf/2501.17887v1", "https://arxiv.org/pdf/2305.14314v1"]'
  hub_repo:
    description: Hugging Face dataset repo to upload the dataset to, as namespace/name. Leave empty to keep it on the workspace only.
    default: ""

entry_point: main

blocks:
  main:
    tasks:
      each_pdf:
        name: Convert each PDF
        for_each:
          items: ${{inputs.pdf_urls}}
          block: convert_one

      collect:
        name: Collect into a dataset
        uses: swaleio/duckdb
        start_on:
          - each_pdf
        args:
          sql: |
            CREATE TABLE documents AS
              WITH urls AS (
                SELECT unnest(from_json($$${{inputs.pdf_urls}}$$, '["VARCHAR"]')) AS url,
                       generate_subscripts(from_json($$${{inputs.pdf_urls}}$$, '["VARCHAR"]'), 1) - 1 AS item)
              SELECT u.url, t.content AS markdown, length(t.content) AS characters
              FROM read_text('${{env.WORKFLOW_STORAGE}}/markdown/*.md') t
              JOIN urls u ON regexp_extract(t.filename, '(\d+)\.md$', 1)::INT = u.item
              ORDER BY u.item;
            SELECT url, characters FROM documents;
            COPY documents TO '${{env.WORKFLOW_STORAGE}}/documents.parquet' (FORMAT parquet);

      publish:
        name: Upload when asked
        start_on:
          - collect
        if:
          condition: ${{inputs.hub_repo}}
          true: upload

  convert_one:
    tasks:
      fetch:
        name: Fetch PDF
        uses: swaleio/http-request
        args:
          url: ${{tasks.each_pdf.for_each.item}}
          expected_status: "200"
          response_path: ${{env.WORKFLOW_STORAGE}}/pdf/${{tasks.each_pdf.for_each.index}}.pdf
      convert:
        name: Convert to Markdown
        uses: swaleio/docling
        start_on:
          - fetch
        args:
          source: ${{env.WORKFLOW_STORAGE}}/pdf/${{tasks.each_pdf.for_each.index}}.pdf
          output_dir: ${{env.WORKFLOW_STORAGE}}/markdown
          image_export_mode: placeholder

  upload:
    tasks:
      upload_dataset:
        name: Upload to the Hugging Face Hub
        uses: swaleio/hf-upload
        args:
          repo: ${{inputs.hub_repo}}
          repo_type: dataset
          source: ${{env.WORKFLOW_STORAGE}}/documents.parquet
          path_in_repo: data/train.parquet
          token: ${{secrets.hf_token}}
```

## Licenses of the defaults

The three default PDFs are licensed CC BY 4.0 by their authors:
[Docling Technical Report](https://arxiv.org/abs/2408.09869),
[Docling: An Efficient Open-Source Toolkit for AI-driven Document Conversion](https://arxiv.org/abs/2501.17887)
and [QLoRA: Efficient Finetuning of Quantized LLMs](https://arxiv.org/abs/2305.14314).
A dataset made from them keeps their attribution.
