Hi group,

We need to update the PDF by inserting a table at runtime as the data in the 
table is dynamic. We trying the following code which is able to insert the 
table but overlaps
Existing text. Could someone please suggest if this the right way of doing this 
or any other pointers will help?

PdfReader reader = new PdfReader("abc.pdf");
 Color textColor = Color.CYAN;
 BaseColor baseColor = new BaseColor(textColor);
 PdfStamper stamper = new PdfStamper(reader, new 
FileOutputStream("stamped.pdf"));
  stamper.insertPage(1, PageSize.A4);
  AcroFields form = stamper.getAcroFields();
   List<AcroFields.FieldPosition> fieldPosition = 
form.getFieldPositions("Placehoder10");
   Object[] obj = fieldPosition.toArray();
   PdfContentByte directcontent = 
stamper.getOverContent(((AcroFields.FieldPosition)obj[0]).page);
      PdfImportedPage p = stamper.getImportedPage(reader, 
((AcroFields.FieldPosition)obj[0]).page);
      float f = 600;
      ColumnText col = new ColumnText(directcontent);
   col.setAlignment(Element.ALIGN_CENTER);
PageSize.A4.getWidth()-36, PageSize.A4.getHeight()-300);
   col.setSimpleColumn(10,10,500,500);

      PdfPTable table = new PdfPTable(3);
      table.setWidthPercentage(100f);

      PdfPCell cell =null;

      for (int m = 0; m < 3; m++)
      {

      for (int l = 0; l < 3; l++)
      {
      cell = new PdfPCell();
      cell.setBackgroundColor(new BaseColor(Color.BLUE));
      cell.setMinimumHeight(1f);
      cell.addElement(new Chunk("Testing the PDF" + l + " "+ m ));
      table.addCell(cell);

      }
      }
      col.addElement(table);

      int currentColumn =0;
      while (true)
      {
      int status = col.go();
      if ((status & ColumnText.NO_MORE_TEXT) != 0)
      {
      break;
      }
      ++currentColumn;
      if(currentColumn>=1){
      break;
      }

      }
   stamper.setFreeTextFlattening(true);
   stamper.close();

   stamper.close();
  }


Thanks,

Dilpreet Singh
Sales Express Dev Lead.
Home Equity Group

Wells Fargo & Company | 550 California Street | 11th Floor | San Francisco, CA 
94104
Mac: A0112-116
Tel 415-947-4966 | Cell 812-223-2065
[email protected]<mailto:[email protected]>

"This message may contain confidential and/or privileged information. If you 
are not the addressee or authorized to receive this for the addressee, you must 
not use, copy, disclose, or take any action based on this message or any 
information herein. If you have received this message in error, please advise 
the sender immediately by reply e-mail and delete this message. Thank you for 
your cooperation."



------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to