0
votes

we are using iText PDFPTable. The problem we are facing is because of the following line of code:

table.setHeaderRows(headerRows);

This piece of code works fine in local environment (WAS hosted in windows), but doesn't work, alignment is messed up, in dev server (WAS hosted in Unix). We are unable to figure out what the problem is, as in both cases IE is used. Can someone please answer why alignment issues come up in dev server? adding more code... method creating standard table:

 public PdfPTable createStandardTable(int columnCount, int headerRows) {
    zebraTable = true;
    horizontalBorders = false;

    PdfPTableEvent tableEvent = new PdfPTableEvent()
    {
        // begin (another) anonymous inner class extends PdfPTableEvent
        @Override
        public void tableLayout(PdfPTable table, float[][] width, float[] height,
                int headerRows, int rowStart, PdfContentByte[] canvas) {
            // code provided by Bruno Lowagie, author of iText, via StackOverflow.
            float widths[] = width[0];
            float x1 = widths[0];
            float x2 = widths[widths.length - 1];
            float y = height[height.length - 1];
            PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
            cb.moveTo(x1, y);
            cb.lineTo(x2, y);
            cb.setColorStroke(TABLE_BORDER_COLOR);
            cb.stroke();
        }
        // end anonymous inner class extends PdfPTableEvent
    };

    PdfPTable table = tableCreationHelper(columnCount, headerRows);
    table.setTableEvent(tableEvent);
    return table;
}

private helper method

private PdfPTable tableCreationHelper(int columnCount, int headerRows) {
    PdfPTable table = new PdfPTable(columnCount);
    table.setSpacingBefore(TABLE_SPACING);
    table.setSpacingAfter(TABLE_SPACING);
    table.setWidthPercentage(TABLE_WIDTH_PERCENT);
    table.setHeaderRows(headerRows);
    return table;
}

please let me know if you need more information

Thanks much, Babu.

1
"Can someone please answer why alignment issues come up in dev server?" - hardly: Unless you provide enough code and information to allow proper analysis, you ask for pure guesswork. - mkl
I added more code for clarity, please let me know if you need more information. - Bab
Well, that's still not enough code to run, you should try to provide a sscce which still delivers different results in those environments. Before, though, you can try and share two PDFs, one from each of your environments, which should look the same but don't. Probably something can be derived from there contents. - mkl

1 Answers

0
votes

I figured out the issue. Dev server had iText version 5.5.0, where as local configuration is 5.5.2. setHeadersRow function of iText 5.5.0 messed up the alignment.