rst2pdf / rst2pdf

Use a text editor. Make a PDF.

Home Page:http://rst2pdf.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serbian Cyrillic letters not supported

hristinanikpi opened this issue · comments

We work on a project where we want to automate creation of a poetry book from a bunch of poems in rst format. We have to folders eng (with poems in English) and rs (with poems in Serbian). Our goal is to have all the poems in one document in rst format and convert it to pdf. Everything is done on Ubuntu Linux.

The problem that appears is that Serbian characters are not recognized. The command that we used is:
rst2pdf book.rst -o book.pdf

We tried setting up the font:
rst2pdf book.rst -o book.pf --font-path=path-to-a-specific-ttf-file
This produced a pdf but all the unrecognized characters were marked black.

Afterwards, we tried setting up both font and language:
rst2pdf book.rst -o book.pdf --font-path=/usr/share/fonts/X11/Cyrillic --language='sr'
We tried with a few different fonts and tried using 'sr-Rs' and 'rs' for language, but unsuccessfully. Here we got the following error:
languages.py:39 Language 'sr' not supported by Docutils

🖥 Versions
python3 -V
Python 3.10.12

pip freeze | grep rst2pdf
rst2pdf==0.101

pip freeze | grep reportlab
reportlab==3.6.8

I'll be honest: the maintainers here are English speakers so our character set knowledge is limited. Does this past issue help at all with your use case? #1125

Hi @hristinanikpi, my answer comes a little bit late, but maybe the experience I had with Serbian Latin characters would help. I had the same problem with the unrecognized characters (they were replaced with black squares). It can be solved through by using a separate styling file which contains the font instructions for different elements, for example:

styles:
  base: {fontName: DejaVuSans, fontSize: 12}
  footer: {alignment: TA_CENTER, parent: base}
  heading1: {fontName: DejaVuSans, parent: heading}
  title: {fontName: DejaVuSans, fontSize: 32}
  table-heading: {fontName: DejaVuSans-Bold, parent: heading}

And then run the rst2pdf command like this:

rst2pdf -S book-style.yaml book.rst -o book.pdf

Where book-style.yaml contains the styles configuration.

The fontName DejaVuSans displays the characters well, so it did the trick for the Serbian Latin, maybe it would help with the Cyrillic as well. If not, try experimenting with some other fonts. Hope this helps!