gpt4 book ai didi

itext - 对齐 itextsharp 表

转载 作者:行者123 更新时间:2023-12-04 09:21:35 24 4
gpt4 key购买 nike

有谁知道如何左对齐 iTextSharp 表?

最佳答案

您可以使用 PdfPTableHorizontalAlignment属性(property)。

这是您可以用来进行实验的 C# 测试方法:

    private void TestTableCreation() {
using (FileStream fs = new FileStream("TableTest.pdf", FileMode.Create)) {
Document doc = new Document(PageSize.A4);
PdfWriter.GetInstance(doc, fs);
doc.Open();

PdfPTable table = new PdfPTable(4);
table.WidthPercentage = 50.0f;
// Options: Element.ALIGN_LEFT (or 0), Element.ALIGN_CENTER (1), Element.ALIGN_RIGHT (2).
table.HorizontalAlignment = Element.ALIGN_LEFT;

for (int i = 1; i <= 20; i++) {
PdfPCell cell = new PdfPCell(new Phrase(String.Format("Cell # {0}", i)));
cell.FixedHeight = 30.0f;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;

table.AddCell(cell);
}

doc.Add(table);
doc.Close();
}
}

关于itext - 对齐 itextsharp 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4145808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com