Example usage for com.lowagie.text Document add

List of usage examples for com.lowagie.text Document add

Introduction

In this page you can find the example usage for com.lowagie.text Document add.

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeEntry(Document document, String label, double value) throws Exception {
    Paragraph questionParagraph = new Paragraph();
    questionParagraph.setLeading(14, 0);
    questionParagraph.setIndentationLeft(18);
    questionParagraph.add(new Chunk(label.trim() + ": ", boldedFont));
    questionParagraph.add(new Chunk(
            BigDecimalValidator.getInstance().format(value, LocaleContextHolder.getLocale()), normalFont));
    document.add(questionParagraph);
}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeEntry(Document document, String label, Date value, String dateFormat) throws Exception {
    Paragraph questionParagraph = new Paragraph();
    questionParagraph.setLeading(14, 0);
    questionParagraph.setIndentationLeft(18);
    questionParagraph.add(new Chunk(label.trim() + ": ", boldedFont));
    questionParagraph.add(new Chunk(DateValidator.getInstance().format(value, dateFormat), normalFont));
    document.add(questionParagraph);
}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeCurrencyEntry(Document document, String label, double value) throws Exception {
    Paragraph questionParagraph = new Paragraph();
    questionParagraph.setLeading(14, 0);
    questionParagraph.setIndentationLeft(18);
    questionParagraph.add(new Chunk(label.trim() + ": ", boldedFont));
    questionParagraph.add(new Chunk(
            CurrencyValidator.getInstance().format(value, LocaleContextHolder.getLocale()), normalFont));
    document.add(questionParagraph);
}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeBooleanQuestionStatistics(Document document, Question question,
        List<QuestionStatistic> questionStatistics, String optionLabel, String optionFrequencyLabel,
        String trueLabel, String falseLabel) throws Exception {

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(1);

    Table statsTable = createOptionsQuestionStatisticsTableHeader(optionLabel, optionFrequencyLabel);
    Cell cell;//from   ww  w.  j  a v  a2s.  co m
    Boolean foundOption = false;

    cell = new Cell(new Paragraph(trueLabel, normalFont));
    statsTable.addCell(cell);
    if (questionStatistics != null && questionStatistics.size() > 0) {
        for (QuestionStatistic questionStatistic : questionStatistics) {
            if (questionStatistic.getEntry().equals("1")) {
                foundOption = true;
                cell = new Cell(
                        new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont));
                statsTable.addCell(cell);

                cell = new Cell();
                Image img = Image.getInstance(this.getClass().getResource("/chartbar.png"));
                cell.setColspan(5);
                img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f);
                cell.addElement(img);
                cell.setVerticalAlignment(Cell.ALIGN_BOTTOM);
                statsTable.addCell(cell);
                break;
            }
        }
    }
    if (!foundOption) {
        cell = new Cell(new Paragraph(percentFormat.format(0), normalFont));
        statsTable.addCell(cell);

        cell = new Cell();
        cell.setColspan(5);
        statsTable.addCell(cell);
    }

    foundOption = false;
    cell = new Cell(new Paragraph(falseLabel, normalFont));
    statsTable.addCell(cell);
    if (questionStatistics != null && questionStatistics.size() > 0) {
        for (QuestionStatistic questionStatistic : questionStatistics) {
            if (questionStatistic.getEntry().equals("0")) {
                foundOption = true;
                cell = new Cell(
                        new Paragraph(percentFormat.format(questionStatistic.getFrequency()), normalFont));
                statsTable.addCell(cell);

                cell = new Cell();
                Image img = Image.getInstance(this.getClass().getResource("/chartbar.png"));
                cell.setColspan(5);
                img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f);
                cell.addElement(img);
                cell.setVerticalAlignment(Cell.ALIGN_BOTTOM);
                statsTable.addCell(cell);
                break;
            }
        }
    }
    if (!foundOption) {
        cell = new Cell(new Paragraph(percentFormat.format(0), normalFont));
        statsTable.addCell(cell);

        cell = new Cell();
        cell.setColspan(5);
        statsTable.addCell(cell);
    }
    document.add(statsTable);

}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeOptionsQuestionStatistics(Document document, Question question,
        List<QuestionStatistic> questionStatistics, String optionLabel, String optionFrequencyLabel)
        throws Exception {

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(1);

    Table statsTable = createOptionsQuestionStatisticsTableHeader(optionLabel, optionFrequencyLabel);
    Cell cell;//  w w  w.  j  a  v  a 2 s.c om

    int rowIndex = 0;
    for (QuestionOption option : question.getOptions()) {
        Boolean foundOption = false;
        cell = new Cell(new Paragraph(option.getText(), normalFont));
        //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));}
        statsTable.addCell(cell);

        if (questionStatistics != null && questionStatistics.size() > 0) {
            for (QuestionStatistic questionStatistic : questionStatistics) {
                if (question.getType().getIsMultipleValue()) {
                    //multiple value question (checkboxes) match on order
                    if (questionStatistic.getOptionOrder().equals(option.getOrder())) {
                        foundOption = true;

                        cell = new Cell(new Paragraph(percentFormat.format(questionStatistic.getFrequency()),
                                normalFont));
                        statsTable.addCell(cell);

                        cell = new Cell();
                        Image img = Image.getInstance(this.getClass().getResource("/chartbar.png"));
                        cell.setColspan(5);
                        img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f);
                        cell.addElement(img);
                        cell.setVerticalAlignment(Cell.ALIGN_BOTTOM);
                        statsTable.addCell(cell);
                        break;
                    }
                } else {
                    //single value question match on value
                    if (questionStatistic.getEntry() != null
                            && questionStatistic.getEntry().equals(option.getValue())) {
                        foundOption = true;
                        cell = new Cell(new Paragraph(percentFormat.format(questionStatistic.getFrequency()),
                                normalFont));
                        //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));}
                        statsTable.addCell(cell);

                        cell = new Cell();
                        //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));}
                        Image img = Image.getInstance(this.getClass().getResource("/chartbar.png"));
                        cell.setColspan(5);
                        img.scaleAbsolute((float) (questionStatistic.getFrequency() * 210), 10f);
                        cell.addElement(img);
                        cell.setVerticalAlignment(Cell.ALIGN_BOTTOM);
                        statsTable.addCell(cell);
                        break;
                    }

                }
            }
        }

        if (!foundOption) {

            cell = new Cell(new Paragraph(percentFormat.format(0), normalFont));
            //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));}
            statsTable.addCell(cell);

            cell = new Cell();
            //if ((rowIndex % 2) == 1) {cell.setBackgroundColor(new Color(244,244,244));}
            cell.setColspan(5);
            statsTable.addCell(cell);
        }
        rowIndex++;
    }
    document.add(statsTable);

}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeBooleanMatrixQuestionStatistics(Document document, Question question,
        List<QuestionStatistic> questionStatistics, String trueLabel, String falseLabel) throws Exception {

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(1);

    Table statsTable;// w  w  w.  ja v a 2 s .c  o  m
    Cell cell;

    statsTable = new Table(question.getColumnLabels().size() + 1);
    statsTable.setWidth(94);
    statsTable.setBorder(0);
    statsTable.setOffset(5);
    statsTable.setPadding(2);
    statsTable.setDefaultCellBorder(0);

    //header
    cell = new Cell();
    cell.setBorder(Cell.BOTTOM);
    statsTable.addCell(cell);
    for (QuestionColumnLabel columnLabel : question.getColumnLabels()) {
        cell = new Cell(new Paragraph(columnLabel.getLabel(), boldedFont));
        cell.setBorder(Cell.BOTTOM);
        statsTable.addCell(cell);
    }
    int rowIndex = 1;
    for (QuestionRowLabel rowLabel : question.getRowLabels()) {
        cell = new Cell(new Paragraph(rowLabel.getLabel(), boldedFont));
        cell.setBorder(Cell.RIGHT);
        if ((rowIndex % 2) == 1) {
            cell.setBackgroundColor(new Color(244, 244, 244));
        }
        statsTable.addCell(cell);
        for (QuestionColumnLabel columnLabel : question.getColumnLabels()) {
            boolean found = false;
            cell = new Cell();
            if ((rowIndex % 2) == 1) {
                cell.setBackgroundColor(new Color(244, 244, 244));
            }
            for (QuestionStatistic questionStatistic : questionStatistics) {
                if (questionStatistic.getRowOrder().equals(rowLabel.getOrder())
                        && questionStatistic.getColumnOrder().equals(columnLabel.getOrder())
                        && questionStatistic.getEntry().equals("1")) {
                    cell.add(new Paragraph(
                            trueLabel + ": " + percentFormat.format(questionStatistic.getFrequency()),
                            normalFont));
                    found = true;
                    break;
                }
            }
            if (!found) {
                cell.add(new Paragraph(trueLabel + ": " + percentFormat.format(0), normalFont));
            }

            found = false;
            for (QuestionStatistic questionStatistic : questionStatistics) {
                if (questionStatistic.getRowOrder().equals(rowLabel.getOrder())
                        && questionStatistic.getColumnOrder().equals(columnLabel.getOrder())
                        && questionStatistic.getEntry().equals("0")) {
                    cell.add(new Paragraph(
                            falseLabel + ": " + percentFormat.format(questionStatistic.getFrequency()),
                            normalFont));
                    found = true;
                    break;
                }
            }
            if (!found) {
                cell.add(new Paragraph(falseLabel + ": " + percentFormat.format(0), normalFont));
            }

            statsTable.addCell(cell);
        }
        rowIndex++;
    }

    document.add(statsTable);

}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeNumericMatrixQuestionStatistics(Document document, Question question,
        List<QuestionStatistic> questionStatistics, String minimumLabel, String maximumLabel,
        String averageLabel, String standardDeviationLabel) throws Exception {

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(1);

    Table statsTable;//from   ww w  . ja v a  2  s  . co  m
    Cell cell;

    statsTable = new Table(question.getColumnLabels().size() + 1);
    statsTable.setWidth(94);
    statsTable.setBorder(0);
    statsTable.setOffset(5);
    statsTable.setPadding(2);
    statsTable.setDefaultCellBorder(0);

    //header
    cell = new Cell();
    cell.setBorder(Cell.BOTTOM);
    statsTable.addCell(cell);
    for (QuestionColumnLabel columnLabel : question.getColumnLabels()) {
        cell = new Cell(new Paragraph(columnLabel.getLabel(), boldedFont));
        cell.setBorder(Cell.BOTTOM);
        statsTable.addCell(cell);
    }
    int rowIndex = 1;
    for (QuestionRowLabel rowLabel : question.getRowLabels()) {
        cell = new Cell(new Paragraph(rowLabel.getLabel(), boldedFont));
        cell.setBorder(Cell.RIGHT);
        if ((rowIndex % 2) == 1) {
            cell.setBackgroundColor(new Color(244, 244, 244));
        }
        statsTable.addCell(cell);
        for (QuestionColumnLabel columnLabel : question.getColumnLabels()) {
            boolean found = false;
            cell = new Cell();
            if ((rowIndex % 2) == 1) {
                cell.setBackgroundColor(new Color(244, 244, 244));
            }
            for (QuestionStatistic questionStatistic : questionStatistics) {
                if (questionStatistic.getRowOrder().equals(rowLabel.getOrder())
                        && questionStatistic.getColumnOrder().equals(columnLabel.getOrder())) {
                    cell.add(new Paragraph(
                            minimumLabel + ": " + BigDecimalValidator.getInstance()
                                    .format(questionStatistic.getMin(), LocaleContextHolder.getLocale()),
                            normalFont));
                    cell.add(new Paragraph(
                            maximumLabel + ": " + BigDecimalValidator.getInstance()
                                    .format(questionStatistic.getMax(), LocaleContextHolder.getLocale()),
                            normalFont));
                    cell.add(new Paragraph(
                            averageLabel + ": " + BigDecimalValidator.getInstance()
                                    .format(questionStatistic.getAverage(), LocaleContextHolder.getLocale()),
                            normalFont));
                    cell.add(new Paragraph(standardDeviationLabel + ": "
                            + BigDecimalValidator.getInstance().format(
                                    questionStatistic.getSampleStandardDeviation(),
                                    LocaleContextHolder.getLocale()),
                            normalFont));

                    break;
                }
            }
            if (!found) {
            }

            statsTable.addCell(cell);
        }
        rowIndex++;
    }

    document.add(statsTable);

}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeCurrencyMatrixQuestionStatistics(Document document, Question question,
        List<QuestionStatistic> questionStatistics, String minimumLabel, String maximumLabel,
        String averageLabel, String standardDeviationLabel) throws Exception {

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(1);

    Table statsTable;/*from   w ww .  jav  a2  s .co m*/
    Cell cell;

    statsTable = new Table(question.getColumnLabels().size() + 1);
    statsTable.setWidth(94);
    statsTable.setBorder(0);
    statsTable.setOffset(5);
    statsTable.setPadding(2);
    statsTable.setDefaultCellBorder(0);

    //header
    cell = new Cell();
    cell.setBorder(Cell.BOTTOM);
    statsTable.addCell(cell);
    for (QuestionColumnLabel columnLabel : question.getColumnLabels()) {
        cell = new Cell(new Paragraph(columnLabel.getLabel(), boldedFont));
        cell.setBorder(Cell.BOTTOM);
        statsTable.addCell(cell);
    }
    int rowIndex = 1;
    for (QuestionRowLabel rowLabel : question.getRowLabels()) {
        cell = new Cell(new Paragraph(rowLabel.getLabel(), boldedFont));
        cell.setBorder(Cell.RIGHT);
        if ((rowIndex % 2) == 1) {
            cell.setBackgroundColor(new Color(244, 244, 244));
        }
        statsTable.addCell(cell);
        for (QuestionColumnLabel columnLabel : question.getColumnLabels()) {
            boolean found = false;
            cell = new Cell();
            if ((rowIndex % 2) == 1) {
                cell.setBackgroundColor(new Color(244, 244, 244));
            }
            for (QuestionStatistic questionStatistic : questionStatistics) {
                if (questionStatistic.getRowOrder().equals(rowLabel.getOrder())
                        && questionStatistic.getColumnOrder().equals(columnLabel.getOrder())) {
                    cell.add(new Paragraph(
                            minimumLabel + ": " + CurrencyValidator.getInstance()
                                    .format(questionStatistic.getMin(), LocaleContextHolder.getLocale()),
                            normalFont));
                    cell.add(new Paragraph(
                            maximumLabel + ": " + CurrencyValidator.getInstance()
                                    .format(questionStatistic.getMax(), LocaleContextHolder.getLocale()),
                            normalFont));
                    cell.add(new Paragraph(
                            averageLabel + ": " + CurrencyValidator.getInstance()
                                    .format(questionStatistic.getAverage(), LocaleContextHolder.getLocale()),
                            normalFont));
                    cell.add(new Paragraph(standardDeviationLabel + ": "
                            + CurrencyValidator.getInstance().format(
                                    questionStatistic.getSampleStandardDeviation(),
                                    LocaleContextHolder.getLocale()),
                            normalFont));

                    break;
                }
            }
            if (!found) {
            }

            statsTable.addCell(cell);
        }
        rowIndex++;
    }

    document.add(statsTable);

}

From source file:com.jd.survey.web.pdf.StatisticsPdf.java

License:Open Source License

private void writeDateMatrixQuestionStatistics(Document document, Question question,
        List<QuestionStatistic> questionStatistics, String minimumLabel, String maximumLabel, String dateFormat)
        throws Exception {

    NumberFormat percentFormat = NumberFormat.getPercentInstance();
    percentFormat.setMaximumFractionDigits(1);

    Table statsTable;//from   w  w  w . ja va  2s.  co m
    Cell cell;

    statsTable = new Table(question.getColumnLabels().size() + 1);
    statsTable.setWidth(94);
    statsTable.setBorder(0);
    statsTable.setOffset(5);
    statsTable.setPadding(2);
    statsTable.setDefaultCellBorder(0);

    //header
    cell = new Cell();
    cell.setBorder(Cell.BOTTOM);
    statsTable.addCell(cell);
    for (QuestionColumnLabel columnLabel : question.getColumnLabels()) {
        cell = new Cell(new Paragraph(columnLabel.getLabel(), boldedFont));
        cell.setBorder(Cell.BOTTOM);
        statsTable.addCell(cell);
    }
    int rowIndex = 1;
    for (QuestionRowLabel rowLabel : question.getRowLabels()) {
        cell = new Cell(new Paragraph(rowLabel.getLabel(), boldedFont));
        cell.setBorder(Cell.RIGHT);
        if ((rowIndex % 2) == 1) {
            cell.setBackgroundColor(new Color(244, 244, 244));
        }
        statsTable.addCell(cell);
        for (QuestionColumnLabel columnLabel : question.getColumnLabels()) {
            boolean found = false;
            cell = new Cell();
            if ((rowIndex % 2) == 1) {
                cell.setBackgroundColor(new Color(244, 244, 244));
            }
            for (QuestionStatistic questionStatistic : questionStatistics) {
                if (questionStatistic.getRowOrder().equals(rowLabel.getOrder())
                        && questionStatistic.getColumnOrder().equals(columnLabel.getOrder())) {
                    cell.add(new Paragraph(minimumLabel + ": "
                            + DateValidator.getInstance().format(questionStatistic.getMinDate(), dateFormat),
                            normalFont));
                    cell.add(new Paragraph(maximumLabel + ": "
                            + DateValidator.getInstance().format(questionStatistic.getMaxDate(), dateFormat),
                            normalFont));
                    break;
                }
            }
            if (!found) {
            }

            statsTable.addCell(cell);
        }
        rowIndex++;
    }

    document.add(statsTable);

}

From source file:com.jd.survey.web.pdf.SurveyPdf.java

License:Open Source License

private void writeAnswer(Document document, String questionText, boolean answerValue, String falseMessage,
        String trueMessage) throws Exception {

    //String falseString ="False";  
    //String trueString = "True";

    Paragraph questionParagraph = new Paragraph();
    questionParagraph.setLeading(14, 0);
    questionParagraph.add(new Chunk(questionText.trim() + ": ", boldedFont));
    questionParagraph.add(new Chunk(answerValue ? trueMessage : falseMessage, normalFont));
    document.add(questionParagraph);
}