I'm having multiple problems trying to insert a table into my document.  I've
included a sample to demonstrate most of them, but there's one I can't
reproduce.

If you run the sample below, you'll see the following bugs:

- Header and footer are missing from the first page.  Since no content was
added to the page at that point, the header and footer should appear
properly.  Similarly, headers and footers should be changeable after newPage
has been called, but before content is added.  I guess this qualifies as a
suggestion, but it would help lots of people.

OK, here are the REAL bugs:

Page 1:
- Extra blank row at bottom of table.
- Large space above cell text, no space below, even though I set all spacing
parameters to zero.
- Heavy border on bottom of table, even though it's not actually the end of
the table.

Page 2:
- Extra blank row at top of table.  If you reduce the number of "content"
paragraphs to 35, you'll lose the blank row, but the top row will be
over-tall by a full line.
- Text not aligned with table borders.
- Heavy border on top of table, even though it's not actually the start of
the table.

Page 3:
- No header.
- Footer pushed onto page 4.

Page 4:
- Page 3 footer at the top, but otherwise fine.

And one more bug:  In my main app, if I turn off the fake "content"
paragraphs, the table won't appear at all.  It seems to only appear if it
touches the bottom of the page.  I can't reproduce it in this test app
though.

Any workarounds would be appreciated.  Respond to the list, I'll see it in
the archive.

-Bill



import java.io.*;

import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;

public class TableFormatBug {
        
        static String[] clauses = {
                "52.203-3", "XXXXXXXXXX",
                "52.203-5", "XXXXXXXX XXXXXXX XXXXXXXXXX XXXX",
                "52.203-7", "XXXX-XXXXXXXX XXXXXXXXXX",
                "52.203-8", "XXXXXXXXXXXX, XXXXXXXXXX, XXX XXXXXXXX XX XXXXX
XXX XXXXXXX XX XXXXXXXX XXXXXXXX",
                "52.211-10", "XXXXXXXXXXXX, XXXXXXXXXXX, XXX XXXXXXXXXX XX
XXXX",
                "52.211-12", "XXXXXXXXXX XXXXXXX -- XXXXXXXXXXXX",
                "52.215-21 ALT II", "XXXXXXXXXXXX XXX XXXX XX XXXXXXX XXXX XX
XXXXXXXXXXX XXXXX XXXX XXXX XX XXXXXXX XXXX --XXXXXXXXXXXXX (XXX 0000)
XXXXXXXXX XX",
                "52.216-24", "XXXXXXXXXX XX XXXXXXXXXX XXXXXXXXX",
                "52.216-25", "XXXXXXXX XXXXXXXXXXXXXX",
                "52.225-13", "XXXXXXXXXXXX XX XXXXXXX XXXXXXX XXXXXXXXX",
                "52.232-5", "XXXXXXXX XXXXX XXXXX-XXXXX XXXXXXXXXXXX
XXXXXXXXX",
                "52.232-27", "XXXXXX XXXXXXX XXX XXXXXXXXXXXX XXXXXXXXX",
                "52.233-3", "XXXXXXX XXXXX XXXXX",
                "52.233-4", "XXXXXXXXXX XXX XXX XXXXXX XX XXXXXXXX XXXXX",
                "52.236-5", "XXXXXXXX XXX XXXXXXXXXXX",
                "52.236-7", "XXXXXXX XXX XXXXXXXXXXXXXXXX ",
                "52.236-15", "XXXXXXXXX XXX XXXXXXXXXXXX XXXXXXXXX",
                "52.244-6", "XXXXXXXXXXXX XXX XXXXXXXXXX XXXXX",
                "52.253-1", "XXXXXXXX XXXXXXXXX XXXXX",
        };                      
        
        
        public static void main(String[] args) throws FileNotFoundException,
DocumentException {
                Document document = new Document();
                PdfWriter.getInstance(document, new
FileOutputStream("table_bug.pdf"));
                document.open();
        
                HeaderFooter header = new HeaderFooter(new Phrase("Project
Title"), false);
                header.setBorder(Rectangle.NO_BORDER);
                document.setHeader(header);

                HeaderFooter footer = new HeaderFooter(new Phrase("Section#
Document Title              Page: "), new Phrase(" "));
                footer.setAlignment(Element.ALIGN_CENTER);
                footer.setBorder(Rectangle.NO_BORDER);
                document.setFooter(footer);
                document.resetPageCount();
                document.newPage();
                
//              document.open();
                processXML( document );

                // append blank page
                document.newPage();
                document.add(Chunk.NEWLINE);

                document.close();
        }

        public static void processXML( Document document ) throws
DocumentException {
                Table curTable = null;
                
                document.newPage();

                // push table across page break
                for( int i=0; i<38; i++ )  document.add(new
Paragraph("content"));

                for( int i=0; i<clauses.length; i+=2 ) {
                        if( curTable == null ) {
                                curTable = new Table( 3 );
                                curTable.setWidth( 100 );  // percent
                                curTable.setWidths( new int[] { 85, 315, 50 }
);  // relative weights
                                curTable.setPadding(0);  //??
                                curTable.setSpaceInsideCell(0);  //between
border and text
                                curTable.setSpacing(0);  //between cell
borders
                                curTable.setCellsFitPage( true );  //no
single cell should span pages
                        }
                        curTable.addCell( clauses[i] );
                        curTable.addCell( clauses[i+1] );
                        curTable.addCell( clauses[i] );
                }
                                
                if( curTable != null ) {
                        document.add( curTable );
                        curTable = null;
                }
        }
}


-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid7521&bid$8729&dat1642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to