Version final
This commit is contained in:
parent
2cc235e765
commit
e7d3ab34ed
65
README.md
65
README.md
@ -301,40 +301,47 @@ python3 -c "import pandas, openpyxl, dotenv; print('OK', pandas.__version__, ope
|
||||
```
|
||||
|
||||
#### 7.7) OCR (PDF real + escaneado) con Tesseract (Alpine)
|
||||
Si necesitas leer PDFs escaneados para el autorrelleno, usa este flujo.
|
||||
|
||||
**Instalacion OCR en Alpine (servidor)**
|
||||
Si el backend dice "OCR no disponible", instala esto en Alpine:
|
||||
```bash
|
||||
|
||||
# 1) Asegura repo community (donde esta ocrmypdf/tesseract-data)
|
||||
ALPINE_VER="$(cut -d. -f1,2 /etc/alpine-release)"
|
||||
sed -i 's/^#\(.*\/community\)/\1/' /etc/apk/repositories
|
||||
grep -q "/v${ALPINE_VER}/community" /etc/apk/repositories || \
|
||||
echo "https://dl-cdn.alpinelinux.org/alpine/v${ALPINE_VER}/community" >> /etc/apk/repositories
|
||||
|
||||
# 2) Instala herramientas: pdftotext (poppler), ocrmypdf, tesseract + idiomas
|
||||
# 1) Paquetes del sistema (OCR + deps de Python)
|
||||
apk update
|
||||
apk add --no-cache \
|
||||
poppler-utils \
|
||||
ocrmypdf \
|
||||
tesseract-ocr \
|
||||
tesseract-ocr-data-spa \
|
||||
tesseract-ocr-data-eng
|
||||
tesseract-ocr-data-eng \
|
||||
python3 py3-pip py3-virtualenv \
|
||||
build-base python3-dev musl-dev \
|
||||
libffi-dev openssl-dev zlib-dev \
|
||||
jpeg-dev tiff-dev freetype-dev lcms2-dev openjpeg-dev
|
||||
|
||||
# 3) Procesa el PDF (real/escaneado/mixto)
|
||||
IN="${1:-archivo.pdf}"
|
||||
BASE="${IN%.pdf}"
|
||||
TXT="${BASE}.txt"
|
||||
OCRPDF="${BASE}.ocr.pdf"
|
||||
# 2) Venv (si ya tienes /opt/saludut/venv, solo activalo)
|
||||
python3 -m venv /opt/saludut/venv
|
||||
. /opt/saludut/venv/bin/activate
|
||||
|
||||
# Intenta extraer texto directo
|
||||
pdftotext -layout "$IN" - > "$TXT" 2>/dev/null || true
|
||||
|
||||
# Si el texto es muy corto, probablemente es escaneado (o casi todo imagen) -> OCR
|
||||
LEN="$(tr -d '[:space:]' < "$TXT" | wc -c | tr -d ' ')"
|
||||
if [ "${LEN:-0}" -lt 80 ]; then
|
||||
ocrmypdf -l spa+eng --skip-text --rotate-pages --deskew --optimize 3 "$IN" "$OCRPDF"
|
||||
pdftotext -layout "$OCRPDF" "$TXT"
|
||||
echo "OK (OCR aplicado cuando hacia falta): $OCRPDF | Texto: $TXT"
|
||||
else
|
||||
echo "OK (PDF con texto): Texto: $TXT"
|
||||
fi
|
||||
# 3) Librerias Python usadas por el extractor
|
||||
pip install --upgrade pip
|
||||
pip install pdfplumber pymupdf pytesseract pillow
|
||||
```
|
||||
|
||||
En `backend/.env` agrega (o ajusta):
|
||||
```
|
||||
PYTHON_PATH=/opt/saludut/venv/bin/python
|
||||
TESSERACT_PATH=/usr/bin/tesseract
|
||||
TESSDATA_PREFIX=/usr/share/tessdata
|
||||
```
|
||||
|
||||
Verificacion:
|
||||
```bash
|
||||
tesseract --list-langs | grep spa
|
||||
/opt/saludut/venv/bin/python -c "import pytesseract; print(pytesseract.get_tesseract_version())"
|
||||
```
|
||||
|
||||
Reinicia el backend:
|
||||
```bash
|
||||
rc-service saludut-backend restart
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user