Pou*_*uya 1 c# itextsharp pdfptable
我是iTextSharp的首发,我将此代码编写为创建RoundRectangle到PdfPTable并在页面中心对齐表
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);
Run Code Online (Sandbox Code Playgroud)
我想改变表格宽度我改变代码
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);
Run Code Online (Sandbox Code Playgroud)
但页面中没有工作也没有更改宽度表.请帮我.谢谢大家
您可以使用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);
}
Run Code Online (Sandbox Code Playgroud)