An Alfresco T-Engine that converts PDF, Office documents, HTML, and images to Markdown using MarkItDown, pymupdf4llm with RapidOCR, and Markdown to PDF using md2pdf.
- Features
- Supported Transformations
- Getting Started
- API Reference
- Docker Deployment
- Testing
- Contributing
- Security
- License
- Bidirectional conversion: PDF/Office/HTML/Images to Markdown and Markdown to PDF
- Dockerized: Ready-to-use Docker container with all dependencies
- Alfresco integration: Native T-Engine for Alfresco Content Services
- Lightweight: Uses MarkItDown and pymupdf4llm instead of heavy ML-based pipelines
- OCR: Extract the text of images, scanned PDFs and PDFs with outlined text (printer proofs) with RapidOCR
- Extensible: Easy to add new transformation capabilities
This project provides an Alfresco Content Services (ACS) transformer that converts a wide variety of document types into Markdown format using four lightweight Python libraries:
- MarkItDown (MIT License) - Converts Office documents, HTML and CSV to Markdown
- pymupdf4llm (AGPL-3.0) - Converts PDF documents and images to Markdown
- RapidOCR (Apache-2.0) - OCR engine used by pymupdf4llm for pages without a text layer
- md2pdf (MIT License) - Converts Markdown to PDF
The transformer runs inside a Docker container and can be integrated into Alfresco as a local transformer.
The following source formats are converted to text/markdown (or text/x-markdown):
| Source | MIME Type |
|---|---|
| Word (.docx) | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
| Excel (.xlsx) | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
| PowerPoint (.pptx) | application/vnd.openxmlformats-officedocument.presentationml.presentation |
| HTML | text/html |
| XHTML | application/xhtml+xml |
| CSV | text/csv |
The following source formats are converted to text/markdown (or text/x-markdown):
| Source | MIME Type |
|---|---|
application/pdf |
|
| PNG | image/png |
| JPEG | image/jpeg |
| TIFF | image/tiff |
| BMP | image/bmp |
Images, and PDF pages without a text layer (scans, text converted to outlines in printer proofs), are read by OCR with RapidOCR. PDF pages that already have a readable text layer (at least 100 characters) are not OCRed, even when they hold a logo or a picture, and are converted as before.
OCR runs on the CPU and takes about 10 to 20 seconds per page with 2 threads. Each OCR conversion uses about 1 GB of memory, so the number of PyMuPDF4LLM conversions running at the same time is limited: the next requests wait for a free slot, up to the conversion timeout, then fail with 503. With the defaults (2 conversions, 2 OCR threads each), 6 simultaneous OCR requests peak at about 1.7 GiB for the whole container, against 3.8 GiB without the limit. The property can also be set with the TRANSFORM_CORE_PYMUPDF4LLM_MAX_CONCURRENT environment variable.
| Property | Default | Description |
|---|---|---|
transform.core.pymupdf4llm.max.concurrent |
2 |
Maximum number of PyMuPDF4LLM conversions (PDF and images) running at the same time. Allow about 1 GB of container memory per conversion |
transform.core.pymupdf4llm.timeout.ms |
900000 |
Maximum duration of one conversion, and maximum wait for a free conversion slot |
OCR is configured with these environment variables:
| Variable | Default | Description |
|---|---|---|
PYMUPDF4LLM_OCR_ENABLED |
true |
Set to false to disable OCR: images and pages without a text layer then give an empty Markdown |
PYMUPDF4LLM_OCR_DPI |
300 |
Resolution at which pages are rendered for OCR. Lower it to speed up OCR, at the cost of small text |
PYMUPDF4LLM_OCR_MAX_PAGES |
20 |
Maximum number of pages OCRed per document; the next pages without a text layer are skipped. 0 removes the limit |
PYMUPDF4LLM_OCR_THREADS |
2 |
CPU threads used by each OCR conversion. Without a limit, ONNX Runtime would start one thread per CPU core of the host |
| Source | Target | Description |
|---|---|---|
text/markdown |
application/pdf |
Convert Markdown documents to PDF |
To create the transformer Docker image, run:
./run.sh build
This uses alfresco-base-java and installs Python 3.10 with MarkItDown, pymupdf4llm, RapidOCR and md2pdf via pip. RapidOCR ships its ONNX models, so OCR needs no download at runtime.
To run the image:
./run.sh start
- Port 8090 is for transformations
To enable remote debugging locally, start the container with:
docker compose -f target/docker-compose.yml run -p 8099:8099 -e JAVA_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:8099" becpg-transform-markdownExample of request to transform a PDF file to Markdown:
curl --location --request POST 'http://localhost:8090/transform' \ --form 'file=@"/path/to/sample.pdf"' \ --form 'sourceMimetype="application/pdf"' \ --form 'targetMimetype="text/markdown"'
You can declare the Docker service as follow in a docker-compose.yml file:
becpg-transform-markdown: image: becpg/becpg-transform-markdown:1.0.6 ports: - "8090:8090" environment: - SERVER_PORT=8090 healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8090/live"] interval: 30s timeout: 10s retries: 5
Add the following JVM property to your Alfresco instance:
-DlocalTransform.becpg-transform-markdown.url=http://localhost:8090/
This allows Alfresco to discover and use the transformer.
GET http://localhost:8090/live
POST http://localhost:8090/transform
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
file |
File | Yes | Source file to transform |
sourceMimetype |
String | Yes | MIME type of source file |
targetMimetype |
String | Yes | Desired output MIME type |
Example:
curl --location --request POST 'http://localhost:8090/transform' \ --form 'file=@"/path/to/document.pdf"' \ --form 'sourceMimetype="application/pdf"' \ --form 'targetMimetype="text/markdown"'
Run integration tests (requires MarkItDown and pymupdf4llm installed locally):
mvn testRun a specific test:
mvn test -Dtest=MarkitdownTransformerITThe DockerTransformIT builds a Docker image, starts a container, and verifies every supported transformation end-to-end. It is a parameterized test covering all 24 source/target combinations from the config (12 unique transformations, each with both text/markdown and text/x-markdown targets). It also checks that the text of a synthetic food label is extracted by OCR from a PDF with outlined text, a PNG and a TIFF, and that 6 simultaneous OCR conversions all succeed while the container memory peak stays under 3.5 GiB.
mvn package -DskipTests
mvn test -Dtest=DockerTransformITOutput files are written to src/test/resources/output/ for manual inspection.
We welcome contributions! Please see our Contributing Guidelines and Code of Conduct for details.
For security-related issues, please see our Security Policy.
- This project is licensed under the GNU Lesser General Public License v3.0 - see the LICENSE file for details.
- This project uses MarkItDown and md2pdf, licensed under the MIT License.
- This project uses pymupdf4llm, licensed under the AGPL-3.0 License.
- This project uses RapidOCR, licensed under the Apache-2.0 License.
- Base image from Alfresco Docker Base Java
- beCPG - The open source PLM solution
- MarkItDown - Microsoft's lightweight document-to-Markdown converter
- pymupdf4llm - PDF and image to Markdown conversion
- RapidOCR - OCR engine
- md2pdf - Markdown to PDF conversion
- Alfresco - The open content services platform
Made with care by the beCPG team