Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Mar 02, 2024 7:34 am

Hi,
I am trying to embed fonts in docx file in python using spire.doc but it doesn't work
My code like this :
Code: Select all
        document.EmbedFontsInFile = True
        private_font = PrivateFontPath(font, FontStyle.Regular, fonts_path)
        document.PrivateFontList.Add(private_font)

it gives me error : PrivateFontList has no attribute 'Add'
I tried using append, it doen't work too
Please help me
Thanks

ahmedf4wzy
 
Posts: 1
Joined: Sat Mar 02, 2024 7:30 am

Mon Mar 04, 2024 5:50 am

Hello,

Thank you for your inquiry.
Please note that the data type for the document.PrivateFontList.__add__() method is a List data type. Please refer to the code snippet below for embedding private fonts into a Word document:
Code: Select all
...
fonts = []
private_font = PrivateFontPath(font, FontStyle.Regular, fonts_path)
fonts.append(private_font)
document.PrivateFontList.__add__(fonts)
document.EmbedFontsInFile = True
document.SaveToFile("result.docx", FileFormat.Docx2016)

If you have any further questions or need additional guidance, please do not hesitate to reach out.
Thank you for your attention.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc

cron