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.

Thu Apr 28, 2022 10:32 am

Hey!
I am using spire.doc.free::3.9.0 in java.
I need to replace the font of the text in the table with one downloaded from the Internet.
This works locally, but not through the docker project image.
Can you help me with this?

Code: Select all
var urlPath = Thread.currentThread().getContextClassLoader().getResource("fonts");
var document = new com.spire.doc.Document(new ByteArrayInputStream(stream.toByteArray()));
var fontPath = new PrivateFontPath();
fontPath.setFontName("capture");
fontPath.setFontPath(urlPath.getPath() + "/capture-it.ttf");
document.setEmbedFontsInFile(true);
document.setEmbedSystemFonts(false);
document.getPrivateFontList().add(fontPath);

for (var objSection : document.getSections()) {
            if (objSection instanceof com.spire.doc.Section section) {
                for (var objTable : section.getTables()) {
                    if (objTable instanceof Table table1) {
                        for (var objRow : table1.getChildObjects()) {
                            if (objRow instanceof TableRow row) {
                                for (var objCell : row.getCells()) {
                                    if (objCell instanceof TableCell cell) {
                                        for (var objParagraph : cell.getParagraphs()) {
                                            if (objParagraph instanceof com.spire.doc.documents.Paragraph pr) {
                                                for (var objText : pr.getChildObjects()) {
                                                    if (objText instanceof TextRange text) {
                                                        text.getCharacterFormat().setFontName("capture");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

Kreker721425
 
Posts: 1
Joined: Wed Apr 27, 2022 3:19 pm

Fri Apr 29, 2022 10:26 am

Hi,

Thank you for your inquiry.
I recommend that you test with our latest version(Spire.Doc for Java Version:5.4.10). If the problem still exists, please provide the following information for further investigation.
1) JDK version such as JDK 1.8.0_281
2) Your font (capture-it.ttf)
3) Docker File and Your doc test document
You can attach here or send it to us via email (support@e-iceblue.com). Thank you in advance.

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Sat Sep 30, 2023 4:19 am

Replacing a font in the text of a Word file with a font downloaded from the Internet can present some difficulties, especially when switching between local and Docker environments
<a href="https://fontesdeletras.io/nl/">Fontesdeletras</a>
[Fontesdeletras](https://fontesdeletras.io/nl/)
https://fontesdeletras.io/nl/

Fontedeletrasionl
 
Posts: 1
Joined: Sat Sep 30, 2023 4:17 am

Wed Oct 04, 2023 12:45 pm

Hello,

Thanks for your message.
When switching the project’s location from a local environment to a Docker environment, the most important thing is to change the font path and give the font access permission to the current user. Is there something wrong with you?
If yes, please describe it in detail

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc

cron