Skip to content

Program to translate PDF while maintaining the layout and fonts. You can use several offline translation engines ( LibreTranslate, translateLocally, NLLB-serve ) + Google

Notifications You must be signed in to change notification settings

MoonDragon-MD/PyTranslatePDF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PyTranslatePDF

Program to translate PDF while maintaining the layout and fonts. You can use several offline translation engines ( LibreTranslate, translateLocally, NLLB-serve ) + Google

Works on both GNU/Linux (Ex:Ubuntu/Debian) and Windows

Description

I created this program to translate mainly offline PDFs without losing the layout, font, font color, original images.

It was not easy and maybe still not perfect.

One very important thing to keep the layout is fonts: you have to have the PDF fonts in the system to have a proper layout of the text. I put an automatic search method but it doesn't always succeed, so I added a mapping for fonts, here you can add your own (you can help by enabling loggin).

I set that special carraters don't go to the translator because they can give problems.

There are three modes of editing

  • translated text only

  • replacing original text with translated

  • overlay via rectangles with translated text on top.

The latter is needed in special cases where there is writing both on the images and on top of them, or in special cases where using substitution you can no longer see anything (depending on how they created the PDF)

For camouflage I set that the color of the rectangle is calculated based on the average of the background colors under that text box.

Here is an example:

alt text

Dependencies

  • Python installed on the system, as a minimum python version 3.8
  • sudo apt install fonts-dejavu (with Linux)
  • pip install PyMuPDF requests googletrans==3.1.0a0 numpy Pillow pdfrw pikepdf

Optional dependencies

Installation

GNU/Linux ./install_PyTranslatePDF.sh (Adds shortcut with icon to main menu)

Usage

Portable GNU/Linux StartUbuntu.sh (double-click and then click run) or in terminal ./StartUbuntu.sh

Portable Windows StartWindows.bat (double-click)

Direct start GUI GNU/Linux python3 PyTranslatePDF_GUI.py

Direct start GNU/Linux python3 PyTranslatePDF.py name.pdf name_translate.pdf en it [font_customized] [translate_locally_path] (these last two are optional)

Direct start GUI Windows python PyTranslatePDF_GUI.py

Direct start Windows python PyTranslatePDF.py name.pdf name_translate.pdf en it [font_customized] [translate_locally_path] (these last two are optional)

Screenshot

alt text

About

Program to translate PDF while maintaining the layout and fonts. You can use several offline translation engines ( LibreTranslate, translateLocally, NLLB-serve ) + Google

Resources

Stars

Watchers

Forks