-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from Frooodle/cleanups
Latest release
- Loading branch information
Showing
82 changed files
with
3,398 additions
and
845 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,4 +109,6 @@ local.properties | |
*.tar.gz | ||
*.rar | ||
|
||
/build | ||
/build | ||
|
||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
|
||
To run the application without Docker, you will need to manually install all dependencies and build the necessary components. | ||
|
||
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. | ||
|
||
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, ie installing LibreOffice sub components rather than full LibreOffice package. | ||
|
||
### Step 1: Prerequisites | ||
|
||
Install the following software, if not already installed: | ||
|
||
- Java 17 or later | ||
|
||
- Gradle 7.0 or later (included within repo so not needed on server) | ||
|
||
- Git | ||
|
||
- Python 3 (with pip) | ||
|
||
- Make | ||
|
||
- GCC/G++ | ||
|
||
- Automake | ||
|
||
- Autoconf | ||
|
||
- libtool | ||
|
||
- pkg-config | ||
|
||
- zlib1g-dev | ||
|
||
- libleptonica-dev | ||
|
||
For Debian-based systems, you can use the following command: | ||
|
||
```bash | ||
sudo apt-get update | ||
sudo apt-get install -y git automake autoconf libtool libleptonica-dev pkg-config zlib1g-dev make g++ java-17-openjdk python3 python3-pip | ||
``` | ||
|
||
### Step 2: Clone and Build jbig2enc (Only required for certain OCR functionality) | ||
|
||
```bash | ||
git clone https:github.com/agl/jbig2enc | ||
cd jbig2enc | ||
./autogen.sh | ||
./configure | ||
make | ||
sudo make install | ||
``` | ||
|
||
### Step 3: Install Additional Software | ||
Next we need to install LibreOffice for conversions, ocrmypdf for OCR, and opencv for patern recognition functionality. | ||
|
||
Install the following software: | ||
|
||
- libreoffice-core | ||
|
||
- libreoffice-common | ||
|
||
- libreoffice-writer | ||
|
||
- libreoffice-calc | ||
|
||
- libreoffice-impress | ||
|
||
- python3-uno | ||
|
||
- unoconv | ||
|
||
- pngquant | ||
|
||
- unpaper | ||
|
||
- ocrmypdf | ||
|
||
- opencv-python-headless | ||
|
||
For Debian-based systems, you can use the following command: | ||
|
||
```bash | ||
sudo apt-get install -y libreoffice-core libreoffice-common libreoffice-writer libreoffice-calc libreoffice-impress python3-uno unoconv pngquant unpaper ocrmypdf | ||
pip3 install opencv-python-headless | ||
``` | ||
|
||
### Step 4: Clone and Build Stirling-PDF | ||
|
||
```bash | ||
git clone https://github.com/Frooodle/Stirling-PDF.git | ||
cd Stirling-PDF | ||
./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 | ||
|
||
### 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 none english scanning. | ||
|
||
##### Installing Language Packs | ||
|
||
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/tesseract-ocr/4.00/tessdata` | ||
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. | ||
|
||
|
||
|
||
### Step 7: Run Stirling-PDF | ||
|
||
```bash | ||
./gradlew bootRun | ||
or | ||
java -jar build/libs/app.jar | ||
``` | ||
|
||
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. | ||
|
||
You can do this in the terminal by using the `export` command or -D arguements to java -jar command: | ||
|
||
```bash | ||
export APP_HOME_NAME="Stirling PDF" | ||
or | ||
-DAPP_HOME_NAME="Stirling PDF" | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import cv2 | ||
import numpy as np | ||
import sys | ||
import argparse | ||
|
||
def is_blank_image(image_path, threshold=10, white_percent=99, white_value=255, blur_size=5): | ||
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) | ||
|
||
if image is None: | ||
print(f"Error: Unable to read the image file: {image_path}") | ||
return False | ||
|
||
# Apply Gaussian blur to reduce noise | ||
blurred_image = cv2.GaussianBlur(image, (blur_size, blur_size), 0) | ||
|
||
_, thresholded_image = cv2.threshold(blurred_image, white_value - threshold, white_value, cv2.THRESH_BINARY) | ||
|
||
# Calculate the percentage of white pixels in the thresholded image | ||
white_pixels = np.sum(thresholded_image == white_value) | ||
total_pixels = thresholded_image.size | ||
white_pixel_percentage = (white_pixels / total_pixels) * 100 | ||
print(f"Page has white pixel percent of {white_pixel_percentage}") | ||
return white_pixel_percentage > white_percent | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Detect if an image is considered blank or not.') | ||
parser.add_argument('image_path', help='The path to the image file.') | ||
parser.add_argument('-t', '--threshold', type=int, default=10, help='Threshold for determining white pixels. The default value is 10.') | ||
parser.add_argument('-w', '--white_percent', type=float, default=99, help='The percentage of white pixels for an image to be considered blank. The default value is 99.') | ||
args = parser.parse_args() | ||
|
||
blank = is_blank_image(args.image_path, args.threshold, args.white_percent) | ||
|
||
if blank: | ||
# Return code 1: The image is considered blank. | ||
sys.exit(1) | ||
else: | ||
# Return code 0: The image is not considered blank. | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.