我在 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 字体打印的文本都以深色填充形状(即正方形、三角形等)的形式出现。
请提出为什么会这样。当我正确地遵循每件事时。