--- name: pdf-processor label: PDF 처리 description: Python을 사용하여 PDF에서 텍스트/표를 추출하거나 PDF를 생성합니다. icon: \uE9F9 allowed-tools: - folder_map - document_read - file_read - file_write - process - format_convert tabs: cowork --- PDF 파일을 읽거나 새 PDF를 생성하세요. ## 실행 경로 선택 (Python 가능/불가) - 먼저 `process`로 `python --version`을 확인하세요. - Python 가능: 기존 pypdf/pdfplumber/reportlab 경로를 사용하세요. - Python 불가: `document_read`로 텍스트/구조를 추출하고, 생성 작업은 `format_convert` + `file_write` 기반으로 대체하세요. ## 사전 준비 필요한 패키지를 확인하고 설치하세요: ``` process: pip install pypdf pdfplumber reportlab ``` ## 작업 절차 ### PDF 텍스트 추출 1. **파일 확인**: folder_map으로 PDF 파일 위치 확인 2. **추출 스크립트 작성**: file_write로 Python 스크립트 생성 3. **실행**: `process`로 실행 4. **결과 전달**: 추출된 텍스트를 사용자에게 전달 ### PDF 생성 1. **내용 파악**: 사용자가 원하는 문서 내용 확인 2. **생성 스크립트 작성**: file_write로 Python 스크립트 생성 3. **실행 및 확인**: `process`로 실행 ## 텍스트 추출 템플릿 ```python import pdfplumber import json results = [] with pdfplumber.open('input.pdf') as pdf: for i, page in enumerate(pdf.pages): text = page.extract_text() or '' tables = page.extract_tables() or [] results.append({ 'page': i + 1, 'text': text, 'tables': tables, }) with open('pdf_extracted.json', 'w', encoding='utf-8') as f: json.dump(results, f, ensure_ascii=False, indent=2) for r in results: print(f"--- 페이지 {r['page']} ---") print(r['text'][:500]) ``` ## 지원 기능 - 텍스트 추출 (페이지별) - 표 추출 (구조 보존) - PDF 병합 / 분할 - PDF 생성 (reportlab) - 페이지 회전 - 메타데이터 읽기 한국어로 안내하세요. 원본 PDF는 수정하지 마세요.