> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jinba.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Word Processing

> Advanced Word document processing and text highlighting

## Overview

Word Processing tools provide advanced capabilities for working with Microsoft Word documents (.docx). These tools enable content extraction, text highlighting, review comments, AI-powered document generation from templates, and document formatting with support for multiple languages including Japanese, Chinese, and other international character sets.

## Key Features

### WORD\_EXTRACT

* Extract text, tables, images, and comments (with replies) from .docx files in document order
* Returns a structured array of elements preserving the original document structure
* Table content is returned as a two-dimensional array of cell strings
* Supports Japanese and other languages

### WORD\_TEXT\_HIGHLIGHT

* Apply colored highlights to specific text in .docx files
* Support for multiple highlight colors
* International character encoding support
* Precise text matching and highlighting
* Preserve document formatting and structure

### WORD\_TEXT\_COMMENT

* Add review comments to specific text in .docx files
* Comments all occurrences of the target text by default, or only the Nth occurrence with the `index` option
* Custom author name for comments (default: `Jinbaflow`)
* Handles Japanese, Chinese, and other multilingual text natively

### WORD\_TEMPLATE\_GENERATE

* Generate a Word document based on a .dotx/.docx template
* An LLM analyzes the template's styles and structure, then creates content following the template's design rules according to your instructions
* Optionally incorporate structured data (e.g., table data, lists) into the generated document

## Authentication

No authentication is required for most Word processing tools. `WORD_TEMPLATE_GENERATE` uses an LLM and accepts an optional OpenAI API key via the `api_key` config; if omitted, it defaults to Jinba credits (`{{ secrets.JINBA_CREDIT_KEY }}`).

## Example: Extracting Document Content

`WORD_EXTRACT` takes a `file_url` pointing to a .docx file and returns a structured array of elements. Each element is one of:

* `{ "type": "text", "content": "..." }`
* `{ "type": "table", "content": [["cell", ...], ...] }`
* `{ "type": "image", "name": "..." }`
* `{ "type": "comment", "content": "...", "author": "...", "date": "...", "target": N, "replies": [...] }`

```yaml theme={null}
- id: upload_document
  name: upload_document
  tool: INPUT_FILE
  input:
    - name: description
      value: "Upload Word document to extract content from"

- id: extract_content
  name: extract_content
  tool: WORD_EXTRACT
  input:
    - name: file_url
      value: "{{steps.upload_document.result.file_url}}"
```

## Example: Adding Review Comments

`WORD_TEXT_COMMENT` takes a `file_url`, an `items` map of target text to comment, and an optional `author` name. Each item value is `{ "comment": "...", "index": N }` where the optional 1-based `index` targets the Nth occurrence; omit it to comment all occurrences. The output `result` is the URL of the commented .docx file.

```yaml theme={null}
- id: add_review_comments
  name: add_review_comments
  tool: WORD_TEXT_COMMENT
  input:
    - name: file_url
      value: "{{steps.upload_document.result.file_url}}"
    - name: items
      value: |
        {
          "quarterly revenue": { "comment": "Please double-check this figure." },
          "deadline": { "comment": "Confirm with the PM.", "index": 2 }
        }
    - name: author
      value: "Legal Review Bot"
```

## Example: Generating a Document from a Template

`WORD_TEMPLATE_GENERATE` takes a `template_url` (.dotx or .docx), `instructions` describing what content to create, and optional structured `data` (e.g., table data, lists) to incorporate. The output is `result.url`, the URL of the generated document.

```yaml theme={null}
- id: upload_template
  name: upload_template
  tool: INPUT_FILE
  input:
    - name: description
      value: "Upload a Word template (.dotx or .docx)"

- id: generate_document
  name: generate_document
  tool: WORD_TEMPLATE_GENERATE
  input:
    - name: template_url
      value: "{{steps.upload_template.result.file_url}}"
    - name: instructions
      value: |
        Create a project proposal for the new customer portal,
        including an executive summary, milestones, and a budget section.
    - name: data
      value: |
        {
          "milestones": [
            { "name": "Design", "due": "2026-08-01" },
            { "name": "Implementation", "due": "2026-09-15" }
          ]
        }
```

## Example: Document Review and Highlighting

`WORD_TEXT_HIGHLIGHT` takes a `file_url` and a `highlights` array where each item is `{ "text": "...", "color": "..." }`. Text matching is case-insensitive substring matching across paragraphs and table cells. The output `result` is the signed URL of the highlighted .docx file, which downstream steps can reference as `{{steps.highlight_key_terms.result}}`.

```yaml theme={null}
- id: upload_document
  name: upload_document
  tool: INPUT_FILE
  input:
    - name: description
      value: "Upload Word document for review and highlighting"

- id: highlight_key_terms
  name: highlight_key_terms
  tool: WORD_TEXT_HIGHLIGHT
  input:
    - name: file_url
      value: "{{steps.upload_document.result.file_url}}"
    - name: highlights
      value: |
        [
          {
            "text": "important",
            "color": "YELLOW"
          },
          {
            "text": "urgent",
            "color": "RED"
          },
          {
            "text": "deadline",
            "color": "PINK"
          },
          {
            "text": "action required",
            "color": "GREEN"
          }
        ]
```

## Example: Contract Review Workflow

```yaml theme={null}
- id: input_contract
  name: input_contract
  tool: INPUT_FILE
  input:
    - name: description
      value: "Upload contract document for legal review"

- id: extract_contract_text
  name: extract_contract_text
  tool: WORD_EXTRACT
  input:
    - name: file_url
      value: "{{steps.input_contract.result.file_url}}"

- id: identify_key_clauses
  name: identify_key_clauses
  tool: OPENAI_INVOKE
  config:
    - name: version
      value: gpt-4
  input:
    - name: prompt
      value: |
        Analyze this contract and identify key clauses that should be highlighted:
        
        {{steps.extract_contract_text.result}}
        
        Please identify and return:
        1. Critical terms that need immediate attention (RED highlights)
        2. Important financial terms (YELLOW highlights)
        3. Deadlines and dates (PINK highlights)
        4. Termination clauses (BLUE highlights)
        5. Liability limitations (GREEN highlights)
        
        Return as JSON array with text, color, and importance level.

- id: apply_legal_highlights
  name: apply_legal_highlights
  tool: PYTHON_SANDBOX_RUN
  input:
    - name: code
      value: |
        import json
        import re
        
        # Parse AI recommendations
        ai_response = """{{steps.identify_key_clauses.result.content}}"""
        
        # Define standard legal term highlights
        legal_highlights = [
            {"text": "termination", "color": "BLUE"},
            {"text": "liability", "color": "GREEN"},
            {"text": "indemnification", "color": "GREEN"},
            {"text": "breach", "color": "RED"},
            {"text": "default", "color": "RED"},
            {"text": "payment", "color": "YELLOW"},
            {"text": "due date", "color": "PINK"},
            {"text": "force majeure", "color": "VIOLET"},
            {"text": "confidential", "color": "TURQUOISE"},
            {"text": "intellectual property", "color": "DARK_BLUE"}
        ]
        
        print(json.dumps(legal_highlights, indent=2))

- id: highlight_contract_terms
  name: highlight_contract_terms
  tool: WORD_TEXT_HIGHLIGHT
  input:
    - name: file_url
      value: "{{steps.input_contract.result.file_url}}"
    - name: highlights
      value: "{{steps.apply_legal_highlights.result.stdout}}"

- id: create_review_summary
  name: create_review_summary
  tool: OUTPUT_FILE
  input:
    - name: content
      value: |
        Contract Review Summary
        ======================
        
        Document: {{steps.input_contract.input.description}}
        Review Date: {{date | format('YYYY-MM-DD HH:mm:ss')}}
        
        Highlighting Legend:
        - RED: Critical terms requiring immediate attention
        - YELLOW: Financial terms and payment obligations  
        - PINK: Deadlines and important dates
        - BLUE: Termination and ending clauses
        - GREEN: Liability and indemnification terms
        - VIOLET: Force majeure and exceptional circumstances
        - TURQUOISE: Confidentiality and privacy terms
        - DARK_BLUE: Intellectual property clauses
        
        Key Findings:
        {{steps.identify_key_clauses.result.content}}
        
        Recommendations:
        1. Review all RED highlighted terms with legal counsel
        2. Verify all PINK highlighted dates are accurate
        3. Ensure YELLOW highlighted financial terms are acceptable
        4. Confirm BLUE highlighted termination conditions
        
        Next Steps:
        - Legal team review required
        - Stakeholder approval needed
        - Client signature pending
    - name: filename
      value: "contract_review_summary_{{date | format('YYYY-MM-DD')}}.txt"
    - name: fileType
      value: "txt"
```

## Example: Multi-language Document Processing

```yaml theme={null}
- id: upload_multilingual_doc
  name: upload_multilingual_doc
  tool: INPUT_FILE
  input:
    - name: description
      value: "Upload document with Japanese/Chinese text"

- id: highlight_multilingual_terms
  name: highlight_multilingual_terms
  tool: WORD_TEXT_HIGHLIGHT
  input:
    - name: file_url
      value: "{{steps.upload_multilingual_doc.result.file_url}}"
    - name: highlights
      value: |
        [
          {
            "text": "重要",
            "color": "RED"
          },
          {
            "text": "緊急",
            "color": "PINK"
          },
          {
            "text": "注意",
            "color": "YELLOW"
          },
          {
            "text": "截止日期",
            "color": "PINK"
          }
        ]

- id: process_highlighted_content
  name: process_highlighted_content
  tool: GEMINI_INVOKE_WITH_FILE
  config:
    - name: version
      value: gemini-1.5-flash
    - name: token
      value: "{{secrets.GEMINI_API_KEY}}"
  input:
    - name: prompt
      value: |
        Please analyze this highlighted multilingual document and:
        1. Identify all highlighted text sections
        2. Provide English translations for highlighted terms
        3. Summarize the key points by highlight color
        4. Note any critical information that requires attention
    - name: file_url
      value: "{{steps.highlight_multilingual_terms.result}}"
```

## Example: Educational Content Highlighting

```yaml theme={null}
- id: upload_study_material
  name: upload_study_material
  tool: INPUT_FILE
  input:
    - name: description
      value: "Upload educational document for highlighting"

- id: extract_text
  name: extract_text
  tool: WORD_EXTRACT
  input:
    - name: file_url
      value: "{{steps.upload_study_material.result.file_url}}"

- id: identify_study_points
  name: identify_study_points
  tool: OPENAI_INVOKE
  config:
    - name: version
      value: gpt-4
  input:
    - name: prompt
      value: |
        Analyze this educational content and categorize text for highlighting:
        
        {{steps.extract_text.result}}
        
        Categories:
        1. Key concepts and definitions (YELLOW)
        2. Important formulas or equations (GREEN) 
        3. Critical facts and dates (BLUE)
        4. Examples and case studies (VIOLET)
        5. Warning or caution notes (RED)
        
        Return specific text phrases to highlight in each category.

- id: create_study_highlights
  name: create_study_highlights
  tool: PYTHON_SANDBOX_RUN
  input:
    - name: code
      value: |
        # Create educational highlight scheme
        study_highlights = [
            # Key terms and definitions
            {"text": "definition", "color": "YELLOW"},
            {"text": "theorem", "color": "YELLOW"},
            {"text": "principle", "color": "YELLOW"},
            
            # Formulas and equations
            {"text": "formula", "color": "GREEN"},
            {"text": "equation", "color": "GREEN"},
            {"text": "calculate", "color": "GREEN"},
            
            # Important facts
            {"text": "important", "color": "BLUE"},
            {"text": "note that", "color": "BLUE"},
            {"text": "remember", "color": "BLUE"},
            
            # Examples
            {"text": "example", "color": "VIOLET"},
            {"text": "case study", "color": "VIOLET"},
            {"text": "for instance", "color": "VIOLET"},
            
            # Warnings and cautions
            {"text": "warning", "color": "RED"},
            {"text": "caution", "color": "RED"},
            {"text": "avoid", "color": "RED"}
        ]
        
        import json
        print(json.dumps(study_highlights, indent=2))

- id: apply_study_highlights
  name: apply_study_highlights
  tool: WORD_TEXT_HIGHLIGHT
  input:
    - name: file_url
      value: "{{steps.upload_study_material.result.file_url}}"
    - name: highlights
      value: "{{steps.create_study_highlights.result.stdout}}"

- id: create_study_guide
  name: create_study_guide
  tool: OUTPUT_FILE
  input:
    - name: content
      value: |
        Study Guide - Highlighting Legend
        ================================
        
        Color Coding System:
        
        🟡 YELLOW - Key Concepts & Definitions
        - Fundamental terms and concepts
        - Important definitions to memorize
        - Core principles and theories
        
        🟢 GREEN - Formulas & Equations  
        - Mathematical formulas
        - Calculation methods
        - Problem-solving approaches
        
        🔵 BLUE - Critical Facts & Information
        - Important facts to remember
        - Key points for exams
        - Essential knowledge items
        
        🟣 VIOLET - Examples & Case Studies
        - Practical examples
        - Real-world applications
        - Case study references
        
        🔴 RED - Warnings & Cautions
        - Common mistakes to avoid
        - Important warnings
        - Critical safety information
        
        Study Tips:
        1. Focus on YELLOW highlighted definitions first
        2. Practice GREEN highlighted formulas
        3. Memorize BLUE highlighted facts
        4. Review VIOLET highlighted examples
        5. Pay special attention to RED highlighted warnings
        
        Document processed: {{date | format('YYYY-MM-DD HH:mm:ss')}}
    - name: filename
      value: "study_guide_{{date | format('YYYY-MM-DD')}}.txt"
    - name: fileType
      value: "txt"
```

## Highlight Color Options

The `color` value must be one of the following python-docx highlight colors (uppercase). If omitted, it defaults to `YELLOW`.

| Color         | RGB Code | Use Case                               |
| ------------- | -------- | -------------------------------------- |
| YELLOW        | #FFFF00  | Key concepts, definitions              |
| BRIGHT\_GREEN | #00FF00  | Formulas, calculations                 |
| TURQUOISE     | #00FFFF  | Notes, references                      |
| PINK          | #FF00FF  | Deadlines, urgent items                |
| BLUE          | #0000FF  | Important facts, dates                 |
| RED           | #FF0000  | Critical items, warnings               |
| DARK\_BLUE    | #000080  | Intellectual property, special clauses |
| TEAL          | #008080  | Secondary references                   |
| GREEN         | #008000  | Liability, approved items              |
| VIOLET        | #800080  | Examples, case studies                 |

## Use Cases

* **Document Review**: Legal contracts, technical specifications
* **Educational Materials**: Textbooks, study guides, training materials
* **Content Categorization**: Organize information by importance
* **Quality Assurance**: Highlight issues, corrections, improvements
* **Collaboration**: Mark sections for team review
* **Compliance**: Highlight regulatory requirements
* **Translation**: Mark text for translation or localization
* **Research**: Categorize findings and key insights

## Best Practices

### Highlight Strategy

* Use consistent color coding across documents
* Create highlight legends for team collaboration
* Limit colors to avoid visual confusion
* Test highlighting on sample text first

### International Support

* Verify encoding compatibility for non-Latin characters
* Test with multilingual content before bulk processing
* Consider right-to-left text direction for Arabic/Hebrew
* Use Unicode-compatible text matching

### Performance Optimization

* Process large documents in sections
* Use specific text matching to reduce processing time
* Batch similar highlighting operations
* Monitor file size after highlighting
