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.

Tue Apr 01, 2025 12:16 pm

Hi,
We use next code to produce pdf file:
Code: Select all
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.awt.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@RestController
public class SpiredocController {



    @GetMapping("/testPdf")
    public ResponseEntity<Resource> generateDocument() {
        Document document = new Document();
        document.addSection().addParagraph().appendHTML("""
                <html><p>&nbsp;</p>
                <p>&nbsp;</p>
                <p>게으른 개를 뛰어넘는 재빠른 갈색 여우</p>
                <p>&nbsp;</p>
                <p>test korean</p></html>""");

        document.getLastSection().addParagraph().appendText("게으른 개를 뛰어넘는 재빠른 갈색 여우");
        document.getLastSection().addParagraph().appendText("This is a test");
        try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            document.saveToStream(outputStream, FileFormat.PDF);
            ByteArrayResource resource = new ByteArrayResource(outputStream.toByteArray(), "document.pdf");
            HttpHeaders headers = new HttpHeaders();
            headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"document.pdf\"");
            return ResponseEntity.ok().headers(headers).contentType(MediaType.APPLICATION_OCTET_STREAM).body(resource);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @GetMapping("/testFonts")
    public ResponseEntity<List<String>> getInstalledFonts() {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Set<String> systemFonts = Arrays.stream(ge.getAllFonts()).map(Font::getFamily).collect(Collectors.toSet());
        List<String> availableFonts = systemFonts.stream().toList();
        return ResponseEntity.status(HttpStatus.OK).body(availableFonts);
    }
}


When we execute testPpdf route generated file doesn't contains Korean:
Untitled.png


While we have installed Korean fonts, like Noto Sans KR, Noto Serif KR.
Attached source and API outputs.

Env details:
Amazon Linux 2023.6.20250218 (Docker)
java-17-amazon-corretto
SpireDoc for Java 13.1.3
Spring Boot v2.6.15, Spring v5.3.27
Locale: C.UTF-8

Please help to resolve this issue.
Thanks,
Andrei Chorin

andrei.chorin
 
Posts: 68
Joined: Sun Jan 08, 2023 2:36 pm

Thu Apr 03, 2025 7:34 am

Hello,

Thanks for your inquiry.
I noticed that your HTML code does not specify a font for Korean, which may be the cause of your issue. Please refer to the following code to modify and re-verify whether the issue still exists. In addition, I recommend that you use the "Batang" font to draw Korean, which is the default font used by Microsoft wrod to draw Korean. Looking forward to your test results.
Code: Select all
 Document document = new Document();
 // font folder
 document.setCustomFontsFolders("noto-serif-kr folder");
 document.addSection().addParagraph().appendHTML("<p>test korean</p>\n" +
                                                 "<p style=\"font-family: 'Noto Serif KR'\">게으른 개를 뛰어넘는 재빠른 갈색 여우</p>");
 document.saveToFile("res.docx",FileFormat.Docx_2016);
 document.saveToFile("res.pdf",FileFormat.PDF);

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Sun Apr 06, 2025 10:26 pm

Hi,
I've changed code:
Code: Select all
        Document document = new Document();
        document.setCustomFontsFolders("C:\\Windows\\Fonts");
        document.addSection().addParagraph().appendHTML("""
                <p>-----------</p>
                <p style=\\"font-family: 'Noto Serif KR'\\">&#50504;&#45397;&#54616;&#49464;&#50836;</p>
                <p>-----------</p>
                <p style=\\"font-family: 'Noto Serif KR'\\">안녕하세요</p>
                <p>-----------</p>
                <p style=\\"font-family: 'SimSun'\\">&#50504;&#45397;&#54616;&#49464;&#50836;</p>
                <p>-----------</p>
                <p style=\\"font-family: 'SimSun'\\">안녕하세요</p>
                <p>-----------</p>
                <p>test korean</p""");

        document.getLastSection().addParagraph().appendText("게으른 개를 뛰어넘는 재빠른 갈색 여우");
        document.getLastSection().addParagraph().appendText("This is a test");
        document.saveToFile("test.docx", FileFormat.Docx_2019);
        document.saveToFile("test.pdf", FileFormat.PDF);

But without success

Regards,
Andrei

andrei.chorin
 
Posts: 68
Joined: Sun Jan 08, 2023 2:36 pm

Mon Apr 07, 2025 2:40 am

Hello,

Thanks for your feedback.
I think your problem is caused by the escape symbol, please copy my code directly to test it. I also attached my result for your reference.
Code: Select all
 Document document = new Document();
 document.setCustomFontsFolders("C:\\Windows\\Fonts");
 document.addSection().addParagraph().appendHTML("""
     <p>-----------</p>
     <p style="font-family: 'Noto Serif KR'">&#50504;&#45397;&#54616;&#49464;&#50836;</p>
     <p>-----------</p>
     <p style="font-family: 'Noto Serif KR'">안녕하세요</p>
     <p>-----------</p>
     <p style="font-family: 'SimSun'">&#50504;&#45397;&#54616;&#49464;&#50836;</p>
     <p>-----------</p>
     <p style="font-family: 'SimSun'">안녕하세요</p>
     <p>-----------</p>
     <p>test korean</p>
     """);
 TextRange textRange = document.getLastSection().addParagraph().appendText("게으른 개를 뛰어넘는 재빠른 갈색 여우");
 textRange.getCharacterFormat().setFontNameFarEast("Noto Serif KR");
 document.getLastSection().addParagraph().appendText("This is a test");
 document.saveToFile("test.docx", FileFormat.Docx_2019);
 document.saveToFile("test.pdf", FileFormat.PDF);

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Sun Apr 20, 2025 6:18 am

Hi,
I've used provided code and got same result:
Untitled.png

Please help.

andrei.chorin
 
Posts: 68
Joined: Sun Jan 08, 2023 2:36 pm

Mon Apr 21, 2025 10:20 am

Hello,

Thanks for your reply.
Have you tried directly using Microsoft Word to convert a Word document containing the "Noto Serif KR" font to PDF? Does it also have font issues?
I have packaged my project into a JAR file and uploaded it along with the "Noto Serif KR" font to this link. After extracting, please directly execute the command "java -jar TestFont.jar" and check if there are any issues with the generated document. Looking forward to your feedback.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Tue Apr 22, 2025 2:44 pm

Hi,
PDF file still doesn't contain Korean.
Untitled1.png

Please see attached files.

Regards,
Andrei Chorin.

andrei.chorin
 
Posts: 68
Joined: Sun Jan 08, 2023 2:36 pm

Wed Apr 23, 2025 3:16 am

Hello,

Thanks for your feedback.
I noticed that the generated PDF can be displayed normally in Adobe Acrobat Reader, but it is not displayed correctly in the Chrome browser, as you have shown in the screenshot. I have logged this issue to our tracking system with ticket SPIREDOC-11229, and our development team will investigate and fix it further. I will keep you informed once there is any progress.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Fri May 23, 2025 9:23 am

Hello,

Thanks for your patience.
We have just released the latest Spire.Doc for Java Version:13.5.3, which fixes the issue SPIREDOC-11229. Welcome to update and test.
WebSite link:https://www.e-iceblue.com/Download/doc-for-java.html

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 732
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.Doc