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.

Fri Nov 24, 2023 3:23 pm

We use Spire.Doc to create Word document containing information loaded from a database. To compose the document we use some small .docx documents as templates. The only 'constructed' parts of the document are tables (for which we use available APIs).
Until about 1 month ago, all worked properly.
Recently, for some parts of the document, the font style is changed.

Apparently, no system updates was made:
- same .net code
- same Spire.Doc version (7.1.0.40040)
- same OS version

Same problem (different behavior) is reproduced on more machines.
Recreating the document with same data of old documents (correctly generated), now produce document with different font.

Examining the produced document at low level, we found following difference for a 'sample' paragraph:

In 'old' created document:
<w:style w:type="paragraph" w:customStyle="1" w:styleId="Normal3755394c-d0af-4a60-bd19-cccddc90c6cd">
<w:name w:val="Normal_3755394c-d0af-4a60-bd19-cccddc90c6cd"/>
<w:qFormat/>
<w:rPr>
<w:rFonts w:ascii="Arial" w:hAnsi="Arial"/>
</w:rPr>
</w:style>

In 'new' created document:
<w:style w:type="paragraph" w:customStyle="1" w:styleId="Normale26a4d20-81f1-4488-8c5b-a5f549f89f57">
<w:name w:val="Normal_e26a4d20-81f1-4488-8c5b-a5f549f89f57"/>
<w:qFormat/>
</w:style>
(font name is missing)


Do you have any explanation for this?

Thank you.
User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Mon Nov 27, 2023 6:30 am

Hi,

Thank you for your inquiry.
Please kindly note that our product will read the corresponding font data from the font library installed in the system based on the font names used in Word documents, and then draw the content with fonts to a new word page. At the same time, by default, the font data will be embedded in the document. Based on the issue you are currently experiencing, it seems that the font used in the document is not installed on your server. I suggest two solutions to address this issue:
Solution1: Install the fonts used in the Word document on the server or copy a copy of the locally installed font library to the server.
Solution2: Instead of installing the font, place the font files in any folder on the server, and then use the document.SetCustomFontsFolders(fontFolder) method to read it.
The complete sample code is as follows:
Code: Select all
// Create a new Document object
Document document = new Document();

// Load the input file into the Document object
document.LoadFromFile(input);

// Set custom font folders for the Document object
document.SetCustomFontsFolders(fontFolder);

// Save the modified Document object to the output file in DOC format
document.SaveToFile(output, Spire.Doc.FileFormat.Doc);

If you have any issue, just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Wed Nov 29, 2023 9:55 am

Thank you for the answer.
I realize from your reply that I missed a very important information: the font we are talking about is 'Arial', which is erroneusly replaced by 'Times new roman'.
Can your hypothesys be applied to this 'basic' font?

Thank you.
User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Thu Nov 30, 2023 5:47 am

Hi,

Thank you for your inquiry.
My solution can be applied to this "basic" font. The reason why replacing the "Times new Roman" font with the "Arial" font in result document may be because our product didn’t read the "Arial" font data from the font library installed in the system. You can refer to the two solutions I provided to you in my previous reply to solve your problem. In addition, please make sure that current user have permission to access the font.
If you have any issue, just feel free to contact us.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Wed Dec 06, 2023 8:45 am

Hello.
We checked solution no. 1.
As expected, the 'Arial' font appears to be properly installed on the system(s) - same problem occurs on both server and clients.
In ddition, because we use some 'small' docx documents as templates, we can confirm that if we open the template on this machines, the correct font is used and text is visualized correctly.

We would like not to test solution #2 because of following motivations:
- the system has worked properly for at least a couple of years
- modifying the program results in some machines update job

I try to explain again the process:
- a small docx file is loaded using the library - the document uses Arial font for some texts
- some parts of the loaded document are replaced with texts loaded from other data source
- the document is saved as new document

The resulting document uses a different font for replaced text:

original docx:
some 'fixed' text
[PLACEHOLDER-NAME], in Arial font

[PLACEHOLDER-NAME] is replaced with text 'article no...'

new document
some 'fixed' text
'article no...' (in Timesn new roman font)


If required, I can attach both template document and a portion of resulting document.

Thank you.
User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Wed Dec 06, 2023 9:55 am

Hi,

Thank you for your feedback.
Please reinstall the Arial font file, then right-click on the reinstalled Arial font file and select Install for All Users.
If the issue still exists, please offer your file and your full test code that can reproduce your issue to help us do further investigation, you can attach here or send it to us via email (support@e-iceblue.com ). Thank you in advance.

Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Thu Dec 14, 2023 8:07 am

Hello.
Re-installing fonts doesn't solved the problem.
I sent via e-mail some material for details.

Thank you.
User avatar

piessequadro
 
Posts: 21
Joined: Mon Nov 05, 2018 10:53 am

Thu Dec 14, 2023 10:47 am

Hi,

Thank you for your feedback.
I tried to test the code you provided through the latest version of Spire.DocStandard9.4.0, but unfortunately it was not successful as many properties and classes were not recognized. I wrote the following simple code based on the logic of your code, but did not reproduce your problem.
Code: Select all
' Declare a new Word document object
Dim doc As New Document()

' Load the Word document from the specified file path
doc.LoadFromFile("..\BrandCategoryProductsTable.docx")

' Get the first section of the document
Dim section As Section = doc.Sections(0)

' Get the first table in the section
Dim table As Table = TryCast(section.Tables(0), Table)

' Replace all occurrences of "[ProductDescription]" with "ADEO CONTROL" followed by a line break character (vbCrLf)
table.Replace("[ProductDescription]", "ADEO CONTROL" & vbCrLf, False, True)

' Declare another Word document object to hold the modified document
Dim doc1 As New Document()

' Load the second Word document from the specified file path
doc1.LoadFromFile("..\BrandSection.docx")

' Add a clone of the first section from the original document to the second document
doc1.Sections.Add(doc.Sections(0).Clone())

' Specify the output file path for the modified document
Dim output As String = "..\ReplaceTextInTable_out1.docx"

' Save the modified document to the specified file path in the Docx2013 format
doc1.SaveToFile(output, FileFormat.Docx2013)

Did you use the latest version of Spire.DocStandard9.4.0? If not, please use the latest version to test again. In addition, may I ask which overloaded method is used for the replace method in your code.
1.png


Sincerely,
Ula
E-iceblue support team
User avatar

Ula.wang
 
Posts: 282
Joined: Mon Aug 07, 2023 1:38 am

Return to Spire.Doc