Technical Manual v1.0.0

Document
& File Translator

Translate PDF, Word, Excel, and PowerPoint files while preserving the original format and style — powered by Ollama, MLX, or LMStudio, with automatic source-language detection.

Read Documentation
Request a Test Session

1. Overview

What is XteVision TransDocs and who is it for?

1.1 What is XteVision TransDocs?

XteVision TransDocs is a Python script and web GUI for translating Microsoft Office files and PDFs while keeping the original format and style. It uses the Ollama, MLX, or LMStudio API and can automatically detect the source language from a minimum of 50 words, or accept a manually specified source language.

1.2 Designed for Scale

This tool is built for production-scale workloads as well as personal translation tasks. It supports multiple UI languages (EN, CN, DE) and three interchangeable AI backends, so it fits both single-user and enterprise deployments.

1.3 Target Users

  • Primary: Teams that translate many business documents (Word, Excel, PowerPoint, PDF) across languages on a regular basis
  • Secondary: Developers who need an API-driven translation pipeline that preserves document structure

2. Features

What TransDocs can do

Auto Language Detection

Detects the source language by analyzing at least 50 words from the document.

Manual Source Language

Override detection with the -s / --src_lang argument for OCR-friendly output.

Full Element Translation

Translates paragraphs, tables, headers, and footers while preserving layout.

Hybrid PDF Pipeline

Uses embedded text when available; scanned pages fall back to Poppler + Tesseract OCR.

Selectable LLM Backends

Run against Ollama, MLX, or LMStudio — whichever fits your infrastructure.

Optional Vision Doublecheck

For important PDFs, verify each page with the vision model before translating.

3. Requirements

Software and system packages you need

  • Python version 3.7 or higher
  • Python packages: python-docx, python-pptx, openpyxl, Pillow, pytesseract, python-dotenv, requests, langdetect, flask, werkzeug
  • System packages for PDF: poppler-utils (pdftoppm or pdftocairo in PATH) and tesseract-ocr with the language packs your documents need
  • LLM backend access: Ollama, MLX, or LMStudio. Set TRANSDOC_API_TOKEN if your backend requires authentication

4. Installation

Set up the environment and install dependencies

4.1 Download & Prepare

cd TransDocs
python -m venv venv
source venv/bin/activate   # On Windows: venv\Scripts\activate

4.2 Install Dependencies

pip install -r requirements.txt

4.3 Install System Packages (Debian/Kali)

sudo apt-get install -y poppler-utils tesseract-ocr tesseract-ocr-eng

Add more Tesseract language packs as needed for your source documents.

4.4 Configuration

Adjust the settings in .env as needed. See the Configuration section for the full list of supported keys.

5. Configuration

Runtime settings in the .env file

Settings can be managed through .env, similar to the invoicer setup. Supported keys include:

KeyPurpose
TRANSDOC_PROVIDERSelected backend provider
TRANSDOC_OLLAMA_URLOllama base URL
TRANSDOC_MLX_URLMLX backend URL
TRANSDOC_LM_STUDIO_URLLMStudio backend URL
TRANSDOC_DEFAULT_MODELModel used when none is specified
TRANSDOC_API_TOKENAuthentication token for the backend
TRANSDOC_UPLOAD_DIRDirectory for uploaded files
TRANSDOC_OUTPUT_DIRDirectory for translated output
TRANSDOC_SECRET_KEYFlask session secret key
TRANSDOC_HOSTHost the web app binds to
TRANSDOC_PORTPort the web app binds to
TRANSDOC_DEBUGEnable Flask debug mode
TRANSDOC_LOG_FILEPath to the log file
TRANSDOC_TESSERACT_LANGSExplicit OCR languages (e.g. eng+deu)

6. Command-Line Interface

Translate documents from the terminal

The transdoc.py script can be run from the command line. For PDF input, the workflow is hybrid: text PDFs are extracted directly, while scanned or image-only pages fall back to OCR. If you already know the source language, passing -s improves OCR language selection. Both the CLI and Flask app load .env automatically, and the CLI supports backend selection with -p/--provider and -b/--base_url.

6.1 Arguments

FlagNameDescription
-iinput_filePath to the input document (required)
-ooutput_filePath to save the translated document (required)
-ttarget_langTarget language code (e.g. en, de, fr) (required)
-kapi_tokenAPI token for authentication (required)
-mmodelModel name to use (e.g. llama3.2)
-ssrc_langSource language code (detected automatically if omitted)

6.2 Examples

Translate with automatic source-language detection:

python transdoc.py -i input.docx -o output.docx -t en -k your_api_token

Translate from a specified source language:

python transdoc.py -i input.docx -o output.docx -t en -k your_api_token -s fr

Translate using a specific model:

python transdoc.py -i input.docx -o output.docx -t en -k your_api_token -m custom_model

7. Web GUI

Optional Flask-based interface

A web-based interface enhances usability by letting users upload documents and receive translations without the command line. This is a suggested implementation using Flask and is currently untested.

7.1 Setup

pip install flask werkzeug

7.2 Running the Web App

python app.py

Open a browser at http://localhost:5000, then:

  • Upload Document: Choose the .docx file to translate
  • Source Language: Optionally enter the source language code
  • Target Language: Enter the target language code
  • Model: Optionally specify a different model
  • API Token: Enter your backend token
  • Translate: Click the button to start the process
  • Download: Download the translated document once finished
Note: The web GUI is a suggested, untested implementation. For mission-critical use, prefer the stable CLI path.

8. Logging

Monitoring and debugging output

The script logs detailed information to both the console and a file named translation_debug.log. Logging defaults to the DEBUG level, capturing all message levels.

  • Console Output: Real-time feedback while the script runs
  • Log File: A persistent record useful for troubleshooting

8.1 Adjusting Logging Levels

To reduce console verbosity, change the logging level in the script:

console_handler.setLevel(logging.INFO)  # Change DEBUG to INFO

9. Troubleshooting

Common issues and solutions

9.1 Script Does Not Execute

  • Check Logging Output: Ensure the logging level is set to DEBUG.
  • Verify File Paths: Confirm the input file path exists.
  • Check Dependencies: Ensure all required Python packages are installed.
  • API Token: Verify the token is correct and has permissions.

9.2 Language Detection Fails

  • Insufficient Text: The document may have fewer than 50 words. Use -s to specify the source language.

9.3 PDF OCR Is Slow or Inaccurate

  • Install Language Packs: Make sure the right Tesseract packs are installed.
  • Set OCR Languages Explicitly: Use TRANSDOC_TESSERACT_LANGS, e.g. export TRANSDOC_TESSERACT_LANGS=eng+deu.
  • Check Poppler Tools: Ensure pdftoppm or pdftocairo is in PATH.

9.4 API & Output Issues

  • API Errors: Verify token validity, network connection, and API URL.
  • Output File Not Created: Check write permissions and review translation_debug.log.
  • Web App Issues: If the port is in use, change it in app.run(debug=True, port=5001).