Example usage for com.lowagie.text.pdf PdfPTable getRows

List of usage examples for com.lowagie.text.pdf PdfPTable getRows

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable getRows.

Prototype

public ArrayList getRows() 

Source Link

Document

Gets an arraylist with all the rows in the table.

Usage

From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java

License:Open Source License

private static void addTable(Document pdfDocument, Chapter pdfSheet, int totalWidth, float[] widths,
        PdfPTable pdfTable) throws Exception {
    final int MAX_WIDTH = (int) (pdfDocument.getPageSize().getWidth() / 842 * 65000);
    //      if(totalWidth>MAX_WIDTH) {
    //Split the tables in subcolumns
    for (int offset = 0; offset < pdfTable.getNumberOfColumns();) {
        if (offset > 0)
            pdfSheet.add(new Chunk(" "));

        //Calculates the indexes that fit the page: [offset; index2]
        int subTotalWidth = 0;
        int index2;
        for (index2 = offset; index2 < pdfTable.getNumberOfColumns() && subTotalWidth < MAX_WIDTH; index2++) {
            subTotalWidth += widths[index2] * totalWidth;
        }/*from  w  w w  . j  a v  a2s . c o m*/
        index2 = Math.min(index2, pdfTable.getNumberOfColumns() - 1);

        //Calculates the new sub widths
        float[] subWidths = new float[index2 - offset + 2];
        for (int i = 0; i < subWidths.length - 1; i++) {
            subWidths[i] = widths[offset + i] * totalWidth / MAX_WIDTH;
        }
        subWidths[subWidths.length - 1] = Math.max(0, (float) (MAX_WIDTH - subTotalWidth) / MAX_WIDTH);
        System.out.println("PDFUtils.addTable() " + Arrays.toString(subWidths));

        //Creates the new sub widths
        PdfPTable subtable = new PdfPTable(subWidths.length);
        subtable.setWidths(subWidths);
        for (int r = 0; r < pdfTable.getRows().size(); r++) {
            for (int c = 0; c < index2 - offset + 1; c++) {
                PdfPCell cell = pdfTable.getRow(r).getCells()[c + offset];
                subtable.addCell(cell);
            }
            PdfPCell pdfCell = new PdfPCell();
            pdfCell.setBorder(0);
            subtable.addCell(pdfCell);
        }

        subtable.setWidthPercentage(100);
        collapseBorder(subtable);
        pdfSheet.add(subtable);

        //Go to the next index offset
        offset = index2 + 1;
    }
    //      } else {
    //         //Calculates the new sub widths
    //         float[] subWidths = new float[widths.length+1];
    //         for (int i = 0; i < subWidths.length-1; i++) {
    //            subWidths[i] = widths[0]*totalWidth/MAX_WIDTH;
    //         }
    //         subWidths[subWidths.length-1] = Math.max(0, (float)(MAX_WIDTH-totalWidth)/MAX_WIDTH);
    //         pdfTable.setWidths(subWidths);
    //         pdfTable.setWidthPercentage(100);
    //         collapseBorder(pdfTable);
    //         pdfSheet.add(pdfTable);
    //      }
}

From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java

License:Open Source License

private static void collapseBorder(PdfPTable pdfTable) {
    for (int r = 0; r < pdfTable.getRows().size(); r++) {
        for (int c = 0; c < pdfTable.getNumberOfColumns(); c++) {
            PdfPCell cell = pdfTable.getRow(r).getCells()[c];
            if (cell.getBorderWidthTop() > 0 && r > 0) {
                PdfPCell cell2 = pdfTable.getRow(r - 1).getCells()[c];
                if (cell2.getBorderWidthBottom() > 0)
                    cell.setBorderWidthTop(0);
            }/* ww w  .j a va 2s. c om*/
            if (cell.getBorderWidthLeft() > 0 && c > 0) {
                PdfPCell cell2 = pdfTable.getRow(r).getCells()[c - 1];
                if (cell2.getBorderWidthRight() > 0)
                    cell.setBorderWidthLeft(0);
            }
        }
    }
}

From source file:com.nokia.s60tools.swmtanalyser.wizards.ReportCreationJob.java

License:Open Source License

/**
 * Returns a table for issues of given priority type from the selected issues.
 * @param allTreeItems tree//w ww . java 2s  . co  m
 * @param p priority
 * @return
 */
private PdfPTable getTableForIssues(Tree allTreeItems, AnalyserConstants.Priority p) {

    float[] relativeWidth = { 60, 25, 15 };//100% total
    PdfPTable table = new PdfPTable(relativeWidth);
    table.setWidthPercentage(100);

    PdfPCell cell = new PdfPCell(new Paragraph("Item name"));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(colorTableHeaderBackGrd);
    cell.setPadding(cellPaddingTableHeader);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Event"));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(colorTableHeaderBackGrd);
    cell.setPadding(cellPaddingTableHeader);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph("Delta"));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(colorTableHeaderBackGrd);
    cell.setPadding(cellPaddingTableHeader);
    table.addCell(cell);

    for (TreeItem parent : allTreeItems.getItems()) {
        for (TreeItem child : parent.getItems()) {
            if (child.getText(4).toLowerCase().equals(p.toString().toLowerCase())) {

                cell = new PdfPCell(new Paragraph(child.getText(1), fontNormalSmallTables));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setPadding(cellPaddingSmall);
                table.addCell(cell);

                cell = new PdfPCell(new Paragraph(child.getText(2), fontNormalSmallTables));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setPadding(cellPaddingSmall);
                table.addCell(cell);

                cell = new PdfPCell(new Paragraph(child.getText(3), fontNormalSmallTables));
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
                cell.setPadding(cellPaddingSmall);
                table.addCell(cell);
            }
        }
    }
    if (table.getRows().size() > 1)
        return table;

    return table;
}

From source file:net.sf.firemox.deckbuilder.BuildBook.java

License:Open Source License

/**
 * //from   w  w  w  .ja  v  a  2s.c o  m
 */
@SuppressWarnings("unchecked")
public void build() {
    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(new FileInputStream(MToolKit.getFile(checklist)),
                Charset.forName("ISO-8859-1")));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return;
    }
    // String charset = Charset.forName("ISO-8859-1").name();
    String line = null;
    int cur = 0;
    int row = 0;
    PdfPCell[] cells = new PdfPCell[3];
    PdfPTable table = new PdfPTable(3);
    Document document = new Document(PageSize.A4);
    try {
        PdfWriter.getInstance(document, new FileOutputStream(this.pdfBook));
        document.open();
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    try {
        in.readLine(); // Removing header line
        String[] tokens = new String[] { "\t", "\\s{2,}" };
        while ((line = in.readLine()) != null) {
            // line = new String(line.getBytes(),charset);
            // Card# Card Name Artist Color Rarity
            String[] fields = null;
            for (String token : tokens) {
                fields = line.split(token);
                if (fields.length == 5) {
                    break;
                }
            }

            if (fields == null || fields.length < 5) {
                System.err.println("Unable to parse " + line);
                continue;
            } else if (fields.length > 5) {
                System.out.println("Too many value found on " + line);
            }
            fields[1] = fields[1].trim();
            fields[1] = fields[1].replaceAll("[ -]", "_");
            fields[1] = fields[1].replaceAll("[/',\\u0092]", "");
            fields[1] = fields[1].replaceAll("", "AE");
            System.out.println("Inserting " + fields[1]);
            if (basicLands.containsKey(fields[1])) {
                int x = basicLands.get(fields[1]);
                cells[cur] = new PdfPCell(getImage(fields[1] + x), true);
                x++;
                basicLands.put(fields[1], x);
            } else {
                cells[cur] = new PdfPCell(getImage(fields[1]), true);
            }
            cur++;
            if (cur == 3) {
                for (int j = 0; j < cells.length; j++) {
                    cells[j].setPadding(2.0f);
                }
                table.getRows().add(new PdfPRow(cells));
                row++;
                cur = 0;
                cells = new PdfPCell[3];
            }
            if (row == 3) {
                table.setWidthPercentage(100);
                document.add(table);
                table = new PdfPTable(3);
                row = 0;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:open.dolphin.hiro.PrescriptionPDFMaker.java

private List<PdfPTable> createPrescriptionTbl2() {
    ClaimItem[] items;/*from  w  ww .  j  a v a 2 s.  c  o  m*/
    PdfPCell pcell, blank, numCell, amountCell;
    int num, cnt;
    double sum; // @009 ?????(?*)
    List<PdfPTable> preTblList = null;
    String admin, number; // @009
    String classCode, amount, medicine; // @009

    try {
        StringBuilder sb = new StringBuilder();
        sb.append(
                "???????(??)??????????????\n");
        sb.append(
                "?????????????????????????");
        PdfPTable ptbl = new PdfPTable(9); // @009
        ptbl.setWidthPercentage(100f);
        // @009 ???, ?, ??, ?, ??, , "(", , ")"
        float[] widthsP = { 14, 7, 52, 8, 15, 32, 2, 5, 9 };
        ptbl.setWidths(widthsP);
        ptbl.getDefaultCell().setPadding(0f);
        preTblList = new ArrayList<PdfPTable>();

        num = 1;
        //admin = "";  // @009 
        //number = ""; // @009 
        //amount = ""; // @009 ?
        numCell = new PdfPCell(new Paragraph("", min_8)); // @009
        numCell.setBorderWidth(LINE_WIDTH_0); // @009

        PdfPCell notes = new PdfPCell(new Paragraph("??", min_8));
        notes.setBorderWidth(LINE_WIDTH_1);
        notes.setBorderWidthBottom(LINE_WIDTH_0);
        PdfPCell bracket = new PdfPCell(new Paragraph("", min_15));
        bracket.setBorderWidth(LINE_WIDTH_0);
        bracket.setHorizontalAlignment(Element.ALIGN_RIGHT);
        bracket.setPadding(0f);
        PdfPCell notesDetail = new PdfPCell(new Paragraph(sb.toString(), min_6));
        notesDetail.setBorderWidth(LINE_WIDTH_0);
        notesDetail.setColspan(5);
        PdfPCell bracketC = new PdfPCell(new Paragraph("", min_15));
        bracketC.setBorderWidth(LINE_WIDTH_0);
        bracketC.setHorizontalAlignment(Element.ALIGN_LEFT);
        bracketC.setPadding(0f);
        bracketC.setColspan(2);

        for (Iterator<BundleMed> ite = pkg.getPriscriptionList().iterator(); ite.hasNext();) {
            BundleMed prescription = ite.next();
            admin = prescription.getAdmin(); // @009  
            number = prescription.getBundleNumber(); // @009  ????=1 bundeNumber
            classCode = prescription.getClassCode(); // @009   221 etc 

            items = prescription.getClaimItem();
            //minagawa^                
            boolean genericIsOk = true;

            if (items != null) {
                for (ClaimItem i : items) {
                    if (i.getCode().equals("099209903")) {
                        genericIsOk = false;
                        break;
                    }
                }
            }
            genericIsOk = true;
            //minagawa4                

            if (ptbl.getRows().isEmpty()) {
                ptbl.addCell(notes);
                ptbl.addCell(bracket);
                ptbl.addCell(notesDetail);
                ptbl.addCell(bracketC);
            }

            // @001 2009/11/17 ?
            // items?null???????????????
            // ???????????items ? null ??????
            // if???????????(??????????)
            if (items != null) {
                boolean clearFlg = true; // @004 2010/02/26  ?
                // ********** @009  **********
                //sum = 0; // ?????
                Font adminF = min_8; // 
                boolean wrap = true;
                if (admin != null) {
                    if (admin.length() > 17) {
                        // ??17???4??
                        adminF = min_4;
                        wrap = false;
                    } else if (admin.length() > 11) {
                        // ??11???6??
                        adminF = min_6;
                    }
                }
                Font medicineF; // ??
                // ********** @009  **********

                // ??? ClaimItem iterate
                for (cnt = 0; cnt < items.length; cnt++) {
                    //System.out.println("row size:" + ptbl.getRows().size());

                    // ??
                    if (!genericIsOk) {
                        blank = new PdfPCell(new Paragraph("", min_8));
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setBorderWidthRight(LINE_WIDTH_1);
                        ptbl.addCell(blank);
                        genericIsOk = true;

                    } else {
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setBorderWidthRight(LINE_WIDTH_1);
                        ptbl.addCell(blank);
                    }

                    if (ptbl.getRows().size() > 13) {
                        // ?13???????????
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setColspan(4);
                        ptbl.addCell(blank);
                        pcell = new PdfPCell(new Paragraph("???", min_8));
                        pcell.setBorderWidth(LINE_WIDTH_0);
                        pcell.setColspan(5);
                        ptbl.addCell(pcell);
                        preTblList.add(ptbl);
                        ptbl = new PdfPTable(9);
                        ptbl.setWidthPercentage(100f);
                        ptbl.setWidths(widthsP);
                        ptbl.getDefaultCell().setPadding(0f);
                        // ??
                        ptbl.addCell(notes);
                        ptbl.addCell(bracket);
                        ptbl.addCell(notesDetail);
                        ptbl.addCell(bracketC);
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        blank.setBorderWidthRight(LINE_WIDTH_1);
                        ptbl.addCell(blank);
                    }

                    if (cnt > 0) {
                        // ?1?????????
                        blank = new PdfPCell();
                        blank.setBorderWidth(LINE_WIDTH_0);
                        ptbl.addCell(blank);
                    } else {
                        // ?1??????
                        numCell = new PdfPCell(new Paragraph(num++ + ")", min_8));
                        numCell.setBorderWidth(LINE_WIDTH_0);
                        setAlignRight(numCell);
                        ptbl.addCell(numCell);
                        // @004 2010/02/26  
                        // ?1?????? false ??
                        if (!ClaimConst.COMMENT_CODE_0.equals(items[cnt].getCode())) {
                            clearFlg = false;
                        }
                        // @004 2010/02/26  
                    }

                    // ********** @009  **********
                    amount = items[cnt].getNumber();
                    //                        System.out.println("??" + items[cnt].getName());
                    //                        System.out.println("?" + amount);
                    //medicine = "";
                    medicine = items[cnt].getName();
                    //                        System.out.println("????" + medicine.length());
                    if (medicine.length() > 19) {
                        // ????19???7??
                        medicineF = min_7;
                    } else {
                        // ????19???8???
                        medicineF = min_8;
                    }
                    // ********** @009  **********

                    if ((ClaimConst.SUBCLASS_CODE_ID.equals(items[cnt].getClassCodeSystem()))
                            && ((String.valueOf(ClaimConst.YAKUZAI).equals(items[cnt].getClassCode()))
                                    || (String.valueOf(ClaimConst.ZAIRYO).equals(items[cnt].getClassCode())))) {

                        pcell = new PdfPCell(new Paragraph(convertNVL(items[cnt].getName()), medicineF)); // ?? ??? ????
                        pcell.setBorderWidth(LINE_WIDTH_0);
                        ptbl.addCell(pcell);
                        amountCell = new PdfPCell(new Paragraph(convertNVL(amount), min_8)); // ?
                        setAlignRight(amountCell);
                        amountCell.setBorderWidth(LINE_WIDTH_0);
                        ptbl.addCell(amountCell);

                        if (!(String.valueOf(ClaimConst.ZAIRYO).equals(items[cnt].getClassCode()))) {
                            // ?????
                            pcell = new PdfPCell(new Paragraph(convertNVL(items[cnt].getUnit()), min_8)); // ??
                            pcell.setBorderWidth(LINE_WIDTH_0);
                            ptbl.addCell(pcell);
                            // ********** @009  **********
                            pcell = new PdfPCell(new Paragraph(admin, adminF)); // 
                            pcell.setBorderWidth(LINE_WIDTH_0);
                            pcell.setNoWrap(wrap);
                            ptbl.addCell(pcell);
                        } else {
                            blank = new PdfPCell();
                            blank.setColspan(2);
                            blank.setBorderWidth(LINE_WIDTH_0);
                            ptbl.addCell(blank);
                        }

                        if (ClaimConst.RECEIPT_CODE_GAIYO.equals(classCode)) {
                            pcell = new PdfPCell(new Paragraph("", min_8));
                            pcell.setBorderWidth(LINE_WIDTH_0);
                            pcell.setColspan(3);
                            ptbl.addCell(pcell);
                            sum = Double.parseDouble(amount) * Double.parseDouble(number);
                            DecimalFormat f = new DecimalFormat("####0.###");
                            //                                System.out.println("??" + sum);
                            amountCell.getPhrase().clear();
                            amountCell.getPhrase().add(new Paragraph(String.valueOf(f.format(sum)), min_8)); // ?
                        } else {
                            // 
                            if ((number != null) && !("".equals(number))) {
                                pcell = new PdfPCell(new Paragraph("(", min_8));
                                pcell.setBorderWidth(LINE_WIDTH_0);
                                ptbl.addCell(pcell);
                                pcell = new PdfPCell(new Paragraph(number, min_8));
                                pcell.setBorderWidth(LINE_WIDTH_0);
                                setAlignRight(pcell);
                                ptbl.addCell(pcell);

                                //minagawa^          
                                if (classCode.startsWith("22")) {
                                    // 
                                    pcell = new PdfPCell(new Paragraph(")", min_8));
                                } else if (classCode.startsWith("21")) {
                                    // 
                                    pcell = new PdfPCell(new Paragraph(")", min_8));
                                    // 
                                } else if (classCode.startsWith("23")) {
                                    pcell = new PdfPCell(new Paragraph("", min_8));
                                }
                                //minagawa$     
                                pcell.setBorderWidth(LINE_WIDTH_0);
                                setAlignRight(pcell);
                                ptbl.addCell(pcell);
                            } else {
                                blank = new PdfPCell();
                                blank.setBorderWidth(LINE_WIDTH_0);
                                blank.setColspan(3);
                                ptbl.addCell(blank);
                            }
                        }
                        // ********** @009  **********
                    } else {
                        pcell = new PdfPCell(new Paragraph(convertNVL(items[cnt].getName()), min_8));
                        pcell.setBorderWidth(LINE_WIDTH_0);
                        pcell.setColspan(7);
                        ptbl.addCell(pcell);
                    }
                }
                // @004 2010/02/26  
                // ?? true ????
                if (clearFlg && (admin == null)) {
                    numCell.getPhrase().clear();
                    num--;
                }
                // @004 2010/02/26  

            } else {
                String stampName = prescription.getOrderName();
                System.err.println("??" + stampName
                        + "????????????");
                StringBuilder b = new StringBuilder();
                b.append("??").append(stampName)
                        .append("?????????").append(System.getProperty(STR_LF));
                System.err.println(b.toString());
            }

            if (!ite.hasNext()) {
                blank = new PdfPCell();
                blank.setBorderWidth(LINE_WIDTH_0);
                ptbl.addCell(blank);
                pcell = new PdfPCell(new Paragraph("", min_8));
                pcell.setBorderWidth(LINE_WIDTH_0);
                pcell.setBorderWidthLeft(LINE_WIDTH_1);
                pcell.setPaddingLeft(30f);
                pcell.setColspan(8);
                ptbl.addCell(pcell);
                preTblList.add(ptbl);
            }
        }
    } catch (Exception e) {
        e.printStackTrace(System.err);
    }
    return preTblList;
}

From source file:org.egov.works.web.actions.contractorBill.ContractorBillPDFGenerator.java

License:Open Source License

public void generatePDF() throws ApplicationException {
    logger.debug("FA1---inside generate pdf ");
    generateDisplayData(mbHeader, egBillRegister);
    try {//  w  w w .j  a  va  2 s .  c  o  m
        // start header Part
        final PdfPTable contractorBillMainTable = new PdfPTable(11);
        contractorBillMainTable.setWidthPercentage(100);
        contractorBillMainTable
                .setWidths(new float[] { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f });
        contractorBillMainTable.getDefaultCell().setPadding(4);
        contractorBillMainTable.getDefaultCell().setBorderWidth(1);
        createHeaderRow(contractorBillMainTable);
        createDetailsRows(contractorBillMainTable);
        document.add(contractorBillMainTable);
        document.add(spacer());

        // ---approval details for workflow
        final PdfPTable approvaldetailsTable = createApprovalDetailsTable(egBillRegister);

        if (approvaldetailsTable.getRows().size() != 1) {
            document.add(makePara("Approval Details"));
            document.add(spacer());
            document.add(approvaldetailsTable);
            document.add(spacer());
        }
        if (contractorBillMainTable.getRows().size() > 11)
            document.newPage();
        createFooter();
        // create certificate page
        document.newPage();
        createCertificate();
        document.close();
    } catch (final DocumentException e) {
        throw new ApplicationRuntimeException(CONTRACTOR_PDF_ERROR, e);
    }
}

From source file:org.egov.works.web.actions.estimate.EstimatePDFGenerator.java

License:Open Source License

public void generatePDF() {
    try {//from  w  w w  . j a  v  a 2s.co m
        final Paragraph headerTextPara = new Paragraph(
                new Chunk(headerText, new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD)));
        String projectCode;
        final String oldEstNo = "";
        HeaderFooter hf;
        headerTextPara.setAlignment(Element.ALIGN_CENTER);
        document.add(headerTextPara);
        document.add(makePara("Executing Department:" + estimate.getExecutingDepartment().getName(),
                Element.ALIGN_LEFT));
        if (estimate.getUserDepartment() != null)
            document.add(
                    makePara("User Department:" + estimate.getUserDepartment().getName(), Element.ALIGN_LEFT));

        final CFinancialYear estimateFinancialYear = estimate.getMultiYearEstimates().get(0).getFinancialYear();
        addZoneYearHeader(estimate, estimateFinancialYear);

        document.add(makePara("Name of Work: " + estimate.getName(), Element.ALIGN_LEFT));
        document.add(makePara("Description: " + estimate.getDescription(), Element.ALIGN_LEFT));

        if (estimate.getProjectCode() != null) {
            projectCode = "Project Code : " + estimate.getProjectCode().getCode();
            document.add(makePara(projectCode, Element.ALIGN_LEFT));
            hf = new HeaderFooter(new Phrase("\t  \t  \t  \t \t \t  \t  \t  \t \t \t  \t  \t  \t \t"
                    + "\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  "
                    + "\t  \t  \t  \t \t\t  \t  \t  \t \t"
                    + headerText.concat("\n")
                            .concat("\t  \t  \t  \t \t \t  \t  \t  \t \t"
                                    + "\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  "
                                    + "\t  \t  \t  \t \t\t  \t  \t  \t \t ABSTRACT ESTIMATE")
                            .concat("\n\n").concat("Name of Work: " + estimate.getName()).concat("\n")
                            .concat("Description: " + estimate.getDescription()).concat("\n")
                            .concat("Estimate Number: " + estimate.getEstimateNumber()).concat(oldEstNo)
                            .concat("\n").concat(projectCode)),
                    false);
        } else
            hf = new HeaderFooter(new Phrase("\t  \t  \t  \t \t \t  \t  \t  \t \t \t  \t  \t  \t \t"
                    + "\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  "
                    + "\t  \t  \t  \t \t\t  \t  \t  \t \t"
                    + headerText.concat("\n")
                            .concat("\t  \t  \t  \t \t \t  \t  \t  \t \t"
                                    + "\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  "
                                    + "\t  \t  \t  \t \t\t  \t  \t  \t \t ABSTRACT ESTIMATE")
                            .concat("\n\n").concat("Name of Work: " + estimate.getName()).concat("\n")
                            .concat("Description: " + estimate.getDescription()).concat("\n")
                            .concat("Estimate Number: " + estimate.getEstimateNumber()).concat(oldEstNo)),
                    false);

        hf.disableBorderSide(Rectangle.TOP);
        hf.disableBorderSide(Rectangle.BOTTOM);
        hf.setLeft(Element.ALIGN_LEFT);
        document.setHeader(hf);
        final PdfPTable overheadsTable = createOverheadsTable(estimate);
        document.add(spacer());
        document.add(overheadsTable);
        document.add(spacer());
        final PdfPTable multiyearTable = createMultiYearTable(estimate);
        document.add(makePara("Year-wise Estimate"));
        document.add(spacer());
        document.add(multiyearTable);
        document.add(spacer());
        document.add(makePara("Estimate Created By: " + estimate.getCreatedBy().getName()));
        document.add(spacer());
        document.add(spacer());
        document.add(makePara("Checked By: "));
        document.newPage();
        addZoneYearHeaderWithOutEstimateNo(estimate, estimateFinancialYear);
        document.add(createActivitiesTable(estimate));
        document.add(spacer());

        final PdfPTable approvaldetailsTable = createApprovalDetailsTable(estimate);
        // TODO:Fixme - commented final out workflow history final details since ordering final of approval is final not
        // getting final listed properly
        /*
         * if (approvaldetailsTable.getRows().size() != 1) { document.add(makePara("Approval Details"));
         * document.add(spacer()); document.add(approvaldetailsTable); }
         */

        final String appropriationNumber = abstractEstimateService
                .getLatestEstimateAppropriationNumber(estimate);

        if (isSkipBudgetCheck()) {
            final PdfPTable depositWorksAppropriationTable = createDepositAppropriationTable(estimate,
                    appropriationNumber);
            if (depositWorksAppropriationTable.getRows().size() != 1)
                if (appropriationNumber != null) {
                    document.newPage();
                    document.add(spacer());
                    document.add(makePara("Deposit Code Appropriation Details"));
                    document.add(spacer());
                    document.add(depositWorksAppropriationTable);
                }
        } else {
            final PdfPTable BudgetaryAppropriationTable = createBudgetaryAppropriationTable(estimate,
                    appropriationNumber);
            final String estimateNumber = estimate.getEstimateNumber();
            if (BudgetaryAppropriationTable.getRows().size() != 1)
                if (!getBudgetDetailUsage(estimateNumber).isEmpty() && appropriationNumber != null) {
                    document.newPage();
                    document.add(spacer());
                    document.add(makePara("Budgetary Appropriation"));
                    document.add(spacer());
                    document.add(BudgetaryAppropriationTable);
                }
        }

        document.newPage();
        document.add(spacer());
        document.add(makePara(
                "EXECUTIVE ENGINEER'S OFFICE,  ZONE.......................................................................",
                Element.ALIGN_LEFT));
        document.add(spacer());
        document.add(makePara(
                "Est No.                                                Unit:                                                 Dept.",
                Element.ALIGN_LEFT));
        document.add(spacer());
        final Paragraph budgetheadTextPara = new Paragraph(
                new Chunk("BUDGET HEAD", new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD)));
        budgetheadTextPara.setAlignment(Element.ALIGN_CENTER);
        document.add(budgetheadTextPara);
        document.add(spacer());
        document.add(makePara("____________________________________________________________________________",
                Element.ALIGN_LEFT));
        document.add(makePara("Rs.                                            ", Element.ALIGN_LEFT));
        document.add(makePara("____________________________________________________________________________",
                Element.ALIGN_LEFT));
        document.add(makePara("Works:                                          ", Element.ALIGN_LEFT));
        document.add(spacer());
        document.add(spacer());
        final Paragraph memoTextPara = new Paragraph(
                new Chunk("MEMO", new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD)));
        memoTextPara.setAlignment(Element.ALIGN_CENTER);
        document.add(memoTextPara);
        document.add(makePara("Budget Grant                               ", Element.ALIGN_LEFT));
        document.add(makePara("Amount Appropriated:__________________________________________________________",
                Element.ALIGN_LEFT));
        document.add(makePara("Balance on Hand:                                ", Element.ALIGN_LEFT));
        document.add(
                makePara("Amount of this estimate_________________________________________________________",
                        Element.ALIGN_LEFT));
        document.add(makePara("Balance forward_______________________________________________________________",
                Element.ALIGN_LEFT));
        document.add(
                makePara("Submitted for favour of sanction                           ", Element.ALIGN_LEFT));
        document.add(spacer());
        document.add(spacer());
        document.add(
                makePara("A.E.E.Unit " + space1 + "\t  \t  \t  \t \t \t  \t  \t  \t \t \t \t \t \t \t \t \t \t"
                        + "Exe.Eng.Zone.....................", Element.ALIGN_LEFT));
        document.add(spacer());
        document.add(makePara("Sanctioned", Element.ALIGN_CENTER));
        document.add(spacer());
        document.add(spacer());
        document.add(makePara("DATE:" + space1
                + "\t  \t  \t  \t \t \t  \t  \t  \t \t \t \t\t  \t  \t  \t \t \t  \t  \t  \t \t \t \t"
                + "Asst.Commissioner Zone...............", Element.ALIGN_LEFT));
        document.add(spacer());
        document.add(makePara(
                space1 + "\t  \t  \t  \t \t \t  \t  \t  \t \t \t \t\t  \t  \t  \t \t \t  \t  \t  \t \t \t \t"
                        + "APPROPRIATION No.",
                Element.ALIGN_LEFT));
        document.add(makePara(space1 + "\t  \t  \t  \t \t \t  \t  \t  \t \t \t \t"
                + "\t  \t  \t  \t \t \t  \t  \t  \t \t \t \t \t \t \t" + "Date:", Element.ALIGN_LEFT));

        // WF for signature -----
        if (approvaldetailsTable.getRows().size() != 1)
            if (shouldShowApprovalNumber) {
                document.resetHeader();
                document.newPage();
                document.add(
                        makePara("\t  \t  \t  \t \t \t  \t  \t  \t \t \t  \t  \t  \t \t"
                                + "\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  "
                                + "\t  \t  \t  \t \t\t  \t  \t  \t \t"
                                + headerText.concat("\n").concat("\t  \t  \t  \t \t \t  \t  \t  \t \t"
                                        + "\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  \t \t\t  \t  \t  "
                                        + "\t  \t  \t  \t \t\t  \t  \t  \t \t ABSTRACT ESTIMATE")
                                        .concat("\n\n")));
                document.add(
                        makePara(
                                "File Current Number :" + space1
                                        + "\t  \t  \t  \t \t \t  \t  \t  \t \t \t \t \t   " + "Date: \t \t",
                                Element.ALIGN_LEFT));
                document.add(makePara(space1
                        + "\t  \t  \t  \t \t \t  \t  \t  \t \t \t \t\t  \t  \t  \t \t \t \t \t  \t  \t  \t "
                        + "Department : ", Element.ALIGN_LEFT));
                document.add(spacer());
                final Paragraph headingPara1 = new Paragraph(
                        new Chunk("NOTE FOR ADMINISTRATIVE SANCTION AS PER RULE 78 OF ",
                                new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD)));
                headingPara1.setAlignment(Element.ALIGN_CENTER);
                document.add(headingPara1);
                final Paragraph headingPara2 = new Paragraph(
                        new Chunk("MCMC ACT 1919 ", new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD)));
                headingPara2.setAlignment(Element.ALIGN_CENTER);
                document.add(headingPara2);

                document.add(spacer());
                final PdfPTable estimateDetailsTable1 = createEstimateDetailsTable1(estimate);
                document.add(estimateDetailsTable1);
                final PdfPTable budgetDetailsTableFourCols = createBudgetDetailsForEstimateTable(estimate);
                document.add(budgetDetailsTableFourCols);
                final PdfPTable estimateDetailsTable2 = createBalanceAmtCalculationTable(estimate);
                document.add(estimateDetailsTable2);
                document.add(spacer());
                final Paragraph endTextPara = new Paragraph(
                        new Chunk("** END **", new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD)));
                endTextPara.setAlignment(Element.ALIGN_CENTER);
                document.add(endTextPara);
            }

        document.close();
    } catch (final DocumentException e) {
        throw new ApplicationRuntimeException("estimate.pdf.error", e);
    }
}

From source file:org.egov.works.web.actions.tender.TenderNegotiationPDFGenerator.java

License:Open Source License

public void generatePDF() {
    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(10);//  w  w w  . j a  va  2 s.c  o  m
    final List<String> tenderTypeList = worksService.getTendertypeList();
    if (tenderTypeList != null && !tenderTypeList.isEmpty())
        percTenderType = tenderTypeList.get(0);
    final String headerText = pdfLabel.get("tenderNegotiationpdf.header");
    try {
        final Paragraph headerTextPara = new Paragraph(
                new Chunk(headerText, new Font(Font.UNDEFINED, LARGE_FONT, Font.BOLD)));
        headerTextPara.setAlignment(Element.ALIGN_CENTER);
        document.add(headerTextPara);
        document.add(makePara(cityName, Element.ALIGN_RIGHT));
        if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                && tenderResponse.getTenderEstimate().getWorksPackage() != null) {
            worksPackgeReq = YES;
            worksPackage = tenderResponse.getTenderEstimate().getWorksPackage();
        }
        String deptName = "";
        if (YES.equalsIgnoreCase(worksPackgeReq)) {
            deptName = tenderResponse.getTenderEstimate().getWorksPackage().getDepartment().getName();
            document.add(makePara(deptName, Element.ALIGN_RIGHT));
            if (getWardList(worksPackage) != null)
                document.add(makePara(
                        pdfLabel.get("tenderNegotiationpdf.ward") + "/"
                                + pdfLabel.get("tenderNegotiationpdf.zone") + getWardList(worksPackage),
                        Element.ALIGN_LEFT));
        } else {
            if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                    && tenderResponse.getTenderEstimate().getAbstractEstimate().getExecutingDepartment() != null
                    && tenderResponse.getTenderEstimate().getAbstractEstimate().getExecutingDepartment()
                            .getName() != null)
                deptName = tenderResponse.getTenderEstimate().getAbstractEstimate().getExecutingDepartment()
                        .getName();
            document.add(makePara(deptName, Element.ALIGN_RIGHT));
            if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                    && tenderResponse.getTenderEstimate().getAbstractEstimate().getWard().getParent() != null
                    && tenderResponse.getTenderEstimate().getAbstractEstimate().getWard() != null)
                document.add(makePara(pdfLabel.get("tenderNegotiationpdf.ward") + "/"
                        + pdfLabel.get("tenderNegotiationpdf.zone")
                        + tenderResponse.getTenderEstimate().getAbstractEstimate().getWard().getName() + "/"
                        + tenderResponse.getTenderEstimate().getAbstractEstimate().getWard().getParent()
                                .getName(),
                        Element.ALIGN_LEFT));
        }
        if (YES.equalsIgnoreCase(worksPackgeReq))
            document.add(makePara(
                    pdfLabel.get("tenderNegotiationpdf.nameofwork")
                            + tenderResponse.getTenderEstimate().getWorksPackage().getName(),
                    Element.ALIGN_LEFT));
        else if (tenderResponse != null && tenderResponse.getTenderEstimate() != null)
            document.add(makePara(
                    pdfLabel.get("tenderNegotiationpdf.nameofwork")
                            + tenderResponse.getTenderEstimate().getAbstractEstimate().getName(),
                    Element.ALIGN_LEFT));
        if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                && tenderResponse.getTenderEstimate().getTenderHeader() != null
                && tenderResponse.getTenderEstimate().getTenderHeader().getTenderNo() != null)
            document.add(makePara(
                    pdfLabel.get("tenderNumber")
                            + tenderResponse.getTenderEstimate().getTenderHeader().getTenderNo(),
                    Element.ALIGN_LEFT));
        if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                && tenderResponse.getTenderEstimate().getWorksPackage() != null)
            document.add(makePara(
                    pdfLabel.get("tenderFileNo")
                            + tenderResponse.getTenderEstimate().getWorksPackage().getTenderFileNumber(),
                    Element.ALIGN_LEFT));
        document.add(spacer());
        String tenderDate = "";
        if (tenderResponse != null && tenderResponse.getTenderEstimate() != null
                && tenderResponse.getTenderEstimate().getTenderHeader() != null
                && tenderResponse.getTenderEstimate().getTenderHeader().getTenderDate() != null)
            tenderDate = sdf.format(tenderResponse.getTenderEstimate().getTenderHeader().getTenderDate());
        document.add(
                makePara(pdfLabel.get("tenderNegotiationpdf.tenderdate") + tenderDate, Element.ALIGN_RIGHT));
        document.add(spacer());
        PdfPTable contractorTable = null;
        if (tenderResponse != null) {
            contractorTable = createContractorTable(tenderResponse);
            document.add(contractorTable);
        }
        document.add(spacer());

        if (tenderResponse != null
                && tenderResponse.getTenderEstimate().getTenderType().equalsIgnoreCase(percTenderType)) {
            PdfPTable negotiationTable = null;
            negotiationTable = createNegotiationTable(tenderResponse,
                    tenderResponse.getTenderResponseContractors().get(0).getContractor());
            document.add(negotiationTable);
            document.add(spacer());
            if (negotiationTable != null && negotiationTable.getRows().size() > 8)
                document.newPage();

        } else if (tenderResponse != null
                && !tenderResponse.getTenderEstimate().getTenderType().equalsIgnoreCase(percTenderType))
            createNegotiationTableForContractors(tenderResponse);

        if (tenderResponse != null && tenderResponse.getNegotiationPreparedBy() != null
                && tenderResponse.getNegotiationPreparedBy().getEmployeeName() != null)
            document.add(makePara(pdfLabel.get("tenderNegotiationpdf.preparedby") + " "
                    + tenderResponse.getNegotiationPreparedBy().getEmployeeName()));
        document.add(spacer());
        document.add(spacer());
        document.add(makePara(pdfLabel.get("tenderNegotiationpdf.checkedby")));
        document.newPage();

        PdfPTable approvaldetailsTable = null;
        if (tenderResponse != null)
            approvaldetailsTable = createApprovalDetailsTable(tenderResponse);

        if (approvaldetailsTable != null && approvaldetailsTable.getRows().size() != 1) {
            document.add(makePara(pdfLabel.get("tenderNegotiationpdf.approvaldetails")));
            document.add(spacer());
            document.add(approvaldetailsTable);
        }
        document.close();
    } catch (final DocumentException e) {
        throw new ApplicationRuntimeException(TENDER_PDF_ERROR, e);
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfTable.java

License:Open Source License

/**
 * Imports the rows and settings from the Table into this PatchRtfTable.
 *
 * @param table//  w  w w .  jav  a  2  s .c  o  m
 *          The source PdfPTable
 * @since 2.1.3
 */
private void importTable(PdfPTable table) {
    this.rows = new ArrayList<PatchRtfRow>();
    this.tableWidthPercent = table.getWidthPercentage();
    // this.tableWidthPercent = table.getWidth();
    this.proportionalWidths = table.getAbsoluteWidths();
    // this.proportionalWidths = table.getProportionalWidths();
    this.cellPadding = (float) (table.spacingAfter() * TWIPS_FACTOR);
    // this.cellPadding = (float) (table.getPadding() * TWIPS_FACTOR);
    this.cellSpacing = (float) (table.spacingAfter() * TWIPS_FACTOR);
    // this.cellSpacing = (float) (table.getSpacing() * TWIPS_FACTOR);
    // this.borders = new PatchRtfBorderGroup(this.document, PatchRtfBorder.ROW_BORDER, table.getBorder(),
    // table.getBorderWidth(), table.getBorderColor());
    // this.borders = new PatchRtfBorderGroup(this.document, PatchRtfBorder.ROW_BORDER, table.getBorder(),
    // table.getBorderWidth(), table.getBorderColor());
    this.alignment = table.getHorizontalAlignment();
    // this.alignment = table.getAlignment();

    int i = 0;
    Iterator rowIterator = table.getRows().iterator();
    // Iterator rowIterator = table.iterator();
    while (rowIterator.hasNext()) {
        this.rows.add(new PatchRtfRow(this.document, this, (PdfPRow) rowIterator.next(), i));
        i++;
    }
    for (i = 0; i < this.rows.size(); i++) {
        this.rows.get(i).handleCellSpanning();
        this.rows.get(i).cleanRow();
    }

    this.headerRows = table.getHeaderRows();
    // this.headerRows = table.getLastHeaderRow();
    this.cellsFitToPage = table.getKeepTogether();
    // this.cellsFitToPage = table.isCellsFitPage();
    this.tableFitToPage = table.getKeepTogether();
    // this.tableFitToPage = table.isTableFitsPage();
    // if(!Float.isNaN(table.getOffset())) {
    // this.offset = (int) (table.getOffset() * 2);
    // }
    // if(!Float.isNaN(table.getOffset())) {
    // this.offset = (int) (table.getOffset() * 2);
    // }
}