0

ファイルからいくつかのテキストを読み込ん.txtで、それらを pdf ファイルに書き込んでいます。しかし、私の pdf では、テキストが大きなフォントとして表示されています。ファイルのフォント サイズ.txtを大きくしたり小さくしたりしても、pdf のフォントは同じになります。

テキストファイルへの書き込みの読み取りで動作している私のコードの一部

Document document = new Document(PageSize.A4.rotate(), 36, 36, 80, 160);
 ........
 .........
           document.newPage();

            //Writing in a default page from the txt file

            document.add(new com.lowagie.text.Paragraph("\n"));
            iStream = new FileInputStream(path1); //path1 is location of .txt file
            in = new DataInputStream(iStream);
            is = new InputStreamReader(in);
            br = new BufferedReader(is);
            String strLine;
            while ((strLine = br.readLine()) != null)
            {
                Paragraph para = new com.lowagie.text.Paragraph(strLine + "\n");
                para.setAlignment(Element.ALIGN_JUSTIFIED);
                document.add(new com.lowagie.text.Paragraph(strLine + "\n"));

            }
            br.close();
            is.close();
            in.close();
            iStream.close();
            document.close();
            writer.close(); 

現在、windchill にサードパーティのライブラリを追加できないため、itext の下位バージョンを使用しています。このバージョンの itext は既に Windchill に含まれています。

書き込み時にpdfファイル内のフォントサイズを設定する方法.?どんな助けでも本当に役に立ちます.

4

1 に答える 1

2

とてもシンプルです:D

まず、私は 1 つのことを変更します。

while ((strLine = br.readLine()) != null) {
    Paragraph para = new com.lowagie.text.Paragraph(strLine + "\n");
    para.setAlignment(Element.ALIGN_JUSTIFIED);
    document.add(para);
}

このようにして、段落は文書内で正当化されます。あなたが行った方法では、1 つの段落オブジェクトのテキストの配置を変更しましたが、まったく異なる新しいものを PDF に追加しました。

今あなたの問題に:次のように、各 Paragraph` コンストラクターで
指定できます。Font

Paragraph para = new com.lowagie.text.Paragraph(strLine + "\n", FontFactory.getFont("Arial", 14f /*This is the size, but as a float!*/);

lowagie API のドキュメント全体は、ここにあります。

よろしくお願いします

于 2013-07-18T11:56:58.203 に答える