0

I have a problem with the library iText. I'm searching to build a nested table and apply the horizontal alignment to a column in the last table, this is my code:

        PdfPTable coverTable = new PdfPTable(2);
        PdfPCell containerCustomerInfo = new PdfPCell();
        PdfPTable customerInfoTable = new PdfPTable(2);
        customerInfoTable.setWidthPercentage(100f);
        customerInfoTable.setWidths(new float[]{30f, 200f});


        PdfPCell ciTitle = new PdfPCell();
        ciTitle.addElement(new Chunk("Customer Info"));
        ciTitle.setColspan(2);
        ciTitle.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        customerInfoTable.addCell(ciTitle);

        PdfPCell personLogoCell = new PdfPCell(); 
        Image personLogo = Image.getInstance("C:/Img/personLogo.png");
        personLogo.scaleAbsolute(20, 20);
        personLogoCell.addElement(personLogo);
        customerInfoTable.addCell(personLogoCell);
        PdfPCell customerInfoCell = new PdfPCell();
        customerInfoCell.addElement(new Chunk(dealerName);
        customerInfoTable.addCell(customerInfoCell);

        containerCustomerInfo.addElement(customerInfoTable);
        coverTable.addCell(containerCustomerInfo);
        coverTable.addCell("");  

The problem is with the cell ciTitle which I applied the horizontal alignment to right. The string "Customer Info" is shown always to left ignoring my setting (I've tried also ALIGN_MIDDLE and ALIGN_CENTER).

Could someone help me?

Thanks

Suxper

Suxper
  • 31
  • 5
  • OK, your question isn't an exact duplicate of [How to right-align text in a PdfPCell?](http://developers.itextpdf.com/question/how-right-align-text-pdfpcell) but the answer is identical: you're setting the alignment in *text mode*, but you're creating the cell in *composite mode*. If you work in composite mode, the horizontal alignment defined at the cell mode will be ignored in favor of the horizontal alignment of the elements in this cell. This question has been answered many times before. Please read the [documentation](http://developers.itextpdf.com/). – Bruno Lowagie Mar 17 '16 at 05:07
  • Thanks a lot! I didn't see that question because was for c#, I didn't think to search also for other language. – Suxper Mar 17 '16 at 08:29

0 Answers0