gpt4 book ai didi

c# - 如何为 PdfPTable 设置宽度并在页面中对齐表格中心

转载 作者:太空宇宙 更新时间:2023-11-03 18:38:17 26 4
gpt4 key购买 nike

我是 iTextSharp 的初学者,我编写了这段代码以在 PdfPTable 中创建 RoundRectangle 并在页面中心对齐表格

 string pdfpath = Server.MapPath("PDFs");
RoundRectangle rr = new RoundRectangle();

using (Document document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfpath + "/Graphics6.pdf", FileMode.CreateNew));
document.Open();
PdfPTable table = new PdfPTable(1);
float[] f=new float[]{0.5f};

table.SetWidths(f);
PdfPCell cell = new PdfPCell()
{
CellEvent = rr,
Border = PdfPCell.NO_BORDER,

Phrase = new Phrase("test")
};
table.AddCell(cell);
document.Add(table);

我想改变表格宽度我改变代码

 string pdfpath = Server.MapPath("PDFs");
RoundRectangle rr = new RoundRectangle();

using (Document document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfpath + "/Graphics6.pdf", FileMode.CreateNew));
document.Open();
PdfPTable table = new PdfPTable(1);
table.TotalWidth = 5;

int[] w = new int[] { 12};
table.SetWidths(w);
PdfPCell cell = new PdfPCell()
{
CellEvent = rr,
Border = PdfPCell.NO_BORDER,

Phrase = new Phrase("test")
};
table.AddCell(cell);
document.Add(table);

但是没有工作,也没有改变页面中的宽度表。请帮我。谢谢大家

最佳答案

您可以使用 TotalWidth 属性为 PdfPTable 设置宽度,如下代码:

string pdfpath = Server.MapPath("PDFs");
RoundRectangle rr = new RoundRectangle();

using (Document document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfpath + "/Graphics200.pdf", FileMode.CreateNew));
document.Open();
PdfPTable table = new PdfPTable(1);
table.TotalWidth = 144f;

table.LockedWidth = true;
PdfPCell cell = new PdfPCell()
{
CellEvent = rr,
Border = PdfPCell.NO_BORDER,
Phrase = new Phrase("test")
};
table.AddCell(cell);
document.Add(table);
}

关于c# - 如何为 PdfPTable 设置宽度并在页面中对齐表格中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12026138/

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