This project demonstrates how to integrate a .NET document conversion tool inside a Java application using Docker.
It combines a .NET console app that converts DOCX to PDF (using TX Text Control) with a Java wrapper that manages Base64-encoded input and output streams.
Components:
-
.NET Console App (
DocxToPdfStdout
)
Converts DOCX (Base64 input) to PDF (Base64 output).
Built forlinux-x64
and located at/app/tool/DocxToPdfStdout/DocxToPdfStdout.dll
. -
Java Wrapper (
DocxToPdfClient
)
Takes a.docx
file, encodes it to Base64, runs the .NET converter viadotnet
,
and writes the resulting.pdf
file. -
Docker Container
Bundles:- Java 21 Runtime (Eclipse Temurin)
- .NET 8 Runtime
- No additional libraries (TX Text Control does not require fonts or GDI)
.
├── Dockerfile
├── pom.xml
├── publish/
│ └── linux-x64/
│ └── DocxToPdfStdout/
│ ├── DocxToPdfStdout.dll
│ ├── DocxToPdfStdout.runtimeconfig.json
│ └── ...
├── src/
│ └── main/java/com/example/DocxToPdfClient.java
└── data/
├── input.docx
└── out/
Run the following commands in the project root directory:
docker build --no-cache -t docx2pdf-java:runtime .
This creates the runtime image containing:
- .NET 8 runtime
- Java 21 JRE (headless)
- The published .NET converter
- The compiled Java application
To convert the sample document included in /data/input.docx
, run:
docker run --rm -v "${PWD}\data\out:/out" docx2pdf-java:runtime
The converted PDF will be available at:
data/out/output.pdf
You can map your own input and output files:
docker run --rm -v "${PWD}:/work" -w /work docx2pdf-java:runtime ./my.docx ./out/my.pdf
To open a shell inside the container for manual testing:
docker run -it --entrypoint /bin/bash docx2pdf-java:runtime
You can test the converter manually:
base64 -w0 /data/input.docx > /tmp/in.b64
dotnet /app/tool/DocxToPdfStdout/DocxToPdfStdout.dll /tmp/in.b64 > /tmp/out.b64
base64 -d /tmp/out.b64 > /tmp/out.pdf && ls -lh /tmp/out.pdf
-
Java app
- Reads the DOCX file
- Writes Base64-encoded content to a temporary
.b64
file - Executes the .NET converter via:
dotnet /app/tool/DocxToPdfStdout/DocxToPdfStdout.dll temp.b64
- Streams Base64 output → decodes → writes a
.pdf
file
-
.NET converter
- Reads Base64 DOCX bytes
- Uses TX Text Control to load and render to PDF
- Outputs Base64-encoded PDF bytes to
stdout
PDF saved to: /out/output.pdf
- Requires TX Text Control Server libraries included in your publish folder.
- Works on linux-x64.
- The .NET DLL path is hard-coded to:
/app/tool/DocxToPdfStdout/DocxToPdfStdout.dll
- Only
openjdk-21-jre-headless
is installed (no fonts or GDI dependencies).
Remove temporary containers and images:
docker system prune -f