Skip to content

TextControl/TXTextControl.Core.Java.Convert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧾 DOCX → PDF Converter (Java + .NET)

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.


⚙️ Overview

Components:

  • .NET Console App (DocxToPdfStdout)
    Converts DOCX (Base64 input) to PDF (Base64 output).
    Built for linux-x64 and located at /app/tool/DocxToPdfStdout/DocxToPdfStdout.dll.

  • Java Wrapper (DocxToPdfClient)
    Takes a .docx file, encodes it to Base64, runs the .NET converter via dotnet,
    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)

🧩 Project Structure

.
├── Dockerfile
├── pom.xml
├── publish/
│   └── linux-x64/
│       └── DocxToPdfStdout/
│           ├── DocxToPdfStdout.dll
│           ├── DocxToPdfStdout.runtimeconfig.json
│           └── ...
├── src/
│   └── main/java/com/example/DocxToPdfClient.java
└── data/
    ├── input.docx
    └── out/

🏗️ Build

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

▶️ Run

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

🧱 Convert your own file

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

🧪 Debug Shell

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

🧠 How It Works

  1. 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
  2. .NET converter

    • Reads Base64 DOCX bytes
    • Uses TX Text Control to load and render to PDF
    • Outputs Base64-encoded PDF bytes to stdout

📦 Example Output

PDF saved to: /out/output.pdf

🧰 Notes

  • 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).

🧼 Cleanup

Remove temporary containers and images:

docker system prune -f

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published