0

Java と iTextPdf を使用して、多数のセルをレイアウトするテーブルを作成しました。これらのセル内のテキストのフォントを変更する方法がわかりません。子供向けなのでComic Sans MSを使おうと思っています。すべてが正常にコンパイルおよび実行されますが、一般的なフォント (おそらく Helvetica など) が得られます。

このようなフォントを生成する方法を知っている人はいますか? ありがとう!

ここに私が書いたものの縮小版があります:

import com.itextpdf.text.FontFactory; 
import com.itextpdf.text.pdf.FontSelector;

public static PdfPTable createTable() {
        FontSelector selector = new FontSelector();
        selector.addFont(FontFactory.getFont("Comic Sans MS"));
        PdfPTable table = new PdfPTable(3);
        PdfPCell cell;
        Phrase ph;

        ph = selector.process("My Title");
        cell = new PdfPCell(ph);
        table.addCell(cell);
        return table;
4

1 に答える 1

0

You can import your font to FontFactory and then use it as

    String filename = "Comic Sans MS.ttf";
    FontFactory.register(filename, filename);
    Font font = FontFactory.getFont(filename, BaseFont.CP1252, BaseFont.EMBEDDED);

This will also embed the font in the PDF file so it will work even if target PDF reader does not have this font installed.

于 2013-03-01T02:09:57.690 に答える