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

pdf-text-extraction-9424c5

하는 일

이 스킬은 일반 리더가 실패할 때 pdftotext로 PDF에서 읽을 수 있는 텍스트를 추출하는 방법을 설명합니다. AI가 직접 읽지 못하는 PDF 문서를 다루는 사람에게 맞습니다.

사용하는 경우

  • ✓PDF 읽기에서 깨지거나 바이너리 내용이 나올 때.
  • ✓PDF에 스캔 이미지나 복잡한 바이너리 구조가 있는 경우.
  • ✓PDF 텍스트를 파일로 저장하거나 나중 단계에 쓰고 싶을 때.

스킬 링크

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

AI에게 요청하는 예시

“제 document.pdf의 텍스트를 읽어 주세요. 일반 리더는 깨진 결과를 주니 pdftotext로 추출해 주세요.”

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

작동 방식

AI는 파일이 있는지 확인하고, pdftotext를 실행해 텍스트를 얻은 뒤, 바로 쓰거나 필요하면 임시 텍스트 파일로 저장합니다.

기술 내용 (원본 SKILL.md)

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

PDF Text Extraction via pdftotext

Problem

When using read_file on PDF documents, the function may return binary image data or garbled content instead of readable text. This occurs because PDFs can contain scanned images or complex binary structures that read_file cannot properly parse as text.

Solution

Use the pdftotext command-line utility via run_shell to extract clean text content from PDF files.

Steps

1. Verify PDF file exists

import os

pdf_path = "path/to/document.pdf"
if not os.path.exists(pdf_path):
    raise FileNotFoundError(f"PDF not found: {pdf_path}")

2. Extract text using pdftotext

from tools import run_shell

# Extract text to stdout
result = run_shell(command=f"pdftotext '{pdf_path}' -", timeout=60)
pdf_text = result.stdout

# Alternative: extract to a temporary file
temp_txt = "/tmp/extracted.txt"
run_shell(command=f"pdftotext '{pdf_path}' '{temp_txt}'", timeout=60)
with open(temp_txt, 'r') as f:
    pdf_text = f.read()

3. Handle parameter naming carefully

When calling read_file, be aware of the parameter name:

  • Use filetype="pdf" (not file_type)
  • Some tool implementations may use different parameter names
# Correct parameter usage
content = read_file(file_path="doc.pdf", filetype="pdf")

# If this returns binary/garbled data, fall back to pdftotext

Common pdftotext Options

Option Description
- Output to stdout
-layout Maintain original layout
-f <n> Start from page n
-l <n> End at page n
-q Quiet mode

Example with options:

result = run_shell(command=f"pdftotext -layout -q '{pdf_path}' -", timeout=60)

Error Handling

from tools import run_shell

def extract_pdf_text(pdf_path):
    """Extract text from PDF using pdftotext with error handling."""
    import os
    
    if not os.path.exists(pdf_path):
        raise FileNotFoundError(f"PDF not found: {pdf_path}")
    
    result = run_shell(command=f"pdftotext '{pdf_path}' -", timeout=60)
    
    if result.returncode != 0:
        raise RuntimeError(f"pdftotext failed: {result.stderr}")
    
    return result.stdout.strip()

When to Use This Pattern

  • read_file returns binary data, garbled text, or image content for a PDF
  • You need searchable/processable text from PDF documents
  • The PDF contains text (not just scanned images - for those, consider OCR tools)

Prerequisites

  • pdftotext must be installed (part of poppler-utils on Debian/Ubuntu, poppler on macOS via Homebrew)
  • Verify availability: run_shell(command="which pdftotext")
자주 묻는 질문

파일이 있는지 먼저 확인하는 이유는 무엇인가요?

PDF 경로가 틀리면 가이드는 분명한 오류와 함께 멈춥니다.

read_file 매개변수 팁은 무엇인가요?

읽기 도구를 호출할 때 file_type 대신 filetype을 쓰라고 가이드가 안내합니다.

출력은 어디로 갈 수 있나요?

화면에 출력하거나 텍스트 파일에 쓸 수 있습니다.

상세 정보

작성자의 원본 설명

Extract text from PDF files using pdftotext when read_file returns binary data

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬