We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aligning text in header or footer using a table


I’m using Apose.Pdf for C#.NET. I’m trying to add headers and footers to every page in my document, where the headers and footers can contain a left part, a right part and a center part. I’ve seen info on your documentation and in forums that says I should do this using a table. My code is below for inserting a table into the footer with three columns. When I view the document, I can only see the top border of the table, and nothing more. Also, I can only see this on the first page. On all other pages I see nothing in the footer. I have tried changing the margins but this seems to make no difference. How can I make my table visible in the footer? Thanks.

    public Document AddFooter(MemoryStream stream)
          var pdf = new Document(stream);
          HeaderFooter footer = new HeaderFooter();

            var tab1 = new Table();
            //Add the table in paragraphs collection of the desired section

            //Set with column widths of the table
            tab1.ColumnWidths = "150 150 150";
            tab1.DefaultCellBorder = new BorderInfo(BorderSide.All, .5F, Color.Gray);

            //Create rows in the table and then cells in the rows
            var row1 = tab1.Rows.Add();
            row1.Cells[0].Alignment = HorizontalAlignment.Left;
            row1.Cells[1].Alignment = HorizontalAlignment.Center;
            row1.Cells[2].Alignment = HorizontalAlignment.Right;

            row1.Cells[0].Paragraphs.Add(new HtmlFragment("<p>right</p>"));
            row1.Cells[1].Paragraphs.Add(new HtmlFragment("<p>center</p>"));
            row1.Cells[2].Paragraphs.Add(new HtmlFragment("<p>left</p>"));

            foreach (Page pdfPage in pdf.Pages)
                pdfPage.Footer = footer;
                pdfPage.PageInfo.Margin.Bottom = 80;

        return pdf;

We have tested your code with a multi-page PDF and the latest version 17.7 of Aspose.Pdf for .NET API. We managed to replicate the problem of missing table in the footer of all pages. It has been logged under the ticket ID PDFNET-43022 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates. We would also recommend you to share the source PDF for verification of the actual scenario.

You can add text and align as narrated in this help topic: Manage Header and Footer of PDF File

Best Regards,
Imran Rafique