Docling convert
Runs docling convert from Docling
(MIT). Docling reads PDF, Word, PowerPoint, Excel, HTML, Markdown, image and
other document files, works out each page's layout, reading order and table
structure with its own models, recognizes the text of scanned pages with OCR,
and writes the document as Markdown, JSON, HTML or plain text. The result keeps
headings, lists and tables, which makes it a good first step for building a
dataset or a retrieval index from documents.
source is one file, a directory whose files are all converted, or a URL.
Each input file becomes one output file in output_dir, with the same name and
the output format's extension.
The models Docling's standard pipeline runs are in the image, under the
licenses its Docker Hub page lists, so conversion downloads nothing. With
to: chunks, Docling counts each chunk's tokens with a tokenizer it downloads
from the Hugging Face Hub, sentence-transformers/all-MiniLM-L6-v2 (Apache-2.0)
unless configured otherwise.
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
source |
yes | — | Absolute path of a file or a directory of files, or a URL. |
output_dir |
yes | — | Absolute path of the directory the results are written to, one file per input. Point it at the mounted workspace (e.g. ${{env.WORKFLOW_STORAGE}}/markdown) to share them with later tasks. |
to |
no | md |
md, json, html, text, doctags, yaml, or chunks (pieces sized for embedding). |
image_export_mode |
no | embedded |
embedded puts pictures inline as base64, Docling's default; referenced saves them as files beside the output; placeholder only marks where they were, which keeps text output small. |
device |
no | auto |
auto uses the GPU when the compute type has one; cpu or cuda forces one. |
Outputs
None. The results are in output_dir, a path the workflow chose; pass it to
the next task.
Compute
GPU recommended. Docling runs its layout and table models on the GPU when
there is one and on the CPU otherwise. A 9-page paper converts in about 20
seconds on a CPU and in about a third of that on a GPU; a CPU compute type
suits small batches, and for_each spreads many documents over parallel tasks.
Example
Fetch the Docling technical report from arXiv (CC BY 4.0) and convert it to Markdown, with each picture marked by a placeholder:
name: Docling example
compute_type: cpu-4
entry_point: main
blocks:
main:
tasks:
fetch:
name: Fetch PDF
uses: swaleio/http-request
args:
url: https://arxiv.org/pdf/2408.09869v5
expected_status: "200"
response_path: ${{env.WORKFLOW_STORAGE}}/pdf/docling-report.pdf
convert:
name: Convert to Markdown
uses: swaleio/docling
start_on:
- fetch
args:
source: ${{env.WORKFLOW_STORAGE}}/pdf
output_dir: ${{env.WORKFLOW_STORAGE}}/markdown
image_export_mode: placeholder
Later tasks read ${{env.WORKFLOW_STORAGE}}/markdown/docling-report.md.
For the workflow syntax these examples use, see the workflow definition reference in the Swale documentation.
Licensed under the MIT License.