Metadata-Version: 2.4
Name: pdfprep
Version: 0.2.1
Summary: PDF 전처리 통합 도구 — 메타데이터, 텍스트 파싱, OCR, 표 추출
Author-email: uwpark <uwpark@simplatform.com>
License: MIT
Project-URL: Homepage, https://pypi.org/project/pdfprep/
Keywords: pdf,ocr,table-extraction,preprocessing,parsing,metadata
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Text Processing
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Classifier: Natural Language :: Korean
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: pypdf<6.0,>=4.0
Requires-Dist: pdfplumber>=0.11.0
Requires-Dist: pymupdf>=1.27.0
Requires-Dist: pillow>=10.0
Provides-Extra: ocr
Requires-Dist: pytesseract>=0.3.13; extra == "ocr"
Requires-Dist: paddleocr==2.7.3; python_full_version < "3.13" and extra == "ocr"
Requires-Dist: paddlepaddle==2.6.2; python_full_version < "3.13" and extra == "ocr"
Requires-Dist: numpy<2; python_full_version < "3.13" and extra == "ocr"
Requires-Dist: numpy<3,>=2; python_full_version >= "3.13" and extra == "ocr"
Requires-Dist: setuptools>=65; python_full_version < "3.13" and extra == "ocr"
Provides-Extra: table
Requires-Dist: camelot-py==1.0.9; extra == "table"
Requires-Dist: tabula-py>=2.10; extra == "table"
Requires-Dist: jpype1>=1.5; python_full_version < "3.13" and extra == "table"
Requires-Dist: layoutparser>=0.3.4; python_full_version < "3.13" and extra == "table"
Requires-Dist: numpy<2; python_full_version < "3.13" and extra == "table"
Requires-Dist: numpy<3,>=2; python_full_version >= "3.13" and extra == "table"
Provides-Extra: all
Requires-Dist: pytesseract>=0.3.13; extra == "all"
Requires-Dist: paddleocr==2.7.3; python_full_version < "3.13" and extra == "all"
Requires-Dist: paddlepaddle==2.6.2; python_full_version < "3.13" and extra == "all"
Requires-Dist: camelot-py==1.0.9; extra == "all"
Requires-Dist: tabula-py>=2.10; extra == "all"
Requires-Dist: jpype1>=1.5; python_full_version < "3.13" and extra == "all"
Requires-Dist: layoutparser>=0.3.4; python_full_version < "3.13" and extra == "all"
Requires-Dist: numpy<2; python_full_version < "3.13" and extra == "all"
Requires-Dist: numpy<3,>=2; python_full_version >= "3.13" and extra == "all"
Requires-Dist: setuptools>=65; python_full_version < "3.13" and extra == "all"

# pdfprep

[![PyPI](https://img.shields.io/pypi/v/pdfprep.svg)](https://pypi.org/project/pdfprep/)
[![Python](https://img.shields.io/pypi/pyversions/pdfprep.svg)](https://pypi.org/project/pdfprep/)
[![License](https://img.shields.io/pypi/l/pdfprep.svg)](https://pypi.org/project/pdfprep/)

PDF 전처리 통합 도구 — **메타데이터 / 텍스트 파싱 / OCR / 표 추출** 4가지 작업을 한 패키지로.

여러 PDF 처리 라이브러리(pypdf, pdfplumber, pymupdf, tesseract, paddleocr, camelot, tabula, layoutparser)를 **일관된 인터페이스**로 감싸서, 엔진별 결과를 한 번에 비교·선택할 수 있습니다.

## 설치

```bash
# 기본 (메타데이터 + 파싱만)
pip install pdfprep

# OCR 포함
pip install "pdfprep[ocr]"

# 표 추출 포함
pip install "pdfprep[table]"

# 전체
pip install "pdfprep[all]"
```

> **Python 버전별 지원 범위 (Windows 포함)**
>
> | 기능 | Python 3.12 | Python 3.13 / 3.14 |
> | --- | --- | --- |
> | 기본 (메타데이터 · 파싱) | ✅ | ✅ |
> | OCR — tesseract | ✅ | ✅ |
> | OCR — paddleocr | ✅ | ⚠️ 설치 제외 |
> | 표 — camelot · tabula | ✅ | ✅ |
> | 표 — layoutparser | ✅ | ⚠️ 설치 제외 |
>
> `paddleocr`/`paddlepaddle`/`layoutparser` 는 아직 Python 3.13+ 휠을 제공하지 않아,
> 3.13/3.14 환경에서는 `pip install` 시 자동으로 제외됩니다 (설치는 정상 완료).
> 해당 엔진을 호출하면 안내 메시지와 함께 건너뜁니다. paddle 계열이 필요하면 Python 3.12 를 사용하세요.

### 시스템 패키지 (해당 기능을 쓸 때만)

| 기능 | 패키지 | 설치 |
| --- | --- | --- |
| `ocr` (tesseract) | tesseract 바이너리 + 언어 데이터 | `sudo apt install tesseract-ocr tesseract-ocr-kor` |
| `table` (camelot lattice 모드) | Ghostscript | `sudo apt install ghostscript` |
| `table` (tabula) | Java 런타임 | `sudo apt install default-jre` |
| `table` (layoutparser) | (없음 — paddlepaddle만 있으면 됨, 최초 실행 시 모델 자동 다운로드) | — |

## 빠른 시작

### 1. 메타데이터

```python
from pdfprep import metadata

metadata.show_pdf_metadata("sample.pdf")
# 파일 크기 / 페이지 수 / Title / Author / 생성일 등 출력
```

### 2. 텍스트 파싱

```python
from pdfprep import parsing

result = parsing.parse_pdf("sample.pdf", engine="pymupdf")
print(result["text"])
print(result["features"])  # 블록 수, 폰트, 이미지 수 등 엔진 특화 정보
```

지원 엔진: `pypdf`, `pdfplumber`, `pymupdf`

### 3. OCR

```python
from pdfprep import ocr

result = ocr.ocr_pdf("scan.pdf", engine="tesseract")
print(result["text"])
print(result["features"]["평균 신뢰도(%)"])
```

지원 엔진: `tesseract`, `paddleocr`

### 4. 표 추출

```python
from pdfprep import table

result = table.extract_tables("doc.pdf", engine="camelot")
for t in result["tables"]:
    print(t["df"])  # pandas DataFrame
```

지원 엔진: `camelot`, `tabula`, `layoutparser`

## CLI

설치 후 다음 명령들이 자동으로 등록됩니다:

```bash
pdfprep-metadata sample.pdf
pdfprep-parse    sample.pdf pymupdf       # 엔진 생략 시 전체 비교
pdfprep-ocr      sample.pdf tesseract
pdfprep-table    doc.pdf    camelot
```

## 공통 API

모든 함수는 `dict`를 반환하며 공통 키가 같습니다:

```python
{
    "engine":      "pymupdf",        # 사용 엔진
    "page_count":  3,                # 페이지 수
    "text":        "...",            # 통합 텍스트
    "pages":       ["...", ...],     # 페이지별 텍스트
    "features":    {...},            # 엔진 특화 지표
}
```

표 추출은 추가로 `table_count`와 `tables` (DataFrame 또는 bbox 리스트)를 포함합니다.

## 엔진별 특징

| 모듈 | 엔진 | 강점 |
| --- | --- | --- |
| `parsing` | pypdf | 가벼움. 목차/폼/주석/암호화 메타 |
| `parsing` | pdfplumber | 표·단어/문자 bbox·도형(선·사각형) |
| `parsing` | pymupdf | 빠름. 블록 구조 + 폰트/색상/이미지 메타 |
| `ocr` | tesseract | 빠름. 다국어 동시 인식. 단어별 신뢰도 |
| `ocr` | paddleocr | 딥러닝. 검출+인식 2단계. 라인 박스 + 신뢰도 |
| `table` | camelot | DataFrame + accuracy/whitespace 품질 지표 |
| `table` | tabula | DataFrame + 자동 헤더 인식 |
| `table` | layoutparser | 표 영역 bbox 검출(TableBank 모델). 셀 추출은 X |

## 요구 사항

- Python ≥ 3.12
- Linux 권장 (macOS·Windows에서도 동작하지만 시스템 패키지 설치 방법은 다름)

## 라이선스

MIT
