Horizontal alignment on row PdfPRow itextsharp (c#)

470 views Asked by At

Need some help here. I'm trying text within a row looks in the same horizontal line as it's corresponding dotted lines This is the result

enter image description here

And this is the part of my code related to the image:

        Font coverHeaderFont = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD, BaseColor.BLACK);
        Font tableContentFont = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLDITALIC, BaseColor.BLACK);
        Font textIndexFont = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD, BaseColor.BLACK);
        Font invisibleFont = new Font(Font.FontFamily.HELVETICA, 11, Font.BOLD, BaseColor.WHITE);
        Font underText = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD | Font.ITALIC, BaseColor.BLACK);

        //table creation
        PdfPTable tblCon = new PdfPTable(3); //3 columns
        tblCon.WidthPercentage = 90f; //wide %
        tblCon.HorizontalAlignment = 1; //centered
        //tblCon.LockedWidth = true;

        //relative col widths in proportions - 1/3 and 2/3
        float[] widths = new float[] { 4f, 6f, 2f };//{ 6f, 4f, 2f };
        tblCon.SetWidths(widths);

        //leave a gap before and after the table
        tblCon.SpacingBefore = 20f;
        tblCon.SpacingAfter = 30f; 

        //Header Cell
        string appHeader = "Applications";
        Chunk cAppHeader = new Chunk(appHeader, underText);

        // CELLS
        PdfPCell cellName = new PdfPCell();
        cellName.PaddingTop = 10f;
        cellName.VerticalAlignment = PdfPCell.ALIGN_TOP;
        cellName.BorderWidth = 1;
        cellName.MinimumHeight = 30f;
        //cellName.HorizontalAlignment = 0; //0=Left, 1=Center, 2=Right

        PdfPCell cellSeparator = new PdfPCell();
        cellSeparator.PaddingTop = 10f;
        cellSeparator.VerticalAlignment = PdfPCell.ALIGN_TOP;
        cellSeparator.BorderWidth = 1;
        cellSeparator.MinimumHeight = 20f;

        PdfPCell cellPage = new PdfPCell();
        cellPage.PaddingTop = 10f;
        cellPage.VerticalAlignment = PdfPCell.ALIGN_TOP;
        cellPage.BorderWidth = 1;
        cellPage.MinimumHeight = 30f;

        for (int i = 0; i < listOfDetailsPDF.Count; i++)
        {
            if (i == 0) //first column, just header
            {
                cellName.AddElement(new Paragraph(cAppHeader));
                cellSeparator.AddElement(new Paragraph(".", invisibleFont)); 
                cellPage.AddElement(new Paragraph("1", invisibleFont));
            }

            var obj = listOfDetailsPDF[i];
            String title = (string)obj.GetType().GetProperty("applicantName").GetValue(obj, null);
            Chunk cTitle = new Chunk(title, textIndexFont);

            int pNPage = (int)obj.GetType().GetProperty("pdfPages").GetValue(obj, null);
            String numberPage = pNPage.ToString();
            Chunk cNumPage = new Chunk(numberPage, textIndexFont);

            cellName.AddElement(new Paragraph(cTitle));
            cellSeparator.AddElement(new Paragraph(dottedLine));
            cellPage.AddElement(new Paragraph(cNumPage));

        }
        tblCon.Rows.Add(new PdfPRow(new PdfPCell[] { cellName, cellSeparator, cellPage }));

I just want: the name with the dotted line with the number page look in the same line in every row. Thank you

0

There are 0 answers