Skip to content

Latest commit

 

History

History
229 lines (161 loc) · 6.74 KB

README.md

File metadata and controls

229 lines (161 loc) · 6.74 KB

FileOperationsXXX PDF Tools

Spring Boot application for converting supported files to PDF, compressing PDFs, and merging multiple PDFs.

Project layout

  • convertx-app: Spring Boot web application for FileOperationsXXX
  • pdf-compression: extracted Ghostscript-based PDF compression subproject

Requirements

  • Java 25
  • Maven 3.9+
  • Linux server with these commands available on the PATH
  • LibreOffice installed and soffice available on the PATH for docx, xlsx, and pptx
  • Ghostscript installed and gs available on the PATH for PDF compression
  • HEIC support installed through ImageMagick (magick or convert) or libheif (heif-convert)

Run

mvn -pl convertx-app -am spring-boot:run

Open http://localhost:8081 to use the web UI for convert, compress, and merge operations.

Local setup

  1. Install JDK 25 and make sure both java and mvn use it.
  2. Verify with:
java -version
mvn -version
  1. If Maven is using a different JDK than your shell, export JAVA_HOME before running Maven:
export JAVA_HOME=/path/to/jdk-25
export PATH="$JAVA_HOME/bin:$PATH"
  1. Build from the project root:
mvn test
  1. Run the app module:
mvn -pl convertx-app -am spring-boot:run
  1. Confirm required native tools are available:
which magick || which convert || which heif-convert
which soffice
which gs

OpenAPI docs:

  • Swagger UI: http://localhost:8081/swagger-ui.html
  • OpenAPI JSON: http://localhost:8081/api/docs

Docker

Build the image from the project root:

docker build -t fileoperationsxxx .

Run it locally:

docker run --rm -p 8081:8081 fileoperationsxxx

Run it with an explicit platform port:

docker run --rm -e PORT=8081 -p 8081:8081 fileoperationsxxx

The container image includes the native Linux dependencies required by the application:

  • LibreOffice for docx, xlsx, and pptx
  • Ghostscript for PDF compression
  • ImageMagick and libheif tools for HEIC conversion and rotation

Automatic deployment on GCP

The repository now includes cloudbuild.yaml for Cloud Build based automatic deployment.

The intended GCP setup is:

  • GitHub repository: ThreeMangoTrees/AllFiles
  • Branch trigger: ^main$
  • Build config file: cloudbuild.yaml
  • Cloud Run service: allfilesxxx
  • Region: us-west1
  • Artifact Registry image path: us-west1-docker.pkg.dev/$PROJECT_ID/cloud-run-source-deploy/allfiles/allfilesxxx:$COMMIT_SHA

On each push to main, Cloud Build will:

  1. build the Docker image from the repo root Dockerfile
  2. run a trivy vulnerability scan and fail the build on HIGH or CRITICAL findings
  3. push the image to Artifact Registry
  4. update the Cloud Run service with the new image

Security

The application now expects HTTP Basic authentication in deployed environments.

  • Username env var: APP_BASIC_AUTH_USERNAME
  • Password env var: APP_BASIC_AUTH_PASSWORD
  • API docs are disabled by default in deployed environments unless explicitly re-enabled
  • Per-client rate limiting is enabled by default for /api/*
  • Optional malware scanning can be enabled with:
    • APP_ANTIVIRUS_ENABLED=true
    • APP_ANTIVIRUS_COMMAND=clamscan

Cloud Run deployments from cloudbuild.yaml now also:

  • set Cloud Run concurrency to 10
  • inject the application password from Secret Manager secret app-basic-auth-password
  • keep Swagger and OpenAPI disabled by default

Linux deployment

Use this checklist before deploying the project to a Linux server.

  1. Install the required native packages.
  • soffice is required for docx, xlsx, and pptx
  • gs is required for PDF compression
  • HEIC conversion requires one of:
    • ImageMagick via magick or convert
    • libheif via heif-convert
  • HEIC rotation requires ImageMagick with HEIC delegate support

On Debian or Ubuntu, a typical install looks like:

sudo apt-get update
sudo apt-get install -y libreoffice ghostscript imagemagick libheif-examples
  1. Use the PORT environment variable when the server platform assigns ports dynamically.
  • The application now reads server.port from PORT and falls back to 8081.
  • This works for systemd services, VMs, containers, and platforms like Cloud Run.
  1. Verify the Linux runtime before launch.
java -version
mvn -version
which soffice
which gs
which magick || which convert || which heif-convert
  1. Package and run the application.
mvn test
mvn -pl convertx-app -am package
java -jar convertx-app/target/convertx-app-0.0.1-SNAPSHOT.jar
  1. For systemd-managed Linux servers, set PORT, JAVA_HOME, and PATH explicitly in the unit file if they are not already present in the service environment.

  2. Size the server with enough memory for LibreOffice and Ghostscript, especially for large Office files and large PDF merge/compression requests.

  3. If the server is container-based, prefer baking the native binaries into the image instead of installing them at container start.

  4. The current file-based logs are configured in logback-spring.xml. Keep console logging enabled if your Linux environment ships logs through journald or a container runtime.

API

Convert a supported file to PDF:

curl -X POST \
  -F "file=@/path/to/file.docx" \
  http://localhost:8081/api/convert/to-pdf \
  --output converted.pdf

Compress a PDF with a 25%, 50%, or 75% profile:

curl -X POST \
  -F "file=@/path/to/file.pdf" \
  -F "targetPercentage=50" \
  http://localhost:8081/api/pdf/compress \
  --output compressed.pdf

Merge two or more PDFs:

curl -X POST \
  -F "files=@/path/to/part-1.pdf" \
  -F "files=@/path/to/part-2.pdf" \
  http://localhost:8081/api/pdf/merge \
  --output merged.pdf

Supported formats

  • docx, xlsx, pptx
  • jpg, jpeg, tiff, gif, bmp, heic
  • txt, rtf, html, htm

Notes

  • docx, xlsx, and pptx are converted through LibreOffice in headless mode.
  • heic conversion uses ImageMagick (magick or convert) or heif-convert.
  • heic rotation currently returns a jpg file because HEIC encoding support is not reliably available in Linux deployments.
  • TODO: implement native HEIC-to-HEIC rotation support so rotated HEIC uploads remain in HEIC format instead of being converted to JPG.
  • Image formats currently convert the first image frame/page into a single-page PDF.
  • PDF compression uses Ghostscript profiles that roughly target 25%, 50%, or 75% size classes; exact output size depends on the source PDF, and the original PDF is returned if recompression would make it larger.
  • PDF merge preserves the input order of the uploaded files.