Hi @Malam Malam ,
float[] widths1 = new float[] { 20f, 20f, 60f };
This line of code distributes the column width proportionally to the width of the table.
The following code means that the width of the column itself is set relative to one-third and two-thirds of the total width of the table.
To set it to one-fifth and four-fifth, you would pass in 1f and 4f, respectively.
You can set the absolute width by passing in a value for the total width of the table, for example:
table.TotalWidth = 216f;
//relative col widths in proportions - 1/3 and 2/3
float[] widths = new float[] { 1f, 2f };
//table total width value
float[] widths = new float[] { 100f, 116f };
I suggest you to set PdfPTable to 1, you can refer to the code below:
protected void btnGeneratePDFFile_Click(object sender, EventArgs e)
{
Document document = new Document();
var output = new FileStream(Server.MapPath("MyFirstPDF.pdf"), FileMode.Create);
var writer = PdfWriter.GetInstance(document, output);
document.Open();
PdfPTable tbfooter = new PdfPTable(1);
tbfooter.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
tbfooter.DefaultCell.Border = 0;
tbfooter.AddCell(new Paragraph());
tbfooter.AddCell(new Paragraph());
var _cell2 = new PdfPCell(new Paragraph(new Chunk("A Fair Lending and Equal Employment Opportunity Agency. For assistance: Individuals with disabilities may contact the ADA Administrator at 924-123-4567, TTY 456-765-1234 or ******@ILoveThisForum.org", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLUE))));
_cell2.HorizontalAlignment = Element.ALIGN_LEFT;
_cell2.Border = 0;
tbfooter.AddCell(_cell2);
tbfooter.AddCell(new Paragraph());
tbfooter.AddCell(new Paragraph());
var _celly = new PdfPCell(new Paragraph(writer.PageNumber.ToString()));//For page no.
_celly.HorizontalAlignment = Element.ALIGN_RIGHT;
_celly.Border = 0;
tbfooter.AddCell(_celly);
float[] widths1 = new float[] {1f };
tbfooter.SetWidths(widths1);
tbfooter.WriteSelectedRows(0, -1, document.LeftMargin, writer.PageSize.GetBottom(document.BottomMargin), writer.DirectContent);
document.Add(tbfooter);
document.Close();
}
protected void btnOpenPDFFile_Click(object sender, EventArgs e)
{
//Open the PDF file
Process.Start(Server.MapPath("MyFirstPDF.pdf"));
btnGeneratePDFFile.Enabled = true;
btnOpenPDFFile.Enabled = false;
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.