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

pdf-read-file-fallback

하는 일

이 스킬은 내장 리더가 이미지나 바이너리 데이터로 반환하는 PDF의 예비 방법입니다. AI가 일반적으로 읽지 못하는 PDF 속 단어가 필요한 사람에게 맞습니다.

사용하는 경우

  • ✓PDF를 읽을 때 텍스트 대신 이미지나 바이너리 데이터가 나올 때.
  • ✓PDF가 스캔 문서이거나 복잡한 서식이 있는 경우.
  • ✓읽을 수 있는 형태의 PDF 텍스트가 필요할 때.

스킬 링크

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

AI에게 요청하는 예시

“AI가 제 PDF에서 바이너리 데이터만 가져옵니다. 명령줄 도구로 텍스트를 꺼내 주세요.”

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

작동 방식

AI는 먼저 일반 파일 읽기를 시도하고 결과가 쓸 만한지 확인합니다. 쓸 수 없으면 layout 옵션을 붙여 pdftotext를 실행해 텍스트를 얻습니다.

기술 내용 (원본 SKILL.md)

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

PDF Text Extraction Fallback

When to Use

Use this pattern when read_file with filetype="pdf" returns binary image data instead of extractable text content. This commonly occurs with PDFs that contain scanned images or complex formatting.

Steps

1. Attempt Primary Extraction

First, try using read_file:

result = read_file(file_path="document.pdf", filetype="pdf")

Important: Use filetype (not file_type) - incorrect parameter naming will cause execution failures.

2. Detect Binary/Image Data

Check if the result contains unusable content:

# Indicators of binary/image data:
# - Contains null bytes: '\x00'
# - Very short or empty
# - Contains image markers (PNG/JPEG headers)
# - Unreadable character sequences

if not result or len(result) < 50 or '\x00' in str(result):
    # Proceed to fallback

3. Use pdftotext via run_shell

Extract text using the pdftotext command-line tool:

shell_result = run_shell(command="pdftotext -layout document.pdf -")
text_content = shell_result.stdout

The - flag outputs to stdout for easy capture. The -layout flag preserves original formatting.

4. Handle pdftotext Unavailable

If pdftotext is not installed, try Python-based extraction:

result = execute_code_sandbox(code="""
import pdfplumber
text = ''
with pdfplumber.open('document.pdf') as pdf:
    for page in pdf.pages:
        extracted = page.extract_text()
        if extracted:
            text += extracted + '\\n'
print(text)
""")

Complete Example

file_path = "report.pdf"

# Primary attempt
result = read_file(file_path=file_path, filetype="pdf")

# Validate and fallback if needed
if not result or len(str(result)) < 100 or '\x00' in str(result):
    # Fallback to pdftotext
    shell_result = run_shell(command=f"pdftotext -layout {file_path} -")
    text_content = shell_result.stdout
    
    # If pdftotext fails, try Python extraction
    if not text_content or len(text_content) < 50:
        code_result = execute_code_sandbox(code=f"""
import pdfplumber
text = ''
with pdfplumber.open('{file_path}') as pdf:
    for page in pdf.pages:
        extracted = page.extract_text()
        if extracted:
            text += extracted + '\\n'
print(text)
""")
        text_content = code_result

Notes

  • pdftotext is part of the poppler-utils package on most Linux systems
  • For scanned/image-only PDFs, consider OCR tools (tesseract) instead
  • Always validate parameter names against tool documentation (filetype vs file_type)
자주 묻는 질문

layout 옵션은 무엇을 하나요?

가능한 한 원래 페이지의 간격과 구조를 유지합니다.

pdftotext가 없으면 어떻게 하나요?

가이드는 pdfplumber 같은 Python 라이브러리를 대체 수단으로 제안합니다.

바이너리 출력은 어떻게 알아보나요?

가이드는 null 바이트, 아주 짧은 결과, 이미지 헤더 같은 신호를 언급합니다.

상세 정보

작성자의 원본 설명

Extract text from PDFs using pdftotext when read_file returns binary data

repo: HKUDS/AgentPilot

인기도

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

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬