본문으로 건너뛰기
Skillpedia
PDF, Word, 슬라이드7.8k · #12967

reliable-pdf-extraction-ac5f89

하는 일

이 스킬은 명령줄 도구나 Python 라이브러리로 PDF의 텍스트를 뽑는 방법을 AI 에이전트에게 보여 줍니다. 엉망인 결과가 아니라 PDF의 단어가 필요한 사람에게 맞습니다.

사용하는 경우

  • ✓파일 읽기 도구가 PDF에 대해 바이너리 이미지 데이터나 깨진 문자를 반환할 때.
  • ✓PDF의 텍스트나 표를 깨끗한 형태로 얻어야 할 때.
  • ✓추출 전에 PDF의 페이지 수나 메타데이터를 확인하고 싶은 경우.

스킬 링크

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/reliable-pdf-extraction-ac5f89/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/reliable-pdf-extraction-ac5f89/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“계약서 PDF의 텍스트를 꺼내서 읽을 수 있게 해 주세요. 일반 리더가 깨진 문자를 반환합니다.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

에이전트는 PDF가 있는지 확인하고 세부 정보를 읽은 뒤, pdftotext를 실행해 텍스트를 저장합니다. 필요하면 PyMuPDF나 pdfplumber 같은 Python 라이브러리를 쓰는데, pdfplumber는 표도 읽을 수 있습니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Reliable PDF Text Extraction

Problem

The read_file tool with filetype='pdf' can be unreliable for PDF text extraction. It may:

  • Return binary image data instead of text
  • Fail with errors on certain PDF structures
  • Lose formatting or structured content

Solution

Use run_shell with dedicated PDF extraction tools instead of relying on read_file for PDFs.

Methods

Method 1: pdftotext (Recommended)

pdftotext input.pdf output.txt

Or to extract to stdout:

pdftotext input.pdf -

With layout preservation:

pdftotext -layout input.pdf output.txt

Method 2: pdfinfo (Metadata)

pdfinfo input.pdf

Useful for checking page count, dimensions, and PDF properties before extraction.

Method 3: Python with PyMuPDF (fitz)

import fitz  # PyMuPDF

doc = fitz.open("input.pdf")
text = ""
for page in doc:
    text += page.get_text()
doc.close()

Method 4: Python with pdfplumber (Tables)

import pdfplumber

with pdfplumber.open("input.pdf") as pdf:
    for page in pdf.pages:
        text = page.extract_text()
        tables = page.extract_tables()

Workflow

  1. Check PDF exists and is readable:

    pdfinfo input.pdf 2>/dev/null || echo "PDF not accessible"
    
  2. Extract text using pdftotext:

    pdftotext -layout input.pdf - > extracted_text.txt
    
  3. If pdftotext fails, try Python fallback:

    import fitz
    doc = fitz.open("input.pdf")
    for i, page in enumerate(doc):
        print(f"--- Page {i+1} ---")
        print(page.get_text())
    doc.close()
    
  4. Verify extraction succeeded:

    • Check output is non-empty
    • Verify text is readable (not binary/garbled)
    • Confirm expected content is present

When to Use

Tool Best For
pdftotext Fast, simple text extraction
pdftotext -layout Preserving spacing/formatting
PyMuPDF Complex PDFs, programmatic access
pdfplumber Tables and structured data

Example Integration

# In your agent workflow, prefer this pattern:
result = run_shell(command="pdftotext document.pdf -", timeout=30)
if result.stdout and len(result.stdout.strip()) > 0:
    content = result.stdout
else:
    # Fallback to Python
    content = execute_python_to_extract_pdf("document.pdf")

Notes

  • Install tools if needed: apt-get install poppler-utils (for pdftotext/pdfinfo)
  • Python libraries: pip install pymupdf pdfplumber
  • Some PDFs are image-scanned and require OCR (Tesseract) instead
  • Always validate extracted content before proceeding with downstream tasks
자주 묻는 질문

pdftotext는 무엇인가요?

PDF의 텍스트를 일반 텍스트 파일로 바꾸는 명령줄 도구입니다.

표도 읽을 수 있나요?

스킬은 표와 구조화된 데이터에는 pdfplumber가 더 낫다고 말합니다.

PDF가 스캔본이면 어떻게 하나요?

이 스킬은 텍스트 추출 방법을 나열하며, 스캔된 페이지는 별도의 OCR 단계가 필요할 수 있습니다.

상세 정보

작성자의 원본 설명

Extract PDF text content using shell tools or Python libraries when read_file PDF handler fails

repo: HKUDS/AgentPilot

인기도

GitHub 스타
7.8k
순위
#12967
라이선스
MIT
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬