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

Free Support Forum - aspose.com

Add table inside PDF document in C# using Aspose.PDF - Repeating table header alignment issue

Hi, I have attached the results of a pdf with repeating headers. On the first page the table headings(interest rate, Transaction and Balance) are aligned correctly. But from page to they’re aligned to the default to the left. On my personal PC I use the evaluation copy and the PDF repeating headers works fine. On the licensed version(10.2.0.0) it is where is gives us issues. Please also confirm if it is a bug in the version or it is something we can fix with a code.

Here is the sample code:

        TextState rightText = new TextState
        {
            HorizontalAlignment = HorizontalAlignment.Right
        };

        TextState tinfo = new TextState
        {
            Font = FontRepository.FindFont("Calibri"),
            FontSize = 8,
            FontStyle = FontStyles.Regular
        };

        Aspose.Pdf.MarginInfo tableDetailsCellPadding = new Aspose.Pdf.MarginInfo
        {
            Top = 2,
            Bottom = 2,
            Left = 5,
            Right = 5
        };

        Aspose.Pdf.Table pdfTable = new Table
        {
            ColumnWidths = "50 230 80 95 95"
        };


        pdfTable.DefaultCellTextState = tinfo;
        pdfTable.RepeatingRowsCount = 3;


        Aspose.Pdf.Row row = pdfTable.Rows.Add();
        Aspose.Pdf.Cell cell;

        Aspose.Pdf.Row row1 = pdfTable.Rows.Add();
        row1.DefaultCellPadding = tableDetailsCellPadding;
        cell = row1.Cells.Add("Transactions");
        cell.ColSpan = 5;
        cell.BackgroundColor = Color.FromArgb(69, 102, 158);
        cell.DefaultCellTextState.ForegroundColor = Color.FromArgb(255, 255, 255);
        cell.DefaultCellTextState.FontSize = 11;
        cell.DefaultCellTextState.FontStyle = FontStyles.Bold;

        Aspose.Pdf.Row row2 = pdfTable.Rows.Add();
        row2.DefaultCellPadding = tableDetailsCellPadding;
        row2.BackgroundColor = Color.FromArgb(155, 157, 164);
        row2.DefaultCellTextState = headerText;
        cell = row2.Cells.Add("Date");
        cell = row2.Cells.Add("Transaction Description");
        cell = row2.Cells.Add("Interest Rate (%)");
        cell.DefaultCellTextState.HorizontalAlignment = HorizontalAlignment.Center;
        cell = row2.Cells.Add("Transaction(R)");
        cell.DefaultCellTextState.HorizontalAlignment = HorizontalAlignment.Right;
        cell = row2.Cells.Add("Balance(R)");
        cell.DefaultCellTextState.HorizontalAlignment = HorizontalAlignment.Right;


        Aspose.Pdf.Row rowInhalt;

        for (int i = 1; i <= 10; i++)
        {
            rowInhalt = pdfTable.Rows.Add();
            rowInhalt.DefaultCellPadding = tableDetailsCellPadding;
            if (i % 2 == 0)
            {
                // Row styling(color) fuction
                rowInhalt.BackgroundColor = Color.FromArgb(232, 233, 234);
            }
            else
            {
                rowInhalt.BackgroundColor = Color.FromArgb(255, 255, 255);
            }
            rowInhalt.Cells.Add("20200701");
            rowInhalt.Cells.Add("TAP-TO-PAY POS PURCHASE VISA LOCAL [01] PNP FAM NEWMARKET ALBERTON ZA");
            rowInhalt.Cells.Add("0.25").DefaultCellTextState = centerText;
            rowInhalt.Cells.Add("1,544.36").DefaultCellTextState = rightText;
            rowInhalt.Cells.Add("1,544.36").DefaultCellTextState = rightText;
        }

HorizonSupportCC2_30000006200_20201008_Transactional (1).pdf (479.0 KB)

@Embrose

We tested the scenario in our environment while using Aspose.PDF for .NET 20.10 and set the headerText aligned to the right. We achieved attached output. You can please check it and let us know in case you notice any issue. Please also share complete code snippet if you notice any issue using latest version of the API.
table.pdf (79.1 KB)