Include non-standard font in Word document

Technical support for Spire.Doc

Moderator: iceblue support

Include non-standard font in Word document

Postby yanu » Wed Jul 19, 2017 12:07 pm

Hi.

We're using a non-standard font (Roboto) in our template. If we decide to include it directly in the word template (by using Word-features) we get some errors like "the document is broken" when opening after the generation (which is done as a stream that gets downloaded in the browser). Even tough the generated document can be repaired (and works in the end), it is not really nice for the user.

Therefore, we decided to include them in the Spire.Doc process by using the following code below.

Code: Select all
            document.EmbedFontsInFile = true;
            document.PrivateFontList.Add(new PrivateFontPath("Roboto",
                ***));
            document.PrivateFontList.Add(new PrivateFontPath("Roboto Thin",
               ***));


However, this doesn't seem to work, as we are not managing the styles in Spire.Doc but using the ones we built in to the docx file. Is there a possiblity to "just" include the fonts needed, without having to declare every single style in Spire.Doc? (We're generating a docx out of it).

Thanks for your suggestions.
yanu
 
Posts: 5
Joined: Wed Jun 01, 2016 11:21 am

Re: Include non-standard font in Word document

Postby Betsy.jiang » Thu Jul 20, 2017 6:12 am

Dear yanu,

Thanks for your inquiry.
Sorry that it is not possible to apply the font style to the paragraphs automatically when creating a docx document, you must to declare every style for corresponding paragraph.
If I misunderstand your meaning, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1551
Joined: Tue Sep 06, 2016 8:30 am

Re: Include non-standard font in Word document

Postby yanu » Thu Jul 20, 2017 6:36 am

Hi Betsy

Thanks for your response.
Just to rephrase my question: Is there a way to include a custom font to a Word template with Spire.Doc? Because if I only add it like shown in my previous post, that font will not be rendered in the document.
yanu
 
Posts: 5
Joined: Wed Jun 01, 2016 11:21 am

Re: Include non-standard font in Word document

Postby Betsy.jiang » Thu Jul 20, 2017 6:47 am

Dear yanu,

Thanks for your response.
Please refer to below link.
https://www.e-iceblue.com/Tutorials/Spi ... ormat.html
The Step 3, is the code to apply the custom font to the paragraph.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1551
Joined: Tue Sep 06, 2016 8:30 am

Re: Include non-standard font in Word document

Postby yanu » Thu Jul 20, 2017 7:28 am

Thank you for reaching back so quickly.
I just figured out what my error was: When creating the document in Word, I didn't use the exact same .ttf-font which I included in Spire.Doc. There are probably different versions of that font around. Once I changed that to be the same .ttf-font, it worked.
yanu
 
Posts: 5
Joined: Wed Jun 01, 2016 11:21 am

Re: Include non-standard font in Word document

Postby Betsy.jiang » Thu Jul 20, 2017 7:33 am

Dear yanu,

Glad to hear that the issue is solved.
Welcome to write to us again if there is any question.

Sincerely,
Betsy
E-iceblue support team
User avatar
Betsy.jiang
 
Posts: 1551
Joined: Tue Sep 06, 2016 8:30 am


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests