o.k. so I figured it out, guess I have to just memorize the api :-)

basically I had to create ColumnText in the PdfTemplate

Here is a code snipet:

                Document pdf = new Document();

                try {
                        // define the size of our text box
                        float   tbWidth     = 216f; // 3 inches
                        float   tbHeight    = 144f; // 2 inches

                        // some text to fill the box
                        String  line        = "This is a long line of text to see 
if it wraps. "
                                                                + "This is a long line 
of text to see if it wraps. "
                                                                + "This is a long line 
of text to see if it wraps. "
                                                                + "This is a long line 
of text to see if it wraps. "
                                                                + "This is a long line 
of text to see if it wraps. "
                                                                + "This is a long line 
of text to see if it wraps. "
                                                                + "This is a long line 
of text to see if it wraps. "
                                                                + "This is a long line 
of text to see if it wraps. "
                                                                + "This is a long line 
of text to see if it wraps. "
                                                                + "This is a long line 
of text to see if it wraps.";

                        PdfWriter w = PdfWriter.getInstance(pdf, new 
FileOutputStream("test.pdf"));

                        pdf.open();

                        PdfContentByte cb = w.getDirectContent();

                        PdfTemplate template = cb.createTemplate(tbWidth, tbHeight);

                        // put our text into a phrase
                        Font        font    = new Font(Font.COURIER, 12f, Font.NORMAL);
                        Phrase      p       = new Phrase(line, font);

                        // define our column text using the template as the Content 
Byte
                        ColumnText  ct      = new ColumnText(template);
                        ct.setSimpleColumn(p, 0, 0, tbWidth, tbHeight, 
font.leading(1), p.ALIGN_LEFT);
                        ct.go();

                        // place our text box in the very center of the page
                        float   x   = (pdf.getPageSize().width()-tbWidth)/2;
                        float   y   = (pdf.getPageSize().height()-tbHeight)/2;
                        cb.addTemplate(template, x, y);

                        // and in the lower left corner of the page just for fun
                        cb.addTemplate(template, 0, 0);
                }
                catch(DocumentException de)
                {
                        System.err.println(de.getMessage());
                }
                catch(IOException ioe)
                {
                        System.err.println(ioe.getMessage());
                }

                pdf.close();

So, Is this the best way to do this? Has any one discovered another way 
to place wrapped text on the page?


-jason


On Friday, May 31, 2002, at 04:40  PM, Jason Essington wrote:

> Hi
>
> I am trying to figure out how to create a "text area" (say a box that 
> is 3"x2" in which text wraps) that I can place in an absolute position 
> on a page.
>
> I have discovered templates, but text added to a template just gets 
> clipped when it hits the edge of the template rather than wrapping.
>
> anyone have any Idea to do this?
>
> thanks
>


_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm

_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to