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> </p>
<p> </p>
<p>게으른 개를 뛰어넘는 재빠른 갈색 여우</p>
<p> </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:
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