Hi, I am using iText 5.0.6 for Java.

I am basically making a report in a pdf using 1 big table. I am using cell
padding to make a little extra space between each row so it is easier to
read, but I don't want this extra spacing to appear with the first row,
below the header, on new pages. 
I want to know is it possible somehow to change or remove some formatting
from the first row on a new page of the table? 

My example report with the issue (on page 2): 
http://rveach.romhack.org/AcReport.pdf Report.pdf 
My code:
------------------------------------------------------
        public ActionForward executeFirstTimeInLogic(ActionMapping mapping,
                        ActionForm form, HttpServletRequest request,
                        HttpServletResponse response) throws Exception {

                populateReportData();

                List<DbTableCodes> columns = ccbForm.getReportColumns();
                int columnCount = columns.size();

                if (columnCount == 0)
                        throw new Exception(
                                        "Trying to create a PDF Report Table 
with no Columns");

                List<CCBHolder> data = ccbForm.getUserCcbs();
                String reportTitle = "ORSIS Change Control Board - "
                                + ccbForm.getReportTitle();
                float widths[] = new float[columnCount];
                String columnNames[] = new String[columnCount];

                Document document = new Document(PageSize.A4.rotate(), 21, 21, 
20, 20);
                ByteArrayOutputStream out = new ByteArrayOutputStream();

                PdfWriter writer = PdfWriter.getInstance(document, out);
                writer.setPageEvent(new ReportHeaderFooter(reportTitle, 
dateTimeFormat
                                .format(Calendar.getInstance().getTime())));

                document.open();

                // //////////////////////////////

                Paragraph p;

                p = createCenterText(reportTitle, header1);
                p.setSpacingAfter(0.0f);
                p.setSpacingBefore(0.0f);
                document.add(p);

                p = createCenterText("Between "
                                + 
dateFormat.format(ccbForm.getProductionDateStart()) + " and "
                                + 
dateFormat.format(ccbForm.getProductionDateEnd()), header2);
                p.setSpacingAfter(0.0f);
                p.setSpacingBefore(-3.0f);
                document.add(p);

                p = createCenterText("Report Date/Time: "
                                + 
dateTimeFormat.format(Calendar.getInstance().getTime()),
                                header3);
                p.setSpacingAfter(20.0f);
                p.setSpacingBefore(-1.0f);
                document.add(p);

                PdfPTable table = new PdfPTable(columns.size());
                table.setHorizontalAlignment(Element.ALIGN_CENTER);
                table.setWidthPercentage(100);

                Iterator<DbTableCodes> itrCol = columns.iterator();
                int pos = 0;

                while (itrCol.hasNext()) {
                        switch (itrCol.next()) {
                        case CCB_NUMBER:
                                columnNames[pos] = "CCB #";
                                widths[pos] = 75;
                                break;
                        case REQUESTOR_NAME:
                                columnNames[pos] = "Requestor Name";
                                widths[pos] = 0;
                                break;
                        case REQUEST_TYPE:
                                columnNames[pos] = "Request Type";
                                widths[pos] = 120;
                                break;
                        case PRODUCTION_DATE:
                                columnNames[pos] = "Production Date";
                                widths[pos] = 100;
                                break;
                        case PROJECT_TITLE:
                                columnNames[pos] = "Project Title";
                                widths[pos] = 0;
                                break;
                        case PROJECT_TYPE:
                                columnNames[pos] = "Project Type";
                                widths[pos] = 90;
                                break;
                        case USER_REPRESENTATIVE_NAME:
                                columnNames[pos] = "Sponsor Contact";
                                widths[pos] = 0;
                                break;
                        case CAPRS_NUMBER:
                                columnNames[pos] = "CAPRS/\nPAIRS/QC#";
                                widths[pos] = 95;
                                break;
                        case CAPRS_DESCRIPTION:
                                columnNames[pos] = 
"CAPRS/PAIRS/QC#<br>Description";
                                widths[pos] = 0.4f;
                                break;
                        case CAPRS_CHANGE_DESCRIPTION:
                                columnNames[pos] = 
"CAPRS/PAIRS/QC#\nDescription of Change\nfor Users";
                                widths[pos] = 0.4f;
                                break;
                        }

                        table.addCell(createCell(columnNames[pos], tableHeader,
                                        tableHeaderBG, false));

                        pos++;
                }

                table.setHeaderRows(1);
                fixWidths(widths, totalTableWidth);

                table.setWidths(widths);

                if (data.size() > 0) {
                        Iterator<CCBHolder> itr = data.iterator();
                        boolean lightBG = true;
                        first = true;

                        while (itr.hasNext()) {
                                CCBHolder holder = itr.next();

                                itrCol = columns.iterator();
                                while (itrCol.hasNext()) {
                                        
table.addCell(createCell(BeanUtils.getProperty(holder,
                                                        
itrCol.next().getColumn()), tableData,
                                                        (lightBG ? tableLightBG 
: tableDarkBG), true));
                                }

                                lightBG = !lightBG;
                                first = false;
                        }
                } else {
                        PdfPCell cell = createCell("No CCB entries to 
display.", tableData,
                                        tableLightBG, true);
                        cell.setColspan(columnCount);
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        table.addCell(cell);
                }

                document.add(table);

                // //////////////////////////////

                document.close();
                response.setContentType("application/pdf");
                response.setContentLength(out.size());
                out.writeTo(response.getOutputStream());

                return null;
        }

        public ActionForward executeSubmitLogic(ActionMapping mapping,
                        ActionForm form, HttpServletRequest request,
                        HttpServletResponse response) throws Exception {
                return executeFirstTimeInLogic(mapping, form, request, 
response);
        }

        public void fixWidths(float widths[], float totalWidth)
                        throws Exception {
                // > 1 - actual width of column
                // > 0 && <= 1 - width of column in percentage of entire table
                // 0 - free form column based on space left
                // < 0 - width of column in percentage of space left

                int size = widths.length;
                float spaceTaken = 0;
                boolean more = false;

                for (int pos = 0; pos < size; pos++) {
                        if (widths[pos] > 1) {
                                spaceTaken += widths[pos];
                        } else if ((widths[pos] <= 1) && (widths[pos] > 0)) {
                                widths[pos] = totalWidth * widths[pos];
                                spaceTaken += widths[pos];
                        } else {
                                more = true;
                        }
                }

                if (spaceTaken > totalWidth)
                        throw new Exception(
                                        "Width of columns goes beyound the 
Total Width of the table");

                if (more) {
                        float spaceRemaining = totalWidth - spaceTaken;
                        int freeCount = 0;

                        for (int pos = 0; pos < size; pos++) {
                                if (widths[pos] < 0) {
                                        widths[pos] = spaceRemaining * 
(-widths[pos]);
                                        spaceTaken += widths[pos];
                                } else if (widths[pos] == 0) {
                                        freeCount++;
                                }
                        }

                        if (spaceTaken > totalWidth)
                                throw new Exception(
                                                "Width of columns goes beyound 
the Total Width of the table");

                        if (freeCount > 0) {
                                spaceRemaining = totalWidth - spaceTaken;

                                for (int pos = 0; pos < size; pos++) {
                                        if (widths[pos] == 0) {
                                                widths[pos] = spaceRemaining / 
freeCount;
                                        }
                                }
                        }
                }
        }

        public Paragraph createCenterText(String text, Font font) {
                Paragraph p = new Paragraph(text, font);
                p.setAlignment(Element.ALIGN_CENTER);
                return p;
        }

        public PdfPCell createCell(String text, Font font, BaseColor color,
                        boolean data) {
                PdfPCell cell = new PdfPCell(new Paragraph((text == null ? "" : 
text),
                                font));
                cell.setVerticalAlignment(Element.ALIGN_CENTER);
                cell.setBackgroundColor(color);
                cell.setBorder(0);
                cell.setNoWrap(false);
                cell.setMinimumHeight((text == null ? 16.0f : 28.0f));
                cell.setPaddingRight(15.0f);
                if (data) {
                        if (!first) {
                                cell.setPaddingTop(10.0f);
                        }
                        cell.setPaddingBottom(14.0f);
                } else {
                        cell.setPaddingBottom(6.0f);
                        // makes it look more even
                }
                return cell;
        }
------------------------------------------------------

--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/How-to-remove-some-table-formatting-on-first-row-of-new-page-tp3520449p3520449.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to