Customizing align PdfPTable in iText 2.1.7

402 views Asked by At

I'm using iText 2.1.7 and I am new to iText; I want to know can we custom align table:

enter image description here

I have already tried using (.setHorizontalAlignment(Element.ALIGN_LEFT)) but my table is starting from quite left I want to align it with my other table

    // TOP 5 BUYER TABLE      
    try {
        document.add(new Paragraph("\n"));
        PdfPTable TopBuyerTable = new PdfPTable(5);
        TopBuyerTable.setWidthPercentage(95);
        float[] columnwidth = { 1, 1,1,1,1};
        TopBuyerTable.setWidths(columnwidth);

     for(int i=1;i<=5;i++) {
        TopBuyerTable.addCell(new PdfPCell(new Phrase("Buyer"+i,footFont)));
        TopBuyerTable.addCell(new PdfPCell(new Phrase("  ",footFont)));
        TopBuyerTable.addCell(new PdfPCell(new Phrase("Turnover",footFont)));
        TopBuyerTable.addCell(new PdfPCell(new Phrase("Rs. ___ Lacs",footFont)));
        TopBuyerTable.addCell(new PdfPCell(new Phrase("No of years of relationship",footFont)));
        TopBuyerTable.completeRow();
     }

        document.add(TopBuyerTable);

    }
    catch (Exception e) {
        e.printStackTrace();
    }

    try {
        document.add(new Paragraph("\n"));
        PdfPTable  BeneficialOwnerTable = new PdfPTable(3);
        BeneficialOwnerTable.setWidthPercentage(30);
        BeneficialOwnerTable.setHorizontalAlignment(Element.ALIGN_LEFT);
        float[] columnwidth = { 1, 1,1};
        BeneficialOwnerTable.setWidths(columnwidth);

        //Row 1
        PdfPCell pCell1;
        pCell1 = new PdfPCell(new Phrase("(Add multiple if required) 
                                                   ",footFont));    
        pCell1.setColspan(3);
        pCell1.setPadding(2);
        BeneficialOwnerTable.addCell(pCell1);                
        BeneficialOwnerTable.completeRow();

        //Row 2

        BeneficialOwnerTable.addCell(new PdfPCell(new 
                                         Phrase("Name",footFont)));
        BeneficialOwnerTable.addCell(new PdfPCell(new Phrase("   
                                                     ",footFont)));
        BeneficialOwnerTable.addCell(new PdfPCell(new 
                                        Phrase("*****",footFont)));
        BeneficialOwnerTable.completeRow();

        document.add(BeneficialOwnerTable);
    } catch (Exception e) {
        e.printStackTrace();
    }

When I used align_left, I expected it to align with other table's but its not doing that.

Thanks in advance

Here's a screenshot of the issue I'm facing

0

There are 0 answers