---
name: doc-parser-53ffd8a7ebc2
description: >-
  Parse complex documents with IBM's open-source Docling library, which
  turns PDFs and Office files into structured Markdown or JSON. Use when a
  user asks to parse a document with tables, extract figures from a document, handle multi-column
  layouts, convert a complex PDF to structured data, extract content from
  academic papers, or process documents with mixed layouts. Handles tables,
  figures, headers, footers, and multi-column text.
license: Apache-2.0
compatibility: "Requires Python 3.10+ with the docling package (pulls in PyTorch)"
metadata:
  author: terminal-skills
  version: "1.1.0"
  category: documents
  tags: "parsing, docling, tables, figures, layout"
  repository: https://github.com/docling-project/docling
  use-cases: "Extract tables and figures from academic papers with complex layouts, Parse financial reports with multi-column formats and embedded charts, Convert complex documents to clean Markdown or JSON preserving structure"
  agents: "claude-code, openai-codex, gemini-cli, cursor"
---

# Document Parser

## Overview

Parse complex documents containing tables, figures, multi-column layouts, headers, and mixed content using the Docling library (originally from IBM Research, now an open-source LF AI & Data project). This skill goes beyond simple text extraction by understanding document structure, detecting layout regions, and preserving the logical reading order across complex formatting.

## Instructions

When a user asks to parse a complex document or extract structured content from a document with tables, figures, or multi-column layouts, follow these steps:

### Step 1: Install docling

```bash
python -m venv .venv && .venv/bin/pip install docling
```

Docling needs Python 3.10+ and depends on PyTorch. On a Linux machine without a GPU, `pip install docling --extra-index-url https://download.pytorch.org/whl/cpu` avoids the large CUDA wheels. The first conversion downloads the layout and table models from Hugging Face, so allow time and network access once.

For a quick one-off, the CLI writes Markdown to the output folder (add `--to json` or `--to html` for other formats):

```bash
.venv/bin/docling Q3-report.pdf --output converted/
```

### Step 2: Load and convert the document

Use `DocumentConverter` to parse the document. Reuse one converter for many files; creating it is the expensive part.

```python
from docling.document_converter import DocumentConverter

converter = DocumentConverter()
result = converter.convert("paper.pdf")        # a local path or an http(s) URL
doc = result.document                          # a DoclingDocument
```

Supported inputs include PDF, DOCX, XLSX, PPTX, HTML, Markdown, CSV, EPUB, images (PNG, JPEG, TIFF, BMP, WEBP), and more; the current list is in the "Supported formats" page of the docling documentation. Legacy `.doc`/`.xls`/`.ppt` and RTF need LibreOffice installed. To limit work on a long PDF, pass `page_range=(1, 20)` to `convert()`.

### Step 3: Export to the desired format

**Markdown** (headings, tables, lists):

```python
markdown = doc.export_to_markdown()
```

**Lossless JSON** (the full document tree, reloadable later):

```python
import json
with open("paper.json", "w") as fp:
    json.dump(doc.export_to_dict(), fp, indent=2)
```

`doc.save_as_markdown("paper.md")`, `doc.save_as_json("paper.json")` and `doc.save_as_html("paper.html")` write files directly.

### Step 4: Handle specific content types

**Tables**: pass the document to `export_to_dataframe` (the argument is required in current versions) and write CSV:

```python
from pathlib import Path

def save_tables(doc, output_dir="tables"):
    Path(output_dir).mkdir(exist_ok=True)
    for i, table in enumerate(doc.tables, start=1):
        df = table.export_to_dataframe(doc=doc)
        df.to_csv(f"{output_dir}/table_{i}.csv", index=False)
    return len(doc.tables)
```

**Figures**: pictures are in `doc.pictures`. To save the image files, ask the PDF pipeline to keep them:

```python
from docling.datamodel.base_models import InputFormat
from docling.datamodel.pipeline_options import PdfPipelineOptions
from docling.document_converter import DocumentConverter, PdfFormatOption

options = PdfPipelineOptions()
options.images_scale = 2.0               # about 144 DPI
options.generate_picture_images = True
converter = DocumentConverter(format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=options)})
doc = converter.convert("paper.pdf").document

for n, picture in enumerate(doc.pictures, start=1):
    page = picture.prov[0].page_no if picture.prov else None
    print(n, page, picture.caption_text(doc) or "no caption")
    picture.get_image(doc).save(f"figure_{n}.png")
```

**Reading order and sections**: `for item, level in doc.iterate_items():` walks headings, paragraphs, tables and pictures in reading order.

**Scanned pages and images**: OCR runs automatically on bitmap content. Pick the language and engine with `--ocr-lang` / `--ocr-engine` on the CLI, or `PdfPipelineOptions.ocr_options`. Use `--no-ocr` to skip it for born-digital PDFs.

### Step 5: Present the results

Format output based on user needs:
- **Full document**: Markdown export with all content preserved
- **Tables only**: CSV files or formatted markdown tables
- **Summary**: Document structure outline with section headings and content types found
- **Specific sections**: Extract targeted parts by heading or page range

## Examples

### Example 1: Parse an academic paper

**User request:** "Parse this research paper and extract all the tables: paper.pdf"

**Actions taken:**
1. Convert paper.pdf using docling
2. Identify 4 tables across 12 pages
3. Export each table as CSV

**Output:**
```
Parsed paper.pdf (12 pages)

Document structure:
  - Title: "Machine Learning Approaches for Climate Prediction"
  - Sections: Abstract, Introduction, Methods, Results, Discussion, References
  - Tables found: 4
  - Figures found: 6

Tables extracted:
  1. table_1.csv - "Dataset Characteristics" (5 cols, 8 rows) - Page 4
  2. table_2.csv - "Model Hyperparameters" (4 cols, 12 rows) - Page 6
  3. table_3.csv - "Performance Comparison" (6 cols, 5 rows) - Page 8
  4. table_4.csv - "Ablation Study Results" (5 cols, 7 rows) - Page 9

All tables saved to current directory.
```

### Example 2: Convert a financial report to Markdown

**User request:** "Convert this quarterly report to Markdown so I can edit it: Q3-report.pdf"

**Actions taken:**
1. Parse Q3-report.pdf with docling (handles multi-column layout)
2. Export as clean Markdown preserving structure

**Output:**
```
Converted Q3-report.pdf to Markdown

Document details:
  - Pages: 24
  - Layout: Multi-column (2-column on pages 3-20)
  - Tables: 8 (all converted to Markdown tables)
  - Figures: 5 (referenced with captions)
  - Sections: 12 headings detected

Output saved to: Q3-report.md (14,200 words)

The multi-column layout has been linearized into single-column reading order.
All tables are preserved as Markdown tables.
```

### Example 3: Pull the line items out of an invoice

**User request:** "Parse this invoice and give me the line items as JSON"

**Actions taken:**
1. Convert invoice.pdf and take the first table (`doc.tables[0]`), which holds the line items
2. Export it with `export_to_dataframe(doc=doc)` and write `df.to_json(orient="records", indent=2)`
3. Read invoice number, date and totals from the Markdown text, since docling returns layout, not named fields

**Output:**
```json
[
  {"Item": "Office Chairs", "Qty": 10, "Unit Price": "299.99", "Total": "2,999.90"},
  {"Item": "Standing Desks", "Qty": 5, "Unit Price": "549.00", "Total": "2,745.00"},
  {"Item": "Monitor Arms", "Qty": 15, "Unit Price": "89.50", "Total": "1,342.50"}
]
```

Column names come from the printed header row and cell values are text, so convert amounts to numbers yourself and check the sum against the invoice total.

## Guidelines

- Docling handles complex layouts automatically including multi-column text, nested tables, and mixed content. Let it do the heavy lifting.
- For very large documents (200+ pages), convert in page ranges (`page_range=(1, 50)`) to manage memory, and use a GPU (`--device cuda`) if one is available.
- `--pipeline vlm` runs a vision-language model (GraniteDocling) instead of the default layout and table models; slower, but sometimes better on messy scans. Check results either way.
- When tables have merged cells or irregular structures, validate the DataFrame output and flag any parsing anomalies.
- Prefer Markdown export for human-readable output and JSON/dict export for programmatic use.
- If docling fails to install or parse a specific format, fall back to pdfplumber for PDFs or python-docx for DOCX files. Pass untrusted files only inside a sandbox or container, as with any parser.
- Always report the document structure (sections, tables, figures found) before detailed output so the user knows what is available.
- For scanned documents without a text layer, docling may use its built-in OCR. If quality is poor, suggest the pdf-ocr skill for better preprocessing.


---
Source attribution: terminal-skills
Original project: https://github.com/TerminalSkills/skills/blob/8a9852d489f274538be9bf1c9121aeb403750b1c/skills/doc-parser/SKILL.md
License: Apache-2.0
License information: https://www.apache.org/licenses/LICENSE-2.0
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to the Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by the Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding any notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   Copyright 2025 Terminal Skills

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.



# Mega AI Hub resource metadata

Creator / publisher: terminal-skills
Original project: https://github.com/TerminalSkills/skills/blob/8a9852d489f274538be9bf1c9121aeb403750b1c/skills/doc-parser/SKILL.md
Attribution basis: Source repository record

Fields of work: Data & Analytics, Education & Research, Marketing, Product Management, Content & Media
Roles: Data Analyst, Researcher, Content Marketer, Product Manager, Technical Writer
Specialties: API, Backend
Tools: Docling
Country applicability: Country not specified
Classification basis: Source category, role and specialization labels
Instruction SHA-256: 2f0a0ac2bb4f7fb85128d2b3cfb22fa40a15c3108b29c8c8c272e8afe200315b
