pmaupin / pdfrw

pdfrw is a pure Python library that reads and writes PDFs
Other
1.84k stars 271 forks source link

How to change the font? #234

Open f1nked opened 2 years ago

f1nked commented 2 years ago

I want to make a document using a TrueType font (.ttf). The font is not system, is in a separate file. How can I integrate it into the document? Changing FONT_NAME does not change the font in the resulting document. Any help would be very helpful. Thanks.

page.Resources.Font.F1.Subtype = PdfName.TrueType
page.Resources.Font.F1.BaseFont = PdfName.FONT_NAME
sl2c commented 10 months ago

There's no simple way to do it in pdfrw as the setting up of fonts in PDF is a rather laborous task. However, see https://github.com/sl2c/pdfrwx/blob/master/pdffont.py for an example of how this can be done in pdfrwx.