From 35141653f719877d14df1baa2c788f3eec0e15db Mon Sep 17 00:00:00 2001 From: Oleh Astappiev <4512729+astappiev@users.noreply.github.com> Date: Sun, 13 Apr 2025 15:35:20 +0200 Subject: [PATCH 1/3] Add Dockerfile --- Dockerfile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..927aaa4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM python:3.9-bookworm + +RUN apt-get update && apt-get install -y \ + libdjvulibre-dev \ + libtiff-dev \ + libjpeg-dev \ + ghostscript \ + poppler-utils \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +RUN pip install poetry +RUN pip install ocrmypdf + +WORKDIR /app +COPY . /app/ + +RUN poetry config virtualenvs.create false \ + && poetry install --no-interaction --no-ansi + +RUN mkdir /files + +WORKDIR /files + +ENTRYPOINT ["python", "-m", "dpsprep"] From 766a62db33c3aaf81cd24e209043ba426dd3d368 Mon Sep 17 00:00:00 2001 From: Oleh Astappiev <4512729+astappiev@users.noreply.github.com> Date: Sun, 13 Apr 2025 15:57:08 +0200 Subject: [PATCH 2/3] add Jbig2enc lib --- Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Dockerfile b/Dockerfile index 927aaa4..4bd3c9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,19 @@ RUN apt-get update && apt-get install -y \ libjpeg-dev \ ghostscript \ poppler-utils \ + # Jbig2enc build requirements below + git autotools-dev automake libtool libleptonica-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +# add Jbig2enc, after debian 13 is released, this can be removed (libjbig2enc-dev will be available) +WORKDIR /opt +RUN git clone https://github.com/agl/jbig2enc + +WORKDIR /opt/jbig2enc +RUN ./autogen.sh && ./configure && make install + +# Continue with environment setup RUN pip install poetry RUN pip install ocrmypdf From 52cd9a94c775c041cfb2463f1cbcff7db32714c2 Mon Sep 17 00:00:00 2001 From: Oleh Astappiev Date: Sun, 13 Apr 2025 23:07:56 +0200 Subject: [PATCH 3/3] feat: reduce image size and update README --- Dockerfile | 46 ++++++++++++++++++++++++++++++++-------------- README.md | 30 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4bd3c9d..aa2343c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,47 @@ -FROM python:3.9-bookworm +# after Debian 13 (trixie) is released, this can be removed in favor of the libjbig2enc-dev package +FROM debian:bookworm-slim AS jbig2enc-builder + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential autoconf automake libtool \ + libleptonica-dev \ + zlib1g-dev \ + libffi-dev \ + ca-certificates \ + curl \ + git \ + libcairo2-dev \ + pkg-config -RUN apt-get update && apt-get install -y \ +WORKDIR /opt + +RUN git clone --depth 1 https://github.com/agl/jbig2enc && \ + cd jbig2enc && \ + ./autogen.sh && \ + ./configure && \ + make && \ + make install + +# The actual image to be used +FROM python:3.11-bookworm + +RUN apt-get update && apt-get install -y --no-install-recommends \ libdjvulibre-dev \ libtiff-dev \ libjpeg-dev \ ghostscript \ poppler-utils \ - # Jbig2enc build requirements below - git autotools-dev automake libtool libleptonica-dev \ + libleptonica-dev \ + # libjbig2enc-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -# add Jbig2enc, after debian 13 is released, this can be removed (libjbig2enc-dev will be available) -WORKDIR /opt -RUN git clone https://github.com/agl/jbig2enc - -WORKDIR /opt/jbig2enc -RUN ./autogen.sh && ./configure && make install +COPY --from=jbig2enc-builder /usr/local/lib/ /usr/local/lib/ +COPY --from=jbig2enc-builder /usr/local/bin/ /usr/local/bin/ -# Continue with environment setup -RUN pip install poetry -RUN pip install ocrmypdf +RUN pip install --no-cache-dir poetry ocrmypdf WORKDIR /app -COPY . /app/ +COPY . . RUN poetry config virtualenvs.create false \ && poetry install --no-interaction --no-ansi diff --git a/README.md b/README.md index d4986b3..e212b3a 100644 --- a/README.md +++ b/README.md @@ -95,3 +95,33 @@ http://askubuntu.com/questions/46233/converting-djvu-to-pdf (OCR text transfer) By implementing the procedure of user pyrocrasty for extracting the outline, and putting it into the PDF generated above: http://superuser.com/questions/801893/converting-djvu-to-pdf-and-preserving-table-of-contents-how-is-it-possible (bookmark transfer) + +## Using Docker + +Build the Docker image: + +```bash +docker build -t dpsprep . +``` + +Run the container with a volume mount to process files: + +```bash +docker run --rm -u $(id -u):$(id -g) -v $(pwd):/files dpsprep input.djvu output.pdf +``` + +To use specific options: + +```bash +docker run --rm -u $(id -u):$(id -g) -v $(pwd):/files dpsprep --pool=8 --quality=50 input.djvu output.pdf +``` + +### Add as alias + +Put the following line into `~/.bashrc` or `~/.zshrc`: + +```bash +alias dpsprep='docker run --rm -u $(id -u):$(id -g) -v $(pwd):/files dpsprep' +``` + +This will allow you to run the command as `dpsprep` without needing to specify the Docker command each time.