我在itext中使用ZapfDingBats字体在Pdf上显示文本。我随后的一般性代码使用如下ZAPFDINGBATS字体来显示文本: -ZapOfDingBats字体在输出中不能正确显示pdf
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字体打印的文本都以深填充形状(例如正方形,三角形等)的形式出现
请建议为什么发生这种情况。当我正确地跟随每一件事。
ZAPFDINGBATS是符号字体。因此,你期望什么? – mkl
字体被称为ZapfDingbats,而不是ZapOfDingBats。 –
刚刚添加到此如何在Java中使用Font对象使用ZapOfDingBats字体。我没有找到在Java Swing中显示ZapOfDingBats文本的方法。我尝试使用字体对象 字体dqFont =新的字体(名称,风格,大小); 我没有找到名称为“ZapOfDingBats”来显示此Java字体。无论如何,我可以得到这种字体对象的这种字体,并可以显示在标签上。 –