jorisschellekens / borb

borb is a library for reading, creating and manipulating PDF files in python.
https://borbpdf.com/
Other
3.4k stars 147 forks source link

BUG #131

Closed sergeiivanitsa closed 2 years ago

sergeiivanitsa commented 2 years ago

Where to get the Font parameter from ?

I am a novice developer, and therefore I want to apologize right away, perhaps for someone the answer to my question will seem obvious, but I have despaired of finding a solution on my own.

My project requires a font that supports unicode characters. To be more precise, Cyrillic characters.

While studying the bomb documentation, I found an example for connecting my own fonts in the section 2.4.1 Setting the Font of a Paragraph Steps to reproduce the behaviour:

But when I transfer the code from the example to VSCode, I see that the Font parameter is not imported from anywhere. And the code doesn't work

image

I tried to import Font from msilib.schema, but the terminal gives an error.

from msilib.schema import Font

image

jorisschellekens commented 2 years ago

Hi there,

Line 28 needs to be a Path towards a ttf (TrueTypeFont) font file.

In order to test whether this code works, I included a custom font in the tests (called JsFont-Regular). There are 2 issues however:

  1. The test files are not included in the build as that would take up a lot of space in the package.
  2. Even if they were, JsFont does not include special characters. It's a font that mimics my handwriting for the basic characters.

You simply need to provide borb with a Path to the actual font file you'd like to use.

You can find a ton of free fonts over at Google Fonts. Simply download one you like (check whether it can display the characters you need) and then copy the path into your code.

Kind regards, Joris Schellekens