ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,489 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
The code below saves a 1 page pdf
How do I add a footer to it?
table.AddCell(PhraseCell(new Phrase("Name:", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.BOLD, BaseColor.BLACK)), PdfPCell.ALIGN_LEFT));
phrase = new Phrase(new Chunk(sName + "\n\n", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, BaseColor.BLACK)));
table.AddCell(PhraseCell(phrase, PdfPCell.ALIGN_LEFT));
cell = PhraseCell(new Phrase(), PdfPCell.ALIGN_CENTER);
cell.Colspan = 2;
cell.PaddingBottom = 10f;
table.AddCell(cell);
document.Add(table);
document.Close();
byte[] bytes = memoryStream.ToArray();
string uncPath1 = @"\\MyServer\MyFolder$\temp\";
File.WriteAllBytes(SharedPath + "employee.pdf", bytes);
Never mind!
I've fixed it using the code below:
PdfPTable tbfooter = new PdfPTable(3);
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("This is my Footer...", FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLUE))));
_cell2.HorizontalAlignment = Element.ALIGN_RIGHT;
_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[] { 20f, 20f, 60f };
tbfooter.SetWidths(widths1);
tbfooter.WriteSelectedRows(0, -1, document.LeftMargin, writer.PageSize.GetBottom(document.BottomMargin), writer.DirectContent);