0
我有一個有幾個數字列的表。我可以對齊行列就好了,但我不能右側列標題列。我認爲,原因是因爲PdfPHeaderCell構造函數不接受Phrase對象,所以我必須使用cell.addElement(),它將其置於複合模式,忽略我指定的對齊方式。PdfPHeaderCell在文本模式下對齊內容
我發現實現我所尋找的效果的唯一方法是創建一個段落,爲其分配對齊,然後將其放在標題中。這對我來說似乎有點笨拙,因爲我不需要任何段落的任何特徵,我只需要對齊它。
有沒有更乾淨的方法來做到這一點?
/**
* Builds a basic header cell from the given string
*
* @param content
* @param alignment
* @return PdfPHeaderCell
*/
protected static PdfPHeaderCell getGenericHeaderCell(String content, Integer alignment)
{
PdfPHeaderCell cell = new PdfPHeaderCell();
Paragraph p = new Paragraph();
p.add(new Phrase(content, TABLE_HEADER));
if (alignment != null)
{
p.setAlignment(alignment);
}
cell.addElement(p);
cell.setBorder(Rectangle.BOTTOM);
cell.setBorderColorBottom(TABLE_HEADER_BORDERCOLOR);
cell.setBorderWidthBottom(1);
cell.setPaddingTop(0);
return cell;
}