Skill: neckr0ik/document-handler (version 1.0.0)

--- name: document-handler description: Read, extract, and convert document files (PDF, DOCX, XLSX, PPTX, EPUB, RTF, ODT, ODS, ODP). Use when working with any document format: extracting text, metadata, converting formats, or processing content. Triggers on mentions of document files, file paths with document extensions, or requests to read/convert documents. --- # Document Handler Extract text, metadata, and content from any document format. ## Supported Formats | Format | Extensions | Text Extract | Metadata | Convert | |--------|------------|--------------|----------|---------| | PDF | .pdf | ✅ pdftotext | ✅ pdfinfo | ✅ pdftoppm | | Word | .docx | ✅ unzip + xml | ✅ | ✅ | | Excel | .xlsx | ✅ unzip + xml | ✅ | ✅ | | PowerPoint | .pptx | ✅ unzip + xml | ✅ | ✅ | | EPUB | .epub | ✅ unzip + html | ✅ | ✅ | | RTF | .rtf | ✅ textutil | ✅ | ✅ | | OpenDocument | .odt, .ods, .odp | ✅ unzip + xml | ✅ | ✅ | ## Quick Commands ### PDF ```bash # Extract text pdftotext -layout input.pdf output.txt # Get metadata pdfinfo input.pdf # Convert to images (for OCR or viewing) pdftoppm -png input.pdf output_prefix # Extract specific pages pdftotext -f 5 -l 10 -layout input.pdf output.txt ``` ### DOCX/XLSX/PPTX (Office Open XML) ```bash # Extract text from DOCX unzip -p input.docx word/document.xml | sed 's/<[^>]*>//g' | tr -s ' \n' # Extract text from XLSX (all sheets) unzip -p input.xlsx xl/sharedStrings.xml | sed 's/<[^>]*>//g' | tr -s '\n' # Extract text from PPTX unzip -p input.pptx ppt/slides/*.xml | sed 's/<[^>]*>//g' | tr -s ' \n' # Get metadata unzip -p input.docx docProps/core.xml ``` ### RTF (macOS) ```bash # Convert RTF to plain text textutil -convert txt input.rtf -output output.txt # Convert RTF to HTML textutil -convert html input.rtf -output output.html ``` ### EPUB ```bash # Extract and read EPUB content unzip -l input.epub # List contents unzip -p input.epub "*.html" | lynx -stdin -dump # Text via lynx unzip -p input.epub "*.xhtml" | sed 's/<[^>]*>//g' # Raw text ``` ### OpenDocument (ODT/ODS/ODP) ```bash # Extract text from ODT unzip -p input.odt content.xml | sed 's/<[^>]*>//g' | tr -s ' \n' # Extract from ODS unzip -p input.ods content.xml | sed 's/<[^>]*>//g' # Get metadata unzip -p input.odt meta.xml ``` ## Scripts ### extract_document.sh Extracts text and metadata from any supported document format. ```bash ~/Dropbox/jarvis/skills/document-handler/scripts/extract_document.sh <file> ``` Output: - Text content to stdout - Metadata as JSON comments ### pdf_to_images.sh Converts PDF pages to images for OCR or visual processing. ```bash ~/Dropbox/jarvis/skills/document-handler/scripts/pdf_to_images.sh <pdf> <output_dir> [dpi] ``` ## Workflow 1. **Identify format** — Check file extension 2. **Extract text** — Use appropriate tool 3. **Get metadata** — Author, date, pages, etc. 4. **Process content** — Summarize, search, transform ## Notes - PDFs with scanned images need OCR (pdftoppm + tesseract) - Encrypted PDFs require password - Complex formatting may be lost in text extraction - For tables in PDFs, consider tabula or camelot

path: scripts/extract_document.sh
content: #!/bin/bash
# Extract text and metadata from any supported document format

set -e

if [[ $# -lt 1 ]]; then
    echo "Usage: $0 <file> [--metadata-only]"
    exit 1
fi

FILE="$1"
META_ONLY="${2:-}"

if [[ ! -f "$FILE" ]]; then
    echo "Error: File not found: $FILE" >&2
    exit 1
fi

EXT="${FILE##*.}"
EXT="${EXT,,}"  # lowercase

extract_metadata() {
    case "$EXT" in
        pdf)
            pdfinfo "$FILE" 2>/dev/null || echo "Could not extract PDF metadata"
            ;;
        docx|xlsx|pptx)
            echo "=== Office Document Metadata ==="
            unzip -p "$FILE" docProps/core.xml 2>/dev/null | sed 's/<[^>]*>/\n/g' | grep -v '^$' || echo "No metadata found"
            ;;
        odt|ods|odp)
            echo "=== OpenDocument Metadata ==="
            unzip -p "$FILE" meta.xml 2>/dev/null | sed 's/<[^>]*>/\n/g' | grep -v '^$' || echo "No metadata found"
            ;;
        epub)
            echo "=== EPUB Metadata ==="
            unzip -p "$FILE" "*.opf" 2>/dev/null | sed 's/<[^>]*>/\n/g' | grep -v '^$' | head -20 || echo "No metadata found"
            ;;
        rtf)
            echo "RTF metadata extraction not supported"
            ;;
        *)
            echo "Unknown format: $EXT"
            ;;
    esac
}

extract_text() {
    case "$EXT" in
        pdf)
            pdftotext -layout "$FILE" - 2>/dev/null || echo "Could not extract PDF text"
            ;;
        docx)
            unzip -p "$FILE" word/document.xml 2>/dev/null | sed 's/<[^>]*>//g' | tr -s ' \n' | sed 's/^ *//;s/ *$//' || echo "Could not extract DOCX text"
            ;;
        xlsx)
            echo "=== Excel Content ==="
            unzip -p "$FILE" xl/sharedStrings.xml 2>/dev/null | sed 's/<[^>]*>//g' | grep -v '^$' || echo "Could not extract XLSX text"
            ;;
        pptx)
            echo "=== PowerPoint Content ==="
            unzip -p "$FILE" ppt/slides/slide*.xml 2>/dev/null | sed 's/<[^>]*>//g' | tr -s ' \n' | grep -v '^$' || echo "Could not extract PPTX text"
            ;;
        odt)
            unzip -p "$FILE" content.xml 2>/dev/null | sed 's/<[^>]*>//g' | tr -s ' \n' || echo "Could not extract ODT text"
            ;;
        ods)
            unzip -p "$FILE" content.xml 2>/dev/null | sed 's/<[^>]*>//g' | tr -s ' \n' || echo "Could not extract ODS text"
            ;;
        odp)
            unzip -p "$FILE" content.xml 2>/dev/null | sed 's/<[^>]*>//g' | tr -s ' \n' || echo "Could not extract ODP text"
            ;;
        epub)
            # Find and extract HTML content
            for html in $(unzip -l "$FILE" | grep -E '\.(html|x?html)$' | awk '{print $4}' | head -20); do
                unzip -p "$FILE" "$html" 2>/dev/null | sed 's/<[^>]*>//g' | tr -s ' \n'
            done
            ;;
        rtf)
            textutil -convert txt -stdout "$FILE" 2>/dev/null || echo "Could not extract RTF text"
            ;;
        *)
            echo "Unknown format: $EXT"
            ;;
    esac
}

if [[ "$META_ONLY" == "--metadata-only" ]]; then
    extract_metadata
else
    echo "=== File: $FILE ==="
    echo ""
    extract_metadata
    echo ""
    echo "=== Content ==="
    extract_text
fi

path: scripts/pdf_to_images.sh
content: #!/bin/bash
# Convert PDF pages to images

set -e

if [[ $# -lt 2 ]]; then
    echo "Usage: $0 <pdf> <output_dir> [dpi=150]"
    exit 1
fi

PDF="$1"
OUTPUT_DIR="$2"
DPI="${3:-150}"

if [[ ! -f "$PDF" ]]; then
    echo "Error: PDF not found: $PDF" >&2
    exit 1
fi

mkdir -p "$OUTPUT_DIR"

BASENAME=$(basename "$PDF" .pdf)

echo "Converting $PDF to images at ${DPI} DPI..."

pdftoppm -png -r "$DPI" "$PDF" "${OUTPUT_DIR}/${BASENAME}"

echo "Done! Images saved to: $OUTPUT_DIR"
ls -la "$OUTPUT_DIR"

Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)