Use ColumnText.setSimpleColumn() to place the text in the new page and
ColumnText.setCanvas() to set it to the PdfContentByte of the page.

Best Regards,
Paulo Soares

----- Original Message ----- 
From: "Merlyn Mathias" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, October 12, 2004 17:25
Subject: [iText-questions] ColumnText


> Hi Paulo,
>
> I am here with another question.
>
> I have a fixed size form which is populated using pdfstamper. I use the
> following code :
>
> ColumnText text = new ColumnText(stamper.getOverContent(1));
>     text.addText(new Phrase(value, FontFactory.getFont
> (FontFactory.COURIER, 12, Font.NORMAL)));
>
>          AcroFields.Item item = form.getFieldItem(field);
>
>           if (item != null)
>           {
>               int pageN =  ((Integer)item.page.get(0)).intValue();
>               text.setCanvas(stamper.getOverContent(pageN));
>               float[] position = form.getFieldPositions(field);
>               text.setSimpleColumn(position[1], position[2], position[3],
> position[4]);
>               text.setAlignment(Element.ALIGN_JUSTIFIED);
>           }
>
>         if ((text.go() & ColumnText.NO_MORE_TEXT) == 0)
> overflowFields.put(name, text);
>
>
> I want to display the remaining data at the end of the document, so I
store it
> in a map for later use.
>
> Now at the end of the page, I have a map (overflowFields) with String as
key
> and the value could be either String or ColumnText.
>
> public byte[] drawAppendix(Map appendixFields) throws DocumentException
>   {
>       if (overflowFields == null || overflowFields.size() == 0)
>           return null;
>
>       Document doc = new Document(reader.getPageSize(1));
>
>       ByteArrayOutputStream appendix = new ByteArrayOutputStream();
>       //PdfWriter tempWriter = PdfWriter.getInstance(doc, appendix);
>
>       Font headerFont = FontFactory.getFont(FontFactory.HELVETICA, 12,
> Font.BOLD);
>       Font footerFont = FontFactory.getFont(FontFactory.HELVETICA, 10);
>
>
>       HeaderFooter header = new HeaderFooter(new Phrase("Appendix",
> headerFont), false);
>       header.setBorder(Rectangle.BOX);
>       header.setAlignment(HeaderFooter.ALIGN_CENTER);
>       doc.setHeader(header);
>
>
>       HeaderFooter footer = new HeaderFooter(new Phrase("Appendix Page ",
> footerFont), true);
>       footer.setBorder(Rectangle.NO_BORDER);
>       footer.setAlignment(HeaderFooter.ALIGN_CENTER);
>       doc.setFooter(footer);
>
>
>       doc.open();
>
>      // PdfContentByte cb = tempWriter.getDirectContent();
>
>       Iterator iter = new TreeSet(overflowFields.keySet()).iterator();
>
>       Table table = new Table(1);
>       table.setBorder(Rectangle.BOX);
>       table.setWidth(100);
>       table.setPadding(5);
>
>
>       while (iter.hasNext())
>       {
>           String key = ((String) iter.next()).trim();
>           String name = (String) appendixFields.get(key);
>           Object value = overflowFields.get(key);
>
>           Cell cell = new Cell();
>           Chunk chunk1 = new Chunk(name + "\n", FontFactory.getFont
> (FontFactory.HELVETICA, 10, Font.BOLD));
>           cell.add(chunk1);
>
>           if (value instanceof ColumnText)
>           {
>               ColumnText text = (ColumnText) value;
>               // Here I want to add the remaining text to the table
>
>           }
> else
>                     {
>               Chunk chunk2 = new Chunk((String)value, FontFactory.getFont
> (FontFactory.COURIER, 12));
>
>               cell.add(chunk2);
>           }
>
>           table.addCell(cell);
>
>       }
>
>       doc.add(table);
>
>       doc.close();
>
>      return appendix.toByteArray();
>
>   }
>
>
> It works fine with strings. I could not figure out how to do it with
> columntext. Now I want all the data to display here so I dont know how to
set
> the column size. and if the data doe not fit in one page, it should grow
to
> the next page.
>
> Thank you so much.
> Merlyn.
>
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
> Use IT products in your business? Tell us what you think of them. Give us
> Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out
more
> http://productguide.itmanagersjournal.com/guidepromo.tmpl
> _______________________________________________
> iText-questions mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/itext-questions



-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to