Click here to Skip to main content
14,603,943 members
Rate this:
Please Sign up or sign in to vote.
See more:
i am using itextsharp for creating document. I have created a footer section in document but content that over the top of footer is overlapping.

How can i fix this?

I want to add page number on each page how can i do this?

Please check this link

public class PdfNote
   {
       public int Create(int id, string path)
       {
           try
           {
               var file = path;

               if (System.IO.File.Exists(file))
                   System.IO.File.Delete(file);


               Document document = new Document(PageSize.A4, 10, 10, 10, 10);

               var writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new  System.IO.FileStream(file, FileMode.Create));
               document.Open();

               writer.PageEvent = new Footer();

               // main content

               document.Close();

               return 1;
           }
           catch (Exception ex)
           {
               throw ex;
           }


       }

       public partial class Footer : PdfPageEventHelper
       {
           public override void OnEndPage(PdfWriter writer, Document doc)
           {
               PdfPTable fTbl = new PdfPTable(1);
               fTbl.TotalWidth = 550;
               fTbl.DefaultCell.Border = 0;

               PdfPTable line = new PdfPTable(1);
               line.DefaultCell.Border = 0;
               line.DefaultCell.BorderWidthBottom = 0.2f;
               line.DefaultCell.Padding = 5;
               line.AddCell("");

               fTbl.AddCell(line);

               PdfPTable footerTbl = new PdfPTable(3);
               footerTbl.TotalWidth = 550;
               footerTbl.DefaultCell.Column.Alignment = 1;
               footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
               footerTbl.DefaultCell.Border = 0;

               footerTbl.AddCell("Print Name:");
               footerTbl.AddCell("Signature:");
               footerTbl.AddCell("Date:");


               PdfPCell cell = new PdfPCell();
               cell.Padding = 20;
               cell.Border = 0;
               cell.BorderWidthBottom = 1;

               footerTbl.AddCell(cell);
               footerTbl.AddCell(cell);
               footerTbl.AddCell(cell);

               fTbl.AddCell(footerTbl);
               fTbl.AddCell(line);

               fTbl.WriteSelectedRows(0, -1, 15, 110, writer.DirectContent);

               //footerTbl.WriteSelectedRows(0, -1, 15, 60, writer.DirectContent);
           }
       }
   }
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I have increased the bottom margin of document so now footer and content are not going to overlap each other.

Document document = new Document(PageSize.A4, 10, 10, 10, 80);
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100