gpt4 book ai didi

java - Noto-sans 不与 Jasper 合作

转载 作者:行者123 更新时间:2023-11-29 09:28:07 26 4
gpt4 key购买 nike

我在 Jasper 中为 noto-sans 字体 ( https://www.google.com/get/noto/#sans-lgc ) 创建了一个字体扩展,并将其添加到我的类路径中。我的应用程序需要支持 fr, de, ja, ko, zh_CN, zh_TW, es ,en。但是生成的pdf没有渲染(ja, ko, zh_CN, zh_TW)。然后我尝试在 jasper 和 itext 之间拆分问题,所以我尝试使用下面的程序来检查 iText 是否正常工作。

import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfWriter;
public class Itext_test {

/** The resulting PDF file. */
public static final String RESULT = "fontTest.pdf";
/** the text to render. */
public static final String TEST = "사과-korean, 苹果(Chienses-simplified), 蘋果(Chinese-traditional), 林檎(Japanese), Sebastián(Spanish), ADÉLAÏDE-fr(French), James Bond(English)";

public void createPdf(String filename) throws IOException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
BaseFont bf = BaseFont.createFont(
"NotoSans-Regular.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf, 20);
ColumnText column = new ColumnText(writer.getDirectContent());
column.setSimpleColumn(36, 730, 569, 36);
column.addElement(new Paragraph(TEST, font));
column.go();
document.close();
}

public static void main(String[] args) throws IOException, DocumentException {
new Itext_test().createPdf(RESULT);
}
}

下面是输出pdf截图enter image description here

因此我们可以看到 ja、ko、zh_CN、zh_TW 字符未呈现。我正在使用 jaspersoft Studio 创建 .jrxml 文件并通过 java 代码填充它。有关更多详细信息,请查看此问题 Unicode characters in Jasper Report我不知道在哪里寻找什么。
如果有人能指出错误或指导我正确的方向,我将非常感激...

最佳答案

主要是因为OracleJRE是商业JRE,但是Noto字体是在开源许可证下发布的,使用OTF格式,所以Oracle JRE不支持这些字体(只要其他OTF字体)。

我所做的是将OTF格式转换为TTF格式,Oracle JRE可以读取和使用它们。

顺便说一句,如果你使用OpenJDK,你可以直接使用OTF字体。

关于java - Noto-sans 不与 Jasper 合作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40799219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com