java - ZapOfDingBats 字体在输出 pdf 上不正确可见

标签 java fonts itext

我在 itext 中使用 ZapfDingBats 字体来显示 Pdf 上的文本。我按照一般代码使用 ZapfDingBats 字体显示文本,如下所示:-

import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;

public class Chap0201 {

    public static void main(String[] args) {

        System.out.println("Chapter 2 example 1: Chunks and fonts");

        // step 1: creation of a document-object
        Document document = new Document();

        try {

            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
            PdfWriter.getInstance(document, new FileOutputStream("C://Chap0201.pdf"));

            // step 3: we open the document
            document.open();

            // step 4: we add content to the document
            Font fonts;
            fonts = FontFactory.getFont(FontFactory.ZAPFDINGBATS, 12, Font.NORMAL);
           // for (int i = 0; i < fonts.length - 1; i++) {
                Chunk chunk = new Chunk("This is some", fonts);
                document.add(new Phrase(chunk));
               // document.add(new Phrase(new Chunk(" font. ",
                //fonts[i]).setTextRise((i % 2 == 0) ? -6 : 6)));
          //  }
            document.add(new Phrase(new Chunk("This text is underlined",
            FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE))));
            document.add(new Phrase(new Chunk("This font is of type ITALIC | STRIKETHRU",
            FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC | Font.STRIKETHRU))));
            Chunk ck = new Chunk("This text has a yellow background color", FontFactory.getFont(FontFactory.HELVETICA, 12));
            ck.setBackground(new Color(0xFF, 0xFF, 0x00));
            document.add(new Phrase(ck));
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }

        // step 5: we close the document
        document.close();
    }
}

我只是按照上面的文本在 Pdf 中显示文本。但是使用 ZapOfDingBats 字体打印的所有文本都以深色填充形状(即正方形、三角形等)的形式出现。 enter image description here

请说明为什么会发生这种情况。因为我正确地遵循了每件事。

最佳答案

ZapfDingbats 是一种 dingbat 字体。

该术语在计算机行业中继续用于描述在指定字母或数字字符的位置具有符号和形状的字体。

(维基百科,http://en.m.wikipedia.org/wiki/Dingbat)

关于java - ZapOfDingBats 字体在输出 pdf 上不正确可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14396578/

相关文章:

java - 将数据库查找映射到 jpa 实体

java - 方法覆盖 : same argument list types (or COMPATIBLE types)?

html - 如何将字体添加到类

java - 如何在我的 android 应用程序中放置自定义字体?

java - 在 itext7 中将 html 转换为 pdf 时出错

java - bouncycaSTLe 和 iText 版本

java - 是否可以在 java 中交换两个数组索引的值?

java - ThreadPoolTask​​Executor 中的 @Autowired 不起作用

fonts - JetBrains Mono和JetBrains Mono NL有什么区别

java - 有没有一种有效的方法可以用 Java 将多个 HTML 字符串写入 PDF 文档?