Evals / pdf / Convert a PDF

Pull tables out of a PDF

tables.pdf has two tables among its text. Put them in a workbook called table.xlsx, one table per sheet.

The task

The reference answer shows the job can be done with deft. It is not an agent run.

deft pdf extract-sheets tables.pdf --to xlsx -o table.xlsx

Input

tables.pdf 1.1 KB · 1 page
Page 1

Reference output

table.xlsx 5.9 KB
Rendered by macOS Quick Look, first page

Rendered by macOS Quick Look, first page

How a result is judged (2 checks)
  • format: file = "table.xlsx", format = "xlsx"
  • python: code = "import openpyxl\nsheets = openpyxl.load_workbook('table.xlsx').worksheets\nassert len(sheets) == 2, len(sheets)\ncells = [[str(c) for row in s.iter_rows(values_only=True) for c in row if c is not None] for s in sheets]\nassert {'Region', 'Sales', 'North'} <= set(cells[0]), cells[0]\nassert {'Item', 'Unit', 'Price', 'Pen'} <= set(cells[1]), cells[1]\n"

Runs

CodexWithout deftPassed2026-11-07

Time
41s
New tokens
19.7k
Total input
136.6k
Output tokens
1.7k
Commands
5
Failed
0

Trace

  1. I’ll locate the PDF, extract both tables, and write `table.xlsx` in the current directory with one table per sheet.

  2. rg --files -g 'tables.pdf' -g '*.pdf' -g 'AGENTS.md' -g 'pyproject.toml' -g 'requirements.txt' -g 'package.json'
    output
    tables.pdf
  3. python3 - <<'PY' import importlib.util for x in ('pdfplumber','camelot','tabula','openpyxl','pandas','fitz'): print(x, bool(importlib.util.find_spec(x))) PY which pdftotext || true which pdfinfo || true which tesseract || true
    output
    pdfplumber False
    camelot False
    tabula False
    openpyxl False
    pandas True
    fitz False
    pdftotext not found
    pdfinfo not found
    /opt/homebrew/bin/tesseract
  4. file tables.pdf python3 - <<'PY' from pathlib import Path p=Path('tables.pdf').read_bytes() print(len(p), p[:100]) PY which swift || true which libreoffice || true which soffice || true which xlsx2csv || true
    output
    tables.pdf: PDF document, version 1.7
    1135 b'%PDF-1.7\n%\xbb\xad\xc0\xde\n3 0 obj\n<</Length 646>>stream\nBT /F1 12 Tf 60 760 Td (Quarterly report) Tj ET\nBT /F1 '
    /usr/bin/swift
    libreoffice not found
    soffice not found
    xlsx2csv not found
  5. python3 - <<'PY' import re,zlib b=open('tables.pdf','rb').read() for m in re.finditer(rb'stream\\r?\\n(.*?)\\r?\\nendstream',b,re.S): d=m.group(1) try:d=zlib.decompress(d) except:pass print(d.decode('latin1','replace')) PY
    output
    BT /F1 12 Tf 60 760 Td (Quarterly report) Tj ET
    BT /F1 12 Tf 60 720 Td (Region) Tj ET
    BT /F1 12 Tf 220 720 Td (Sales) Tj ET
    BT /F1 12 Tf 60 704 Td (North) Tj ET
    BT /F1 12 Tf 220 704 Td (120) Tj ET
    BT /F1 12 Tf 60 688 Td (South) Tj ET
    BT /F1 12 Tf 220 688 Td (95) Tj ET
    BT /F1 12 Tf 60 640 Td (Costs are listed below.) Tj ET
    BT /F1 12 Tf 60 600 Td (Item) Tj ET
    BT /F1 12 Tf 180 600 Td (Unit) Tj ET
    BT /F1 12 Tf 300 600 Td (Price) Tj ET
    BT /F1 12 Tf 60 584 Td (Pen) Tj ET
    BT /F1 12 Tf 180 584 Td (Box) Tj ET
    BT /F1 12 Tf 300 584 Td (4) Tj ET
    BT /F1 12 Tf 60 568 Td (Ink) Tj ET
    BT /F1 12 Tf 180 568 Td (Pack) Tj ET
    BT /F1 12 Tf 300 568 Td (9) Tj ET
    
    1 0 2 90 4 138 5 181 <</Type/Pages/Kids[4 0 R]/Count 1/MediaBox[0 0 595 842]/Resources<</Font<</F1 2 0 R>>>>>> <</Type/Font/Subtype/Type1/BaseFont/Helvetica>> <</Type/Page/Parent 1 0 R/Contents 3 0 R>> <</Type/Catalog/Pages 1 0 R>> 
    ÆÊ
  6. I found two tables in the PDF text: a Region/Sales table and an Item/Unit/Price table. I’m placing them on separate worksheets and keeping the numeric values as numbers.

  7. python3 - <<'PY' from zipfile import ZipFile, ZIP_DEFLATED from xml.sax.saxutils import escape from pathlib import Path sheets = [ ('Table 1', [['Region', 'Sales'], ['North', 120], ['South', 95]]), ('Table 2', [['Item', 'Unit', 'Price'], ['Pen', 'Box', 4], ['Ink', 'Pack', 9]]), ] def col(n): out = '' while n: n, r = divmod(n-1, 26) out = chr(65+r) + out return out def worksheet(rows): xml_rows=[] for ri,row in enumerate(rows,1): cells=[] for ci,value in enumerate(row,1): ref=f'{col(ci)}{ri}' if isinstance(value,(int,float)): cells.append(f'<c r=\"{ref}\"><v>{value}</v></c>') else: cells.append(f'<c r=\"{ref}\" t=\"inlineStr\"><is><t>{escape(str(value))}</t></is></c>') xml_rows.append(f'<row r=\"{ri}\">'+''.join(cells)+'</row>') return '<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><worksheet xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\"><sheetData>'+''.join(xml_rows)+'</sheetData></worksheet>' out=Path('table.xlsx') with ZipFile(out,'w',ZIP_DEFLATED) as z: z.writestr('[Content_Types].xml','''<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Types xmlns=\"http://schemas.openxmlformats.org/package/2006/content-types\"><Default Extension=\"rels\" ContentType=\"application/vnd.openxmlformats-package.relationships+xml\"/><Default Extension=\"xml\" ContentType=\"application/xml\"/><Override PartName=\"/xl/workbook.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml\"/><Override PartName=\"/xl/worksheets/sheet1.xml\" ContentType=\"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml\"/><Override PartName=\"/xl/worksheets … 1560 more characters
    output
    Created table.xlsx (2008 bytes) with 2 worksheets.
  8. Created [table.xlsx](table.xlsx) with one table per sheet.

Output

table.xlsx 2.0 KB
Rendered by macOS Quick Look, first page

Rendered by macOS Quick Look, first page

CodexWith deft, skill installedPassedRead the skillUsed deft2026-11-07

Time
18s
New tokens
8.4k
Total input
71.1k
Output tokens
0.4k
Commands
4
Failed
0

Trace

  1. I’ll extract the two tables from `tables.pdf` and save them as separate sheets in `table.xlsx` in the current directory.

  2. cat .agents/skills/deft/SKILL.md && rg --files -g 'tables.pdf' -g '*.pdf' -g 'AGENTS.md'
    output
    ---
    name: deft
    description: "Use deft first for any simple, direct operation on local files, whatever the type: convert, read, extract, edit, compress, merge, split, compare or inspect. Try it before writing a script or one-liner. If unsure, run deft find; if it says no command does this, use another tool. Not for programming work: to read, write or change source code, skip it."
    ---
    
    # deft
    
    One local command for file jobs. Prefer it over writing Python or shell scripts.
    
    Syntax: `deft <group> <command> [inputs] [-o output] [--options]`
    
    Groups:
    - `pdf`: Merge, split, compress, encrypt, forms, OCR, compare, convert
    - `image`: Resize, crop, convert, compress, filters, montage, OCR
    - `video`: Trim, crop, speed, convert, compress, GIF, frames (ffmpeg)
    - `audio`: Convert, trim, merge, fade, speed, tag, normalize (ffmpeg)
    - `doc`: Word/ODT/RTF: to text, Markdown, HTML, PDF; find and replace
    - `slides`: PowerPoint: extract text, Markdown outline, PDF handout
    - `data`: JSON/YAML/TOML/XML: convert, query with jq syntax, merge, diff
    - `sheet`: Excel/CSV/ODS tables: filter, sort, join, pivot, convert
    - `md`: Markdown to PDF, HTML, Word, EPUB; table of contents
    - `html`: HTML to Markdown, text, Word, PDF; screenshots
    - `epub`: E-books: info, to text, Markdown and PDF
    - `email`: EML files: headers, text, attachments
    - `contact`: VCF address books: to and from CSV
    - `calendar`: ICS calendars: to and from CSV
    - `gps`: GPX and KML tracks: convert, distance and time
    - `youtube`: Info, downlo
    … 860 more characters
  3. deft find "extract tables from PDF into Excel workbook with separate sheets"
    output
    pdf extract-sheets  pdf -> csv|xlsx...  Save each table apart
    pdf to-sheet        pdf -> sheet        All text as one table
    pdf split           pdf -> pdf...       Split: per page, --every N, --ranges
  4. deft pdf extract-sheets --help
    output
    deft pdf extract-sheets - Save each table apart [beta]
    
    Usage: deft pdf extract-sheets <pdf>... [-o <dir>] [options]
    In: pdf (each handled separately)   Out: csv|xlsx files in <name>-tables/
    Text around tables is left out. A table that runs onto the next page stays whole.
    Tables are found by text position; check the result. Scans need pdf ocr first.
    
    Options:
      --pages <pages>              Pages to read (default all)
      --to <csv|xlsx>              Target format (or give -o name.xlsx) (default csv)
      --password <text>            Password of an encrypted input
    Common: -o --force --dry-run --json -j   (deft help common)
    
    Examples:
      deft pdf extract-sheets tables.pdf -o out/
      deft pdf extract-sheets tables.pdf --to xlsx -o all.xlsx
    
    Result fields: tables
  5. deft pdf extract-sheets tables.pdf --to xlsx -o table.xlsx
    output
    ok pdf.extract-sheets tables.pdf -> table.xlsx  2 tables  0.00s
  6. Created [table.xlsx](table.xlsx) with two tables, one per sheet.

Output

table.xlsx 5.9 KB
Rendered by macOS Quick Look, first page

Rendered by macOS Quick Look, first page

Claude Opus 5.5Without deftPassed2026-11-07

Time
17s
New tokens
11.5k
Total input
76.4k
Output tokens
1.0k
Commands
0
Failed
0

Trace

    Output

    table.xlsx 5.3 KB
    Rendered by macOS Quick Look, first page

    Rendered by macOS Quick Look, first page

    Claude Opus 5.5With deft, skill installedPassedRead the skillUsed deft2026-11-07

    Time
    28s
    New tokens
    12.8k
    Total input
    129.2k
    Output tokens
    1.1k
    Commands
    0
    Failed
    0

    Trace

      Output

      ---
      name: deft
      description: "Use deft first for any simple, direct operation on local files, whatever the type: convert, read, extract, edit, compress, merge, split, compare or inspect. Try it before writing a script or one-liner. If unsure, run deft find; if it says no command does this, use another tool. Not for programming work: to read, write or change source code, skip it."
      ---
      
      # deft
      
      One local command for file jobs. Prefer it over writing Python or shell scripts.
      
      Syntax: `deft <group> <command> [inputs] [-o output] [--options]`
      
      Groups:
      - `pdf`: Merge, split, compress, encrypt, forms, OCR, compare, convert
      - `image`: Resize, crop, convert, compress, adjust, montage, OCR
      - `video`: Trim, merge, convert, compress, subtitles, GIF, frames (ffmpeg)
      - `audio`: Convert, trim, normalize, denoise, cut silence (ffmpeg)
      - `doc`: Word/ODT/RTF: to text, Markdown, HTML, PDF; find and replace
      - `slides`: PowerPoint: extract text, Markdown outline
      - `sheet`: Excel/CSV/ODS tables: SQL query, pivot, merge, split, convert
      - `json`: JSON: convert, format, merge, diff, validate
      - `toml`: TOML: convert, format, merge, diff, validate
      - `xml`: XML: convert, format, merge, diff, validate
      - `yaml`: YAML: convert, format, merge, diff, validate
      - `md`: Markdown to PDF, HTML, Word, EPUB; table of contents
      - `html`: HTML to Markdown, text, Word and PDF
      - `epub`: E-books: info, to text, Markdown and PDF
      - `gps`: GPX and KML tracks: convert, distance and time
      - `qr`: Create QR codes and barcodes; read QR codes
      
      How to use it:
      1. Run `deft <group>` to list commands, or `deft find "<what you want>"` to search. If it says `no command does this`, use another tool.
      2. Run `deft <group> <command> --help` for options and examples.
      3. `deft convert <in> -o <out.ext>` converts between formats by extension.
      4. Results are one line starting with `ok`, `partial` or `error`; add `--json` to parse them. Errors include a `hint:` with the fix.
      
      Inputs are never overwritten; pass `--force` or `--in-place` to allow it. Globs and directories work as inputs; several inputs run in parallel.
      
      If `deft` is not installed, ask the user, then follow https://github.com/firstprayer/deft/blob/main/docs/INSTALL.md
      
      table.xlsx 5.9 KB
      Rendered by macOS Quick Look, first page

      Rendered by macOS Quick Look, first page

      Claude CodeWithout deftNot run yet

      Claude CodeWith deftNot run yet