13

私はオープンソースhttp://itextpdf.com/を使用して、いくつかのpdfを作成しています。

テーブルを作成することはできますが、すべての列の幅が同じであるため、特定の列の幅を変更する必要があります。

PdfPTable table = new PdfPTable(6);
Phrase tablePhrse = new Phrase("Sl n0", normalFontBold);
    PdfPCell c1 = new PdfPCell(tablePhrse);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

列の幅を設定する方法が見つかりませんでした。plsはこれを実現するための何らかの方法を提案しています。

4

5 に答える 5

23

setWidths()メソッドを利用できます。

table.setWidths(new int[]{200,50});

public void setWidths(int [] RelativeWidths)

于 2013-02-08T18:32:55.740 に答える
4

これを試して。

float[] columnWidths = new float[]{10f, 20f, 30f, 10f};
table.setWidths(columnWidths);
于 2017-04-04T09:13:54.503 に答える
1

table.setWidths(new int[]{200,50});動作しない 場合の修正方法は次のとおりです。

innertable.setWidthPercentage(50);
于 2016-12-18T08:01:46.213 に答える
1

テーブルの全幅を必ず設定してください

// Set Column Number
PdfPTable table = new PdfPTable(2);

// Set Table Total Width
table.setTotalWidth(500);

// Set Each Column Width - Make Sure Array is the same number specified in constructor
table.setWidths(new int[]{50, 450});
于 2019-01-28T14:44:49.267 に答える
1
float[] columnWidths = {1, 5, 5};

// columnWidths = {column1, column2, column3...}

PdfPTable table = new PdfPTable(columnWidths)
于 2019-04-02T08:58:43.927 に答える