An example microservice which extracts the text contents of uploaded PDF files.
It is built using Quarkus and uses Apache PDFBox as well as Jonathan Link's PDFLayoutTextStripper.
This service is intended to be run as a native Linux binary via GraalVM. Build the binary like so:
./mvnw package -Pnative -Dnative-image.container-runtime=docker
Then create a Docker container with the binary:
docker build -f src/main/docker/Dockerfile.native -t quarkus-examples/quarkus-pdf-export .
Run the container:
docker run -i --rm -p 8080:8080 -e PORT=8080 quarkus-examples/quarkus-pdf-export
To invoke the service, e.g. use httpie like so (adjust the file name to a PDF on your hard disk):
http -f POST localhost:8080/extract uploadedFile@"/path/to/some/file.pdf" -d
This will create a file extracted.txt with the extracted text in the current directory.
The Quarkus-built native binary is a perfect fit for Serverless environments such as Google Cloud Run. Follow the steps in the Google Cloud Run documentation for setting up Cloud Run and the Google Cloud SDK.
Submit a build of the Docker container to the Google Container Registry:
rm -rf target/reports
gcloud builds submit --tag gcr.io/<your project id>/quarkus-pdf-extract
Then deploy an instance of the service to Cloud Run:
gcloud beta run deploy --image gcr.io/<your project id>/quarkus-pdf-extract
You can then invoke the service as shown before, replacing localhost:8080 with the endpoint shown in the output of the deploy
command (similar to https://quarkus-pdf-extract--uc.a.run.app).