rkorv/pdf_translator

Offline PDF translator to Russian, German, French, Spanish, Italian, Portuguese, Turkish languages.

Python

8

8 commits

updated Jun 16, 2024

See the code

README

Introduction

This is a simple script for offline PDF translation from English to Russian [ru], German [de], French [fr], Spanish [es], Italian [it], Portuguese [pr], Turkish [tr] languages.

We use public models to visually analyze the layout, discard formulas and images, and then translate the remaining text.

image

Resulted PDF will store combined images: original page and translated.

Personally, it helps me to read books with a little support in difficult moments :)

You can check 2 translated PDFs in the test folder.

Installation

git clone https://github.com/rkorv/pdf_translator
cd pdf_translator

conda create -n pdf_translator python=3.10
conda activate pdf_translator

pip install -r requirements.txt

Usage

python ./pdf_translator.py <path_to_pdf> <language_code> -o <output_pdf>
# Example
python ./pdf_translator.py input.pdf de -o output.pdf

This script will translate the input PDF file to the German language. Use following language codes: ru, de, fr, es, it, pr, tr.

Process URL directly

python ./pdf_translator.py "https://arxiv.org/pdf/2008.05711.pdf" es

This script will save translated file '2008.05711_es.pdf' in the current directory.

Python API

from pdf_translator import PDFTranslator

pdf_path = "input.pdf"

pdf_translator = PDFTranslator("es")

doc, translations = pdf_translator.translate_pdf(pdf_path)
pdf_translator.save_to_pdf(doc, translations, "output.pdf")

References

rkorv/pdf_translator

Offline PDF translator to Russian, German, French, Spanish, Italian, Portuguese, Turkish languages.

Python

8

8 commits

updated Jun 16, 2024

See the code

README

Introduction

This is a simple script for offline PDF translation from English to Russian [ru], German [de], French [fr], Spanish [es], Italian [it], Portuguese [pr], Turkish [tr] languages.

We use public models to visually analyze the layout, discard formulas and images, and then translate the remaining text.

image

Resulted PDF will store combined images: original page and translated.

Personally, it helps me to read books with a little support in difficult moments :)

You can check 2 translated PDFs in the test folder.

Installation

git clone https://github.com/rkorv/pdf_translator
cd pdf_translator

conda create -n pdf_translator python=3.10
conda activate pdf_translator

pip install -r requirements.txt

Usage

python ./pdf_translator.py <path_to_pdf> <language_code> -o <output_pdf>
# Example
python ./pdf_translator.py input.pdf de -o output.pdf

This script will translate the input PDF file to the German language. Use following language codes: ru, de, fr, es, it, pr, tr.

Process URL directly

python ./pdf_translator.py "https://arxiv.org/pdf/2008.05711.pdf" es

This script will save translated file '2008.05711_es.pdf' in the current directory.

Python API

from pdf_translator import PDFTranslator

pdf_path = "input.pdf"

pdf_translator = PDFTranslator("es")

doc, translations = pdf_translator.translate_pdf(pdf_path)
pdf_translator.save_to_pdf(doc, translations, "output.pdf")

References