Align content of ItexSharp cells in C #

1

Good morning,

I'm working with C # with the Itextsharp library.

Which by pressing a button creates a PDF and inside a small table where it shows the totals. I would like to know how I can align the contents of the cells in a centered way, because at the moment when initializing it, it shows it on the left side.

How can I make the alignment of the contents of the cells in the center.

My code to create the table is as follows:

 var parrafo3 = new Paragraph("\r\n" + "\r\n" + "Total:", fuente);
                    document.Add(parrafo3);

                PdfPTable table = new PdfPTable(9);

                table.AddCell(new PdfPCell(new Paragraph(textBox19.Text, fuente3)));
                table.AddCell(new PdfPCell(new Paragraph(textBox20.Text, fuente3)));
                table.AddCell(new PdfPCell(new Paragraph(textBox21.Text, fuente3)));
                table.AddCell(new PdfPCell(new Paragraph(textBox22.Text, fuente3)));
                table.AddCell(new PdfPCell(new Paragraph(textBox23.Text, fuente3)));
                table.AddCell(new PdfPCell(new Paragraph(textBox24.Text, fuente3)));
                table.AddCell(new PdfPCell(new Paragraph(textBox25.Text, fuente3)));
                table.AddCell(new PdfPCell(new Paragraph(textBox26.Text, fuente3)));
                table.AddCell(new PdfPCell(new Paragraph(textBox27.Text, fuente3)));
                table.HorizontalAlignment = Element.ALIGN_CENTER;
                //resto celdas

                document.Add(table);

Thanks. Greetings

    
asked by Ezequie Lopez 16.08.2018 в 20:53
source

1 answer

2

You can use the HorizonalAlignment and VerticalAlignment properties in the PdfCell class builder for horizontal and vertical centering, respectively.

table.AddCell(new PdfPCell(new Paragraph(textBox25.Text, fuente3)) { HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER, VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE });
    
answered by 16.08.2018 / 21:04
source