Change the font on odfpy?

571 Views Asked by At

How can I change the font on odfpy for example, using Arial or comic sans. I've seen some examples but they only use the params "fontsize" and "fontweight". I can't find any example changing the font and the param "font" doesn't seem to work.

1

There are 1 best solutions below

2
On

Section 5.15.39 in api-for-odfpy.odt lists the style.TextProperties as:

    5.15.39  style.TextProperties
    Requires the following attributes: No attribute is required.
    Allows the following attributes: backgroundcolor, color, condition, country,
 countryasian, countrycomplex, display, fontcharset, fontcharsetasian,
 fontcharsetcomplex, fontfamily, fontfamilyasian, fontfamilycomplex,
 fontfamilygeneric, fontfamilygenericasian, fontfamilygenericcomplex, fontname,
fontnameasian, fontnamecomplex, fontpitch, fontpitchasian, fontpitchcomplex,
 fontrelief, fontsize, fontsizeasian, fontsizecomplex, fontsizerel, fontsizerelasian,
 fontsizerelcomplex, fontstyle, fontstyleasian, fontstylecomplex, fontstylename,
 fontstylenameasian, fontstylenamecomplex, fontvariant, fontweight, fontweightasian,
 fontweightcomplex, hyphenate, hyphenationpushcharcount, hyphenationremaincharcount, language, languageasian, languagecomplex, letterkerning, letterspacing, scripttype,
 textblinking, textcombine, textcombineendchar, textcombinestartchar, textemphasize,
 textlinethroughcolor, textlinethroughmode, textlinethroughstyle, textlinethroughtext,
 textlinethroughtextstyle, textlinethroughtype, textlinethroughwidth, textoutline,
 textposition, textrotationangle, textrotationscale, textscale, textshadow,
 texttransform, textunderlinecolor, textunderlinemode, textunderlinestyle, 
textunderlinetype, textunderlinewidth, usewindowfontcolor.

I assume they are accessible in the same way as fontsize and fontweight, as in:

h1style.addElement(TextProperties(attributes={'fontsize':"24pt",'fontweight':"bold" }))

Although, I personally have no intention of loading software this old to test it.