From 5f6d24f805f3de49bdb66cb4544b671a60e019ea Mon Sep 17 00:00:00 2001 From: Ahmed Khatib Date: Wed, 8 May 2024 01:14:08 +0530 Subject: [PATCH 1/4] Added support for non-root and nix package manager for local installation. Fixed a bad small line break issue. --- LocalRunGuide.md | 70 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 7 deletions(-) diff --git a/LocalRunGuide.md b/LocalRunGuide.md index e0851d62..449dbf73 100644 --- a/LocalRunGuide.md +++ b/LocalRunGuide.md @@ -41,7 +41,7 @@ Install the following software, if not already installed: For Debian-based systems, you can use the following command: ```bash -sudo apt-get update +sudo apt-get upda te sudo apt-get install -y git automake autoconf libtool libleptonica-dev pkg-config zlib1g-dev make g++ openjdk-17-jdk python3 python3-pip ``` @@ -51,8 +51,16 @@ For Fedora-based systems use this command: sudo dnf install -y git automake autoconf libtool leptonica-devel pkg-config zlib-devel make gcc-c++ java-17-openjdk python3 python3-pip ``` +For non-root users with Nix Package Manager, use the following command: +```bash +nix-channel --update +nix-env -iA nixpkgs.jdk17 nixpkgs.git nixpkgs.python38 nixpkgs.gnumake nixpkgs.libgcc nixpkgs.automake nixpkgs.autoconf nixpkgs.libtool nixpkgs.pkg-config nixpkgs.zlib nixpkgs.leptonica +``` + ### Step 2: Clone and Build jbig2enc (Only required for certain OCR functionality) +For Debian and Fedora, you can build it from source using the following commands: + ```bash mkdir ~/.git cd ~/.git &&\ @@ -64,6 +72,11 @@ make &&\ sudo make install ``` +For Nix, you will face `Leptonica not detected`. Bypass this by installing it directly using the following command: +```bash +nix-env -iA nixpkgs.jbig2enc +``` + ### Step 3: Install Additional Software Next we need to install LibreOffice for conversions, ocrmypdf for OCR, and opencv for pattern recognition functionality. @@ -105,6 +118,13 @@ sudo dnf install -y libreoffice-writer libreoffice-calc libreoffice-impress unpa pip3 install uno opencv-python-headless unoconv pngquant WeasyPrint ``` +For Nix: + +```bash +nix-env -iA nixpkgs.unpaper nixpkgs.libreoffice nixpkgs.ocrmypdf nixpkgs.poppler_utils +pip3 install uno opencv-python-headless unoconv pngquant WeasyPrint +``` + ### Step 4: Clone and Build Stirling-PDF ```bash @@ -115,13 +135,12 @@ chmod +x ./gradlew &&\ ./gradlew build ``` - ### Step 5: Move jar to desired location After the build process, a `.jar` file will be generated in the `build/libs` directory. You can move this file to a desired location, for example, `/opt/Stirling-PDF/`. You must also move the Script folder within the Stirling-PDF repo that you have downloaded to this directory. -This folder is required for the python scripts using OpenCV +This folder is required for the python scripts using OpenCV. ```bash sudo mkdir /opt/Stirling-PDF &&\ @@ -129,19 +148,27 @@ sudo mv ./build/libs/Stirling-PDF-*.jar /opt/Stirling-PDF/ &&\ sudo mv scripts /opt/Stirling-PDF/ &&\ echo "Scripts installed." ``` + +For non-root users, you can just keep the jar in the main directory of Stirling-PDF using the following command: +```bash +mv ./build/libs/Stirling-PDF-*.jar ./Stirling-PDF-*.jar +``` + ### Step 6: Other files #### OCR If you plan to use the OCR (Optical Character Recognition) functionality, you might need to install language packs for Tesseract if running non-english scanning. ##### Installing Language Packs -Easiest is to use the langpacks provided by your repositories. Skip the other steps +Easiest is to use the langpacks provided by your repositories. Skip the other steps. + +**Note:** Nix Package Manager pre-installs almost all the packages by default. Manual: 1. Download the desired language pack(s) by selecting the `.traineddata` file(s) for the language(s) you need. 2. Place the `.traineddata` files in the Tesseract tessdata directory: `/usr/share/tessdata` -3. -Please view [OCRmyPDF install guide](https://ocrmypdf.readthedocs.io/en/latest/installation.html) for more info. +3. Please view [OCRmyPDF install guide](https://ocrmypdf.readthedocs.io/en/latest/installation.html) for more info. + **IMPORTANT:** DO NOT REMOVE EXISTING `eng.traineddata`, IT'S REQUIRED. Debian based systems, install languages with this command: @@ -171,14 +198,30 @@ dnf search -C tesseract-langpack- rpm -qa | grep tesseract-langpack | sed 's/tesseract-langpack-//g' ``` +Nix: + +```bash +nix-env -iA nixpkgs.tesseract +``` + ### Step 7: Run Stirling-PDF +Those who have pushed to the root directory, run the following commands: + ```bash ./gradlew bootRun or java -jar /opt/Stirling-PDF/Stirling-PDF-*.jar ``` +Non-root users can run from the Stirling-PDF directory using the following commands: + +```bash +./gradlew bootRun +or +java -jar ./Stirling-PDF-*.jar +``` + ### Step 8: Adding a Desktop icon This will add a modified Appstarter to your Appmenu. @@ -202,7 +245,19 @@ EOF Note: Currently the app will run in the background until manually closed. -### Optional: Run Stirling-PDF as a service +### Optional: Changing the host and port of the application: + +To override the default configuration, you can add the following to `/.git/Stirling-PDF/configs/custom_settings.yml` file: + +```bash +server: + host: 0.0.0.0 + port: 3000 +``` + +**Note:** This file is created after the first application launch. To have it before that, you can create the directory and add the file yourself. + +### Optional: Run Stirling-PDF as a service (requires root). First create a .env file, where you can store environment variables: ``` @@ -239,6 +294,7 @@ WantedBy=multi-user.target ``` Notify systemd that it has to rebuild its internal service database (you have to run this command every time you make a change in the service file): + ``` sudo systemctl daemon-reload ``` From cbe750c76cf6adcc29c03f496b225ef436cddab3 Mon Sep 17 00:00:00 2001 From: Ahmed Khatib Date: Wed, 8 May 2024 01:15:43 +0530 Subject: [PATCH 2/4] Small typo in apt-get update. --- LocalRunGuide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LocalRunGuide.md b/LocalRunGuide.md index 449dbf73..bbd46f50 100644 --- a/LocalRunGuide.md +++ b/LocalRunGuide.md @@ -41,7 +41,7 @@ Install the following software, if not already installed: For Debian-based systems, you can use the following command: ```bash -sudo apt-get upda te +sudo apt-get update sudo apt-get install -y git automake autoconf libtool libleptonica-dev pkg-config zlib1g-dev make g++ openjdk-17-jdk python3 python3-pip ``` From 8b2f24affd33075e26df9d2d68e0d5cc2edf81ed Mon Sep 17 00:00:00 2001 From: Ahmed Khatib Date: Wed, 8 May 2024 01:22:52 +0530 Subject: [PATCH 3/4] Added the export command before running. --- LocalRunGuide.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LocalRunGuide.md b/LocalRunGuide.md index bbd46f50..87d5f161 100644 --- a/LocalRunGuide.md +++ b/LocalRunGuide.md @@ -214,9 +214,11 @@ or java -jar /opt/Stirling-PDF/Stirling-PDF-*.jar ``` -Non-root users can run from the Stirling-PDF directory using the following commands: +Non-root users can run from the Stirling-PDF directory using the following commands (can use any temp directory you want): ```bash +mkdir temp +export DBUS_SESSION_BUS_ADDRESS="unix:path=./temp" ./gradlew bootRun or java -jar ./Stirling-PDF-*.jar From 0a0887aafcfb9060e096fdd2d48f722a09801280 Mon Sep 17 00:00:00 2001 From: Ahmed Khatib Date: Wed, 8 May 2024 01:52:41 +0530 Subject: [PATCH 4/4] Fixed the bad working regarding language packs. Explained the dbus variable change before running the jar file. --- LocalRunGuide.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/LocalRunGuide.md b/LocalRunGuide.md index 87d5f161..e4f744c3 100644 --- a/LocalRunGuide.md +++ b/LocalRunGuide.md @@ -161,8 +161,6 @@ If you plan to use the OCR (Optical Character Recognition) functionality, you mi ##### Installing Language Packs Easiest is to use the langpacks provided by your repositories. Skip the other steps. -**Note:** Nix Package Manager pre-installs almost all the packages by default. - Manual: 1. Download the desired language pack(s) by selecting the `.traineddata` file(s) for the language(s) you need. @@ -204,6 +202,8 @@ Nix: nix-env -iA nixpkgs.tesseract ``` +**Note:** Nix Package Manager pre-installs almost all the language packs when tesseract is installed. + ### Step 7: Run Stirling-PDF Those who have pushed to the root directory, run the following commands: @@ -214,7 +214,11 @@ or java -jar /opt/Stirling-PDF/Stirling-PDF-*.jar ``` -Non-root users can run from the Stirling-PDF directory using the following commands (can use any temp directory you want): +Since libreoffice, soffice, and conversion tools have their dbus_tmp_dir set as `dbus_tmp_dir="/run/user/$(id -u)/libreoffice-dbus"`, you might get the following error when using their endpoints: +``` +[Thread-7] INFO s.s.SPDF.utils.ProcessExecutor - mkdir: cannot create directory ‘/run/user/1501’: Permission denied +``` +To resolve this, before starting the Stirling-PDF, you have to set the environment variable to a directory you have write access to by using the following commands: ```bash mkdir temp