I am trying to generate a pdf using iText and java and following is the code used but i am not able to align the text at the center of the PdfPCell, though i have gone through all links on google and tried setting setHorizontalAlignment(Element.ALIGN_CENTER); but this doesn't work for me.
Table with Cells:
PdfPTable heading1=new PdfPTable(3);
            try{
            heading1.setWidths(new int[]{1,1,1});
            heading1.setTotalWidth(527);
            heading1.setLockedWidth(true);
            heading1.getDefaultCell().setBorder(Rectangle.NO_BORDER);
            heading1.getDefaultCell().setFixedHeight(40);
            /* PdfPCell heading1Text1 = new PdfPCell();
             heading1Text1.setBorder(Rectangle.NO_BORDER);
             heading1Text1.addElement(new Phrase("", new Font(Font.FontFamily.HELVETICA, 12))); 
             heading1Text1.setUseAscender(true);
             heading1Text1.setHorizontalAlignment(Element.ALIGN_CENTER);
             heading1.addCell(heading1Text1);*/
             PdfPCell heading1Text2 = new PdfPCell();
             heading1Text2.setColspan(3);
             heading1Text2.setBorder(Rectangle.NO_BORDER);
             heading1Text2.setHorizontalAlignment(Element.ALIGN_CENTER);
             heading1Text2.addElement(new Phrase("RECEIPT", new Font(Font.FontFamily.HELVETICA, 12,Font.BOLD))); 
             heading1.addCell(heading1Text2);
            /* PdfPCell heading1Text3 = new PdfPCell();
             heading1Text3.setBorder(Rectangle.NO_BORDER);
             heading1Text3.addElement(new Phrase("", new Font(Font.FontFamily.HELVETICA, 12))); 
             heading1.addCell(heading1Text3);*/
                // write content
                document.add(heading1);
        }catch(DocumentException d){
            throw new ExceptionConverter(d);
        }