Click here to Skip to main content
13,195,379 members (60,300 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
So I've tried doing this two ways and neither of them work. I'm going to have 4 rows of 11 columns and I'd like everything to be centered. I can center the header cells (its only 11 extra lines of code) but I want the entire table centered.

What I have tried:

Here is my code:
                    BaseFont bf = BaseFont.CreateFont(
                            BaseFont.HELVETICA_BOLD,
                            BaseFont.CP1252,
                            BaseFont.EMBEDDED);
                    iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 12);
                    PdfPTable table = new PdfPTable(11);
                    //table.HorizontalAlignment = Element.ALIGN_CENTER;
                    table.HorizontalAlignment = 1;
                    table.TotalWidth = 570f;
                    float[] widths = new float[] { 60f, 45f, 35f, 85f, 95f, 40f, 32f, 40f, 35f, 33f, 70f };
                    table.SetWidths(widths);
 
                    PdfPCell cell1 = new PdfPCell(new Phrase("Location", font));
                    PdfPCell cell2 = new PdfPCell(new Phrase("Type", font));
                    PdfPCell cell3 = new PdfPCell(new Phrase("Area", font));
                    PdfPCell cell4 = new PdfPCell(new Phrase("Manfacturer", font));
                    PdfPCell cell5 = new PdfPCell(new Phrase("Model #", font));
                    PdfPCell cell6 = new PdfPCell(new Phrase("BTU's", font));
                    PdfPCell cell7 = new PdfPCell(new Phrase("EER", font));
                    PdfPCell cell8 = new PdfPCell(new Phrase("Amps", font));
                    PdfPCell cell9 = new PdfPCell(new Phrase("Volts", font));
                    PdfPCell cell10 = new PdfPCell(new Phrase("Year", font));
                    PdfPCell cell11 = new PdfPCell(new Phrase("Relace Y/N", font));
                    //cell1.HorizontalAlignment = 1;
                    //cell2.HorizontalAlignment = 1;
                    //cell3.HorizontalAlignment = 1;
                    //cell4.HorizontalAlignment = 1;
                    //cell5.HorizontalAlignment = 1;
                    //cell6.HorizontalAlignment = 1;
                    //cell7.HorizontalAlignment = 1;
                    //cell8.HorizontalAlignment = 1;
                    //cell9.HorizontalAlignment = 1;
                    //cell10.HorizontalAlignment = 1;
                    //cell11.HorizontalAlignment = 1;
 
                    table.AddCell(cell1);
                    table.AddCell(cell2);
                    table.AddCell(cell3);
                    table.AddCell(cell4);
                    table.AddCell(cell5);
                    table.AddCell(cell6);
                    table.AddCell(cell7);
                    table.AddCell(cell8);
                    table.AddCell(cell9);
                    table.AddCell(cell10);
                    table.AddCell(cell11);
                    table.AddCell(acloc1_tbox.Text);
                    table.AddCell(actype1_tbox.Text);
                    table.AddCell(acroom1_tbox.Text);
                    table.AddCell(acman1_tbox.Text);
                    table.AddCell(acmod1_tbox.Text);
                    table.AddCell(acbtu1_tbox.Text);
                    table.AddCell(aceer1_tbox.Text);
                    table.AddCell(acamps1_tbox.Text);
                    table.AddCell(acvolts1_tbox.Text);
                    table.AddCell(acyear1_tbox.Text);
                    table.AddCell(acreplace1_tbox.Text);
                    table.AddCell(acloc2_tbox.Text);
Posted 19-Jun-17 4:15am

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171019.1 | Last Updated 19 Jun 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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