Skip to content

Latest commit

 

History

History
178 lines (132 loc) · 5.19 KB

File metadata and controls

178 lines (132 loc) · 5.19 KB

Camel Example Spring Boot and Docling

This example shows how to work with Apache Camel and the Docling component using Spring Boot to convert documents to Markdown format.

The example demonstrates document conversion from various formats (PDF, DOCX, PPTX, HTML, MD) to Markdown using the Docling service.

Features

  • Document to Markdown Conversion - Automatically converts PDF, DOCX, PPTX, HTML, and MD files to Markdown format

  • Metadata Extraction - Optional route to extract structured data as JSON from documents

  • File-based Processing - Watch directories for new files and process them automatically

  • Java DSL Routes - Routes defined using Camel Java DSL

Prerequisites

Before running this example, you need:

  1. A running Docling-Serve instance at http://localhost:5001

docker run -p 5001:5001 -e DOCLING_SERVE_ENABLE_UI=1 ghcr.io/docling-project/docling-serve:latest

How to run

You can run this example using:

mvn spring-boot:run

Usage

Converting Documents to Markdown

  1. Start the application

  2. Place any PDF, DOCX, PPTX, HTML, or MD file in the src/main/resources/documents/ directory

  3. The application will:

    • Detect the new file

    • Convert it to Markdown using Docling

    • Save the converted file to src/main/resources/output/ directory with .md extension

    • Delete the original file from src/main/resources/documents/

Extracting Structured Metadata

  1. Place documents in src/main/resources/documents/extract/

  2. The application will:

    • Extract structured data from the document

    • Save the metadata as JSON to src/main/resources/output/metadata/

Project Structure

docling/
└── src/
    └── main/
        ├── java/
        │   └── org/apache/camel/example/springboot/docling/
        │       ├── DoclingServeApplication.java
        │       └── DoclingServeRoute.java
        └── resources/
            ├── application.properties
            ├── documents/              # Input directory - place documents here
            │   └── extract/           # Optional: place documents here for metadata extraction
            └── output/                # Output directory for converted Markdown files
                └── metadata/         # Output directory for extracted metadata JSON files

Configuration

Edit src/main/resources/application.properties to configure:

  • docling.serve.url - URL of the Docling service

  • documents.directory - Input directory for documents to convert (default: src/main/resources/documents)

  • output.directory - Output directory for converted files (default: src/main/resources/output)

Routes

The application includes two routes defined in src/main/java/org/apache/camel/example/springboot/docling/DoclingServeRoute.java:

document-to-markdown-converter

  • Watches: src/main/resources/documents/ directory

  • Accepts: PDF, DOCX, PPTX, HTML, MD files

  • Action: Converts to Markdown

  • Output: src/main/resources/output/{filename}.md

document-metadata-extractor

  • Watches: src/main/resources/documents/extract/ directory

  • Accepts: PDF, DOCX, PPTX files

  • Action: Extracts structured data as JSON

  • Output: src/main/resources/output/metadata/{filename}.json

Trying out the example on OpenShift

First, start with creating a new OpenShift project:

$ oc new-project csb-example-docling

Deploy the Docling-Serve instance:

$ cat << EOF| oc apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: docling
spec:
  replicas: 1
  selector:
    matchLabels:
      app: docling
  template:
    metadata:
      labels:
        app: docling
    spec:
      containers:
        - name: docling
          image: quay.io/docling-project/docling-serve:latest
          ports:
            - containerPort: 5001
          env:
            - name: HOME
              value: /tmp
            - name: XDG_CACHE_HOME
              value: /tmp/.cache
---
apiVersion: v1
kind: Service
metadata:
  name: docling
spec:
  selector:
    app: docling
  ports:
    - port: 5001
      targetPort: 5001
EOF

Wait for the Docling pod to be ready (the container downloads models on startup, which may take a few minutes):

$ oc wait --for=condition=available deployment/docling --timeout=300s

How to run

The application is deployed using the openshift-maven-plugin that takes care of creating all the necessary OpenShift resources.

Simply use the following command to deploy the application:

$ mvn clean package -Popenshift

After the application pod reaches the Ready state, you can try the same steps as in the local machine deployment.

To view the application logs, use oc logs deployment/csb-docling

Using Camel components

Apache Camel provides 200+ components which you can use to integrate and route messages between many systems and data formats. To use any of these Camel components, add the component as a dependency to your project.

Help and contributions

If you hit any problem using Camel or have some feedback, then please let us know.

We also love contributors, so get involved :-)

The Camel riders!