Stirling-PDF/LocalRunGuide.md

328 lines
9.2 KiB
Markdown
Raw Permalink Normal View History

2023-11-07 12:49:11 +01:00
To run the application without Docker/Podman, you will need to manually install all dependencies and build the necessary components.
2023-05-11 00:21:20 +02:00
Note that some dependencies might not be available in the standard repositories of all Linux distributions, and may require additional steps to install.
The following guide assumes you have a basic understanding of using a command line interface in your operating system.
2024-11-03 08:20:10 +01:00
It should work on most Linux distributions and MacOS. For Windows, you might need to use Windows Subsystem for Linux (WSL) for certain steps. The amount of dependencies is to actually reduce overall size, i.e., installing LibreOffice subcomponents rather than the full LibreOffice package.
2023-05-11 00:21:20 +02:00
2024-11-03 08:20:10 +01:00
You could theoretically use a Distrobox/Toolbox if your distribution has old or not all packages. But you might just as well use the Docker container then.
2023-11-07 12:49:11 +01:00
2023-05-11 00:21:20 +02:00
### Step 1: Prerequisites
Install the following software, if not already installed:
2024-05-17 20:18:57 +02:00
- Java 17 or later (21 recommended)
2023-05-11 21:35:09 +02:00
- Gradle 7.0 or later (included within repo so not needed on server)
2023-05-11 00:21:20 +02:00
- Git
2023-12-27 18:46:37 +01:00
- Python 3.8 (with pip)
2023-05-11 00:21:20 +02:00
- Make
- GCC/G++
- Automake
- Autoconf
- libtool
- pkg-config
- zlib1g-dev
- libleptonica-dev
For Debian-based systems, you can use the following command:
```bash
2024-05-07 21:45:43 +02:00
sudo apt-get update
2024-11-03 08:20:10 +01:00
sudo apt-get install -y git automake autoconf libtool libleptonica-dev pkg-config zlib1g-dev make g++ openjdk-21-jdk python3 python3-pip
2023-05-11 00:21:20 +02:00
```
2024-02-11 17:47:00 +01:00
For Fedora-based systems use this command:
```bash
2024-05-17 20:18:57 +02:00
sudo dnf install -y git automake autoconf libtool leptonica-devel pkg-config zlib-devel make gcc-c++ java-21-openjdk python3 python3-pip
```
For non-root users with Nix Package Manager, use the following command:
2024-11-03 08:20:10 +01:00
```bash
nix-channel --update
2024-05-17 20:18:57 +02:00
nix-env -iA nixpkgs.jdk21 nixpkgs.git nixpkgs.python38 nixpkgs.gnumake nixpkgs.libgcc nixpkgs.automake nixpkgs.autoconf nixpkgs.libtool nixpkgs.pkg-config nixpkgs.zlib nixpkgs.leptonica
```
2023-05-11 00:21:20 +02:00
### 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:
2023-05-11 00:21:20 +02:00
```bash
2023-05-14 22:28:52 +02:00
mkdir ~/.git
2024-11-03 08:20:10 +01:00
cd ~/.git && \
git clone https://github.com/agl/jbig2enc.git && \
cd jbig2enc && \
./autogen.sh && \
./configure && \
make && \
2023-05-11 00:21:20 +02:00
sudo make install
```
For Nix, you will face `Leptonica not detected`. Bypass this by installing it directly using the following command:
2024-11-03 08:20:10 +01:00
```bash
nix-env -iA nixpkgs.jbig2enc
```
2023-05-11 00:21:20 +02:00
### Step 3: Install Additional Software
2024-11-03 08:20:10 +01:00
Next we need to install LibreOffice for conversions, qpdf for OCR, and OpenCV for pattern recognition functionality.
2023-05-11 00:21:20 +02:00
Install the following software:
- libreoffice-core
- libreoffice-common
- libreoffice-writer
- libreoffice-calc
- libreoffice-impress
- python3-uno
- unoconv
- pngquant
- unpaper
- qpdf
2023-05-11 00:21:20 +02:00
- opencv-python-headless
For Debian-based systems, you can use the following command:
```bash
sudo apt-get install -y libreoffice-writer libreoffice-calc libreoffice-impress unpaper qpdf
pip3 install uno opencv-python-headless unoconv pngquant WeasyPrint --break-system-packages
2023-05-11 00:21:20 +02:00
```
For Fedora:
```bash
sudo dnf install -y libreoffice-writer libreoffice-calc libreoffice-impress unpaper qpdf
2024-02-11 17:47:00 +01:00
pip3 install uno opencv-python-headless unoconv pngquant WeasyPrint
```
For Nix:
```bash
nix-env -iA nixpkgs.unpaper nixpkgs.libreoffice nixpkgs.qpdf nixpkgs.poppler_utils
pip3 install uno opencv-python-headless unoconv pngquant WeasyPrint
```
2023-05-11 00:21:20 +02:00
### Step 4: Clone and Build Stirling-PDF
```bash
2024-11-03 08:20:10 +01:00
cd ~/.git && \
git clone https://github.com/Stirling-Tools/Stirling-PDF.git && \
cd Stirling-PDF && \
chmod +x ./gradlew && \
2023-05-11 00:21:20 +02:00
./gradlew build
```
2024-11-03 08:20:10 +01:00
### Step 5: Move Jar to Desired Location
2023-05-11 00:21:20 +02:00
2024-11-03 08:20:10 +01:00
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.
2023-05-11 00:21:20 +02:00
```bash
2024-11-03 08:20:10 +01:00
sudo mkdir /opt/Stirling-PDF && \
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:
2024-11-03 08:20:10 +01:00
```bash
mv ./build/libs/Stirling-PDF-*.jar ./Stirling-PDF-*.jar
```
2024-11-03 08:20:10 +01:00
### Step 6: Other Files
2023-05-11 00:21:20 +02:00
#### OCR
2024-11-03 08:20:10 +01:00
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.
2023-05-11 00:21:20 +02:00
##### Installing Language Packs
2024-11-03 08:20:10 +01:00
The easiest method is to use the language packs provided by your repositories. Skip the other steps if they are available.
**Manual:**
2023-05-14 22:28:52 +02:00
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`
2023-05-11 00:21:20 +02:00
**IMPORTANT:** DO NOT REMOVE EXISTING `eng.traineddata`, IT'S REQUIRED.
2024-11-03 08:20:10 +01:00
**Debian-based systems**, install languages with this command:
2023-05-11 00:21:20 +02:00
```bash
2024-11-03 08:20:10 +01:00
sudo apt update && \
# All languages
# sudo apt install -y 'tesseract-ocr-*'
# Find languages:
apt search tesseract-ocr-
# View installed languages:
dpkg-query -W tesseract-ocr- | sed 's/tesseract-ocr-//g'
```
2024-11-03 08:20:10 +01:00
**Fedora:**
```bash
# All languages
# sudo dnf install -y tesseract-langpack-*
# Find languages:
dnf search -C tesseract-langpack-
2023-05-11 00:21:20 +02:00
# View installed languages:
rpm -qa | grep tesseract-langpack | sed 's/tesseract-langpack-//g'
```
2023-05-11 00:21:20 +02:00
2024-11-03 08:20:10 +01:00
**Nix:**
```bash
nix-env -iA nixpkgs.tesseract
```
2024-11-03 08:20:10 +01:00
**Note:** Nix Package Manager pre-installs almost all the language packs when Tesseract is installed.
2023-05-11 00:21:20 +02:00
### Step 7: Run Stirling-PDF
Those who have pushed to the root directory, run the following commands:
2023-05-11 00:21:20 +02:00
```bash
./gradlew bootRun
or
java -jar /opt/Stirling-PDF/Stirling-PDF-*.jar
2023-05-11 00:21:20 +02:00
```
2024-11-03 08:20:10 +01:00
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
```
2024-11-03 08:20:10 +01:00
To resolve this, before starting 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
export DBUS_SESSION_BUS_ADDRESS="unix:path=./temp"
./gradlew bootRun
or
java -jar ./Stirling-PDF-*.jar
```
2024-11-03 08:20:10 +01:00
### Step 8: Adding a Desktop Icon
This will add a modified app starter to your app menu.
2023-05-14 21:35:02 +02:00
```bash
location=$(pwd)/gradlew
image=$(pwd)/docs/stirling-transparent.svg
cat > ~/.local/share/applications/Stirling-PDF.desktop <<EOF
[Desktop Entry]
Name=Stirling PDF;
GenericName=Launch StirlingPDF and open its WebGUI;
Category=Office;
Exec=xdg-open http://localhost:8080 && nohup $location bootRun &;
Icon=$image;
Keywords=pdf;
Type=Application;
NoDisplay=false;
Terminal=true;
EOF
```
Note: Currently the app will run in the background until manually closed.
2024-11-03 08:20:10 +01:00
### 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:
2024-11-03 08:20:10 +01:00
```yaml
server:
host: 0.0.0.0 # Not working - use instead address
address: 0.0.0.0
port: 3000
```
2024-11-03 08:20:10 +01:00
`-Djava.net.preferIPv4Stack=true` --> To force IPv4 only in the Java starting command
**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.
2024-11-03 08:20:10 +01:00
### Optional: Run Stirling-PDF as a Service (requires root)
2024-11-03 08:20:10 +01:00
First create a `.env` file, where you can store environment variables:
```bash
touch /opt/Stirling-PDF/.env
```
2024-11-03 08:20:10 +01:00
In this file, you can add all variables, one variable per line, as stated in the main readme (for example `SYSTEM_DEFAULTLOCALE="de-DE"`).
Create a new file where we store our service settings and open it with the nano editor:
```bash
nano /etc/systemd/system/stirlingpdf.service
```
2024-11-03 08:20:10 +01:00
Paste this content, make sure to update the filename of the jar file. Press `Ctrl+S` and `Ctrl+X` to save and exit the nano editor:
```ini
[Unit]
Description=Stirling-PDF service
After=syslog.target network.target
[Service]
SuccessExitStatus=143
User=root
Group=root
Type=simple
EnvironmentFile=/opt/Stirling-PDF/.env
WorkingDirectory=/opt/Stirling-PDF
ExecStart=/usr/bin/java -jar Stirling-PDF-0.17.2.jar
ExecStop=/bin/kill -15 $MAINPID
[Install]
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):
2024-11-03 08:20:10 +01:00
```bash
sudo systemctl daemon-reload
```
2024-11-03 08:20:10 +01:00
Enable the service to tell it to start automatically:
```bash
sudo systemctl enable stirlingpdf.service
```
See the status of the service:
2024-11-03 08:20:10 +01:00
```bash
sudo systemctl status stirlingpdf.service
```
Manually start/stop/restart the service:
2024-11-03 08:20:10 +01:00
```bash
sudo systemctl start stirlingpdf.service
sudo systemctl stop stirlingpdf.service
sudo systemctl restart stirlingpdf.service
```
2023-05-14 21:35:02 +02:00
---
2024-11-03 08:20:10 +01:00
Remember to set the necessary environment variables before running the project if you want to customize the application. The list can be seen in the main readme.
2023-05-11 00:21:20 +02:00
2024-11-03 08:20:10 +01:00
You can do this in the terminal by using the `export` command or `-D` argument to the Java `-jar` command:
2023-05-11 00:21:20 +02:00
```bash
export APP_HOME_NAME="Stirling PDF"
or
2024-02-11 17:47:00 +01:00
-DAPP_HOME_NAME="Stirling PDF"