Hi

 

I am using iText 1.1 jar and using the Table Object instead of the PdfPTable
as we want the code to be consistent for Html reports. I am having a problem
where my first data record is repeating on every page. Attached is the
output file. I have set the headerRows as 1 as in:

 

   

 

     public void report() throws FileNotFoundException, DocumentException

    {

        Document doc = createDocument();

        try

        {

            Table table = createTable(doc);

            defineHeadings(table, columnInfos);           

            table.setLastHeaderRow(1);

            writeData(table);

            doc.add(table);

        }

        finally

        {

            closeDocument(doc);

        }

    }

 

 

   private Table createTable(Document doc) throws BadElementException

    {

        // create a table and put data into it

        Table table = new Table(columnInfos.length);

 

        // make table give contents of cells a little breathing room inside
cell

        table.setPadding(3);

        table.setSpacing(3);

        table.setAutoFillEmptyCells(true);

        table.setCellsFitPage(true);

 

        return table;

    }

 

  

      */

    public static void defineHeadings(Table table, ColumnInfo[] colInfos)
throws BadElementException

    {

        int[] widths = new int[colInfos.length];

        for (int i = 0; i < colInfos.length; i++)

        {

            ColumnInfo ci = colInfos[i];

            String heading = ci.getLabel();

            table.addCell(header(heading));

            widths[i] = ci.getWidth();

        }

        

        //add up the widths and set them on the table

        int totalAllocated = 0;

        int columnCount = 0;

        for(int i = 0; i<widths.length; i++)

        {

            if(widths[i] > -1)

            {

                totalAllocated+=widths[i];

            }

            else

            {

                columnCount++;

            }

        }

        

        int remaining = 100-totalAllocated;

        if(columnCount > 0)

        {

            int divWidth = remaining/columnCount;

            for(int i=0; i<widths.length; i++)

            {

                if(widths[i] < 0)

                {

                    widths[i] = divWidth;

                }

            }

        }

        try

        {

            table.setWidths(widths);

        }

        catch (DocumentException e)

        {

            //eat it

        }

        table.endHeaders();

    }

 

 

    static Cell header(String contents) throws BadElementException

    {

        Font font = FontFactory.getFont(FontFactory.HELVETICA, 10,
Font.BOLD);

        Phrase styledContent = new Phrase(contents, font);

        Cell cell = new Cell(styledContent);

        cell.setHeader(true);

        return cell;

   }

 

Can you let me know where am going wrong? Please let me know.

 

Thanks

arif

Attachment: Test Audit Report 2a.pdf
Description: Adobe PDF document

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to