PDFにテキストを表示するためにitextでZapfDingBatsフォントを使用しています。以下のように、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 フォントを使用して印刷されたすべてのテキストは、暗い塗りつぶされた形状 (つまり、正方形、三角形など) の形で表示されます。
なぜこれが起こっているのかを提案してください。私はすべてを正しくフォローしました。