# Main stage
FROM ubuntu:latest AS base



# JDK for app
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    	openjdk-17-jre
    	
    	
# Doc conversion
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    	libreoffice-core-nogui \
        libreoffice-common \
        libreoffice-writer-nogui \
        libreoffice-calc-nogui \
        libreoffice-impress-nogui \
		python3-uno \
		unoconv
		
		
# OCR MY PDF (unpaper for descew and other advanced featues)
RUN apt-get update && apt-get install -y --no-install-recommends software-properties-common gnupg2 && \
add-apt-repository ppa:alex-p/tesseract-ocr5 && apt install -y --no-install-recommends tesseract-ocr && \
apt-get update && \
    apt-get install -y --no-install-recommends \
        ghostscript \
        python3-pip \
        ocrmypdf \
        unpaper && \
    pip install --upgrade pip && \
    pip install --no-cache-dir --upgrade ocrmypdf && \
    pip install --no-cache-dir --upgrade pillow==10.0.1 reportlab==3.6.13 wheel==0.38.1 setuptools==65.5.1 pyjwt==2.4.0 cryptography==39.0.1
    
    
#CV    
RUN pip install --no-cache-dir opencv-python-headless


# cleanup and etc
RUN rm -rf /var/lib/apt/lists/* && \
    mkdir /usr/share/tesseract-ocr-original && \
    cp -r /usr/share/tesseract-ocr/* /usr/share/tesseract-ocr-original && \
    rm -rf /usr/share/tesseract-ocr