I started with the Table in the Standard library that comes with LCD 8.2

Then I created 6 rows and 2 columns.  Placed static text titles on left
columns and placed text fields on right columns.  Then all fields I
checked "allow multiple lines".

Then I did a "save as" a dynamic PDF. 

 

When I use iText to fill in the fields, the table grows as expected when
the field data is larger than what would fit in the text field without a
scrollbar. In other words, the text field grows in height, and the table
row expands vertically to accommodate the taller text field - and table
rows even bump off to the next page when there is not enough room on the
current page. But if I flatten the fields, the table does not grow, and
any text that is too large to fit in the text field no longer displays. 

 

Is there a way to flatten the fields after the table has already grown,
so that the table rows have the necessary height to accommodate all the
text, and rows get bumped to the next page when necessary?

 

Here's the code that illustrates my issue:

 

public class TableTest
{

    public void testTable() throws Exception
    {
        PdfStamper ps = null; 
        try 
        { 
            // read existing PDF document 
            PdfReader r = new PdfReader( "content/pdf/test_table.pdf");
            ps = new PdfStamper(r, new
FileOutputStream("content/pdf/test_table_out.pdf")); 
            // retrieve properties of PDF form w/AcroFields object 
            AcroFields af = ps.getAcroFields(); 
            Iterator i = af.getFields().keySet().iterator();
            
            while (i.hasNext())
            {
                String s = i.next().toString();

                // set a bunch of text into the field so that it has to
grow to fit the text.
                af.setField(s, "1 adsfasdff as fasd fasdf asdf asdf asdf
asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf\n2 asdf asdf asdf asdf
asdf asdf asdf asdf asdf asdf asdf\n3 asdf asdf asdf asdf asdf asdf adsf
asdf asdf asdf asdf asdf asdf asdf asdf asdf\n4 asdf asdf asdf asdf adf
asdf asdf asdf asdf asdf adf adf\n5 asdf adf asdf adf adf adf adsf adf
adf adsf asdf asdf adf\n6 adf adsf asdf adsf asdf asdf adsf asd\n1
adsfasdff as fasd fasdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
asdf asdf asdf asdf\n2 asdf asdf asdf asdf asdf asdf asdf asdf asdf asdf
asdf\n3 asdf asdf asdf asdf asdf asdf adsf asdf asdf asdf asdf asdf asdf
asdf asdf asdf\n4 asdf asdf asdf asdf adf asdf asdf asdf asdf asdf adf
adf\n5 asdf adf asdf adf adf adf adsf adf adf adsf asdf asdf adf\n6 adf
adsf asdf adsf asdf asdf adsf asd "); 
                af.regenerateField(s);
            }

            // make resultant PDF read-only for end-user 

            // If I comment out this line, the table flows to multiple
pages,

            // and each row is as tall as it needs to be to accommodate
all the text.

            // But if I leave the line uncommented, the resulting PDF is
only one page

            // and the text is cropped at the height of the original
text field.
            ps.setFormFlattening(true); 
        }
        finally 
        { 
            if (ps != null) ps.close(); 
        } 
    }
} 

 

Thanx,

adam

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to