Example usage for com.lowagie.text Phrase Phrase

List of usage examples for com.lowagie.text Phrase Phrase

Introduction

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

Prototype

public Phrase(float leading, String string) 

Source Link

Document

Constructs a Phrase with a certain leading and a certain String.

Usage

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

@Override
public void addDocumentHeaderThin(final Document document, final String name, final String documentTitle,
        final String documentAuthor, final Date date) throws DocumentException {
    SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale());
    LineSeparator line = new LineSeparator(2, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0);
    Paragraph title = new Paragraph(new Phrase(documentTitle, FontUtils.getDejavuBold14Light()));
    title.add(new Phrase(" " + name, FontUtils.getDejavuBold14Dark()));
    title.setSpacingAfter(7f);//from  ww w.  jav a2s .  c  om
    document.add(title);
    document.add(line);
    PdfPTable userAndDate = new PdfPTable(2);
    userAndDate.setWidthPercentage(100f);
    userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT);
    userAndDate.getDefaultCell().setBorderWidth(0);
    Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light()));
    userParagraph.add(new Phrase(" " + getDocumentAuthor(), FontUtils.getDejavuRegular9Dark()));
    Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light());
    userAndDate.addCell(userParagraph);
    userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
    userAndDate.addCell(dateParagraph);
    userAndDate.setSpacingAfter(10f);
    document.add(userAndDate);
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

private void addTableCellAsTable(final PdfPTable table, final String label, final Object fieldValue,
        final String nullValue, final Font headerFont, final Font valueFont, final int columns,
        final int[] columnWidths) {
    PdfPTable cellTable = new PdfPTable(columns);

    if (columnWidths.length > 0) {
        try {//w ww  .j  a va 2s.c  o  m
            cellTable.setWidths(columnWidths);
        } catch (DocumentException e) {
            LOG.error(e.getMessage(), e);
        }
    }

    cellTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    cellTable.addCell(new Phrase(label, headerFont));

    if (fieldValue == null) {
        cellTable.addCell(new Phrase(nullValue, valueFont));
    } else {
        cellTable.addCell(new Phrase(fieldValue.toString(), valueFont));
    }

    table.addCell(cellTable);
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

private PdfPTable setTableProperties(final List<String> header, final boolean lastColumnAligmentToLeft,
        final PdfPTable table, final Map<String, HeaderAlignment> alignments) {
    table.setWidthPercentage(100f);/*w  w  w  .ja  v  a2 s  .  c  om*/
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.setSpacingBefore(7.0f);
    // table.getDefaultCell().setBackgroundColor(ColorUtils.getBackgroundColor());
    table.getDefaultCell().setBorderColor(ColorUtils.getLineDarkColor());
    table.getDefaultCell().setBorderWidth(1.0f);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.getDefaultCell().setPadding(5.0f);
    table.getDefaultCell().disableBorderSide(Rectangle.RIGHT);

    if (alignments == null || alignments.isEmpty()) {
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        int i = 0;
        for (String element : header) {
            i++;
            if (i == header.size()) {
                table.getDefaultCell().enableBorderSide(Rectangle.RIGHT);
            }
            table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark()));
            if (i == 1) {
                table.getDefaultCell().disableBorderSide(Rectangle.LEFT);
            }
        }
    } else {
        int i = 0;

        for (String element : header) {
            i++;
            HeaderAlignment alignment = alignments.get(element);
            if (HeaderAlignment.LEFT.equals(alignment)) {
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            } else if (HeaderAlignment.RIGHT.equals(alignment)) {
                table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);
            }
            if (i == header.size()) {
                table.getDefaultCell().enableBorderSide(Rectangle.RIGHT);
            }
            table.addCell(new Phrase(element, FontUtils.getDejavuBold7Dark()));
            if (i == 1) {
                table.getDefaultCell().disableBorderSide(Rectangle.LEFT);
            }
        }
    }
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    table.getDefaultCell().setBackgroundColor(null);
    table.getDefaultCell().disableBorderSide(Rectangle.RIGHT);
    table.getDefaultCell().setBorderColor(ColorUtils.getLineLightColor());
    return table;
}

From source file:com.silverpeas.kmelia.workflowextensions.SendInKmelia.java

License:Open Source License

private void generatePDFStepHeader(HistoryStep step, com.lowagie.text.Document document) {
    try {//from  ww w.j  a va  2 s .com
        String activity = "";
        if (step.getResolvedState() != null) {
            State resolvedState = step.getProcessInstance().getProcessModel().getState(step.getResolvedState());
            activity = resolvedState.getLabel(getRole(), getLanguage());
        }

        String sAction = null;
        try {
            if ("#question#".equals(step.getAction())) {
                sAction = getString("processManager.question");
            } else if ("#response#".equals(step.getAction())) {
                sAction = getString("processManager.response");
            } else if ("#reAssign#".equals(step.getAction())) {
                sAction = getString("processManager.reAffectation");
            } else {
                Action action = step.getProcessInstance().getProcessModel().getAction(step.getAction());
                sAction = action.getLabel(getRole(), getLanguage());
            }
        } catch (WorkflowException we) {
            sAction = "##";
        }

        String actor = getBestUserDetail().getDisplayedName();

        String date = DateUtil.getOutputDateAndHour(step.getActionDate(), getLanguage());

        String header = "";
        if (StringUtil.isDefined(activity)) {
            header += activity + " - ";
        }
        header += sAction + " (" + actor + " - " + date + ")";

        Font fontHeader = new Font(Font.HELVETICA, 12, Font.NORMAL);

        PdfPCell pCell = new PdfPCell(new Phrase(header, fontHeader));
        pCell.setFixedHeight(28);
        pCell.setBackgroundColor(new Color(239, 239, 239));
        pCell.setVerticalAlignment(Element.ALIGN_MIDDLE);

        PdfPTable pTable = new PdfPTable(1);
        pTable.setWidthPercentage(100);
        pTable.addCell(pCell);

        document.add(pTable);
    } catch (Exception e) {
        SilverTrace.error("workflowEngine", "SendInKmelia.generatePDFStep()", "root.MSG_GEN_ERROR", e);
    }
}

From source file:com.silverpeas.kmelia.workflowextensions.SendInKmelia.java

License:Open Source License

private void generatePDFStepContent(HistoryStep step, com.lowagie.text.Document document) {
    try {//from  w w w  .j a  v a  2s . c o  m
        Form form;
        if ("#question#".equals(step.getAction()) || "#response#".equals(step.getAction())) {
            // TODO
            form = null;
        } else {
            form = getProcessInstance().getProcessModel().getPresentationForm(step.getAction(), getRole(),
                    getLanguage());
        }

        XmlForm xmlForm = (XmlForm) form;
        if (xmlForm != null && step.getActionRecord() != null) {
            DataRecord data = step.getActionRecord();
            VersioningUtil versioningUtil = new VersioningUtil();

            // Force simpletext displayers because itext cannot display HTML Form fields (select,
            // radio...)
            float[] colsWidth = { 25, 75 };
            PdfPTable tableContent = new PdfPTable(colsWidth);
            tableContent.setWidthPercentage(100);

            PdfPCell cell = null;
            Field field;
            String fieldLabel;
            String fieldValue = "";
            Font fontLabel = new Font(Font.HELVETICA, 10, Font.BOLD);
            Font fontValue = new Font(Font.HELVETICA, 10, Font.NORMAL);
            List<FieldTemplate> fieldTemplates = xmlForm.getFieldTemplates();
            for (FieldTemplate fieldTemplate1 : fieldTemplates) {
                GenericFieldTemplate fieldTemplate = (GenericFieldTemplate) fieldTemplate1;

                fieldLabel = fieldTemplate.getLabel("fr");
                field = data.getField(fieldTemplate.getFieldName());
                String componentId = step.getProcessInstance().getProcessModel().getModelId();

                //          fieldValue = data.getField(fieldTemplate.getFieldName()).getValue();
                //wysiwyg field
                if ("wysiwyg".equals(fieldTemplate.getDisplayerName())) {
                    String file = WysiwygFCKFieldDisplayer.getFile(componentId,
                            getProcessInstance().getInstanceId(), fieldTemplate.getFieldName(), getLanguage());

                    //Extract the text content of the html code
                    Source source = new Source(file);
                    if (source != null) {
                        fieldValue = source.getTextExtractor().toString();
                    }
                }
                //Field file type
                else if (FileField.TYPE.equals(fieldTemplate.getDisplayerName())
                        && StringUtil.isDefined(field.getValue())) {
                    boolean fromCompoVersion = "yes".equals(getOrganizationController()
                            .getComponentParameterValue(componentId, "versionControl"));
                    //Versioning Used
                    if (fromCompoVersion) {
                        DocumentVersion documentVersion = versioningUtil
                                .getDocumentVersion(new DocumentVersionPK(Integer.parseInt(field.getValue())));
                        if (documentVersion != null) {
                            fieldValue = documentVersion.getLogicalName();
                        }
                    } else {
                        AttachmentDetail attDetail = AttachmentController
                                .searchAttachmentByPK(new AttachmentPK(field.getValue(), componentId));
                        if (attDetail != null) {
                            fieldValue = attDetail.getLogicalName(getLanguage());
                        }
                    }
                }
                //Field date type
                else if (fieldTemplate.getTypeName().equals("date")) {
                    fieldValue = DateUtil.getOutputDate(fieldValue, "fr");
                }
                //Others fields type
                else {
                    fieldTemplate.setDisplayerName("simpletext");
                    fieldValue = field.getValue(getLanguage());
                }

                cell = new PdfPCell(new Phrase(fieldLabel, fontLabel));
                cell.setBorderWidth(0);
                cell.setPaddingBottom(5);
                tableContent.addCell(cell);

                cell = new PdfPCell(new Phrase(fieldValue, fontValue));
                cell.setBorderWidth(0);
                cell.setPaddingBottom(5);
                tableContent.addCell(cell);
            }

            document.add(tableContent);
        }
    } catch (Exception e) {
        SilverTrace.error("workflowEngine", "SendInKmelia.generatePDFStep()", "root.MSG_GEN_ERROR", e);
    }
}

From source file:com.slamd.report.PDFReportGenerator.java

License:Open Source License

/**
 * Writes the specified text to the provided table as a header cell.
 *
 * @param  table  The table to which the header cell should be written.
 * @param  text   The text to write to the header cell.
 */// w  w  w .  j  a  v a  2s.com
private void writeTableHeaderCell(PdfPTable table, String text) {
    Phrase phrase = new Phrase(text, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, Color.BLACK));
    table.addCell(new PdfPCell(phrase));
}

From source file:corner.orm.tapestry.pdf.components.AbstractPdfTableDisplay.java

License:Apache License

/**
 * PdfPTableHeader/*from  w  ww  .  j  av  a 2  s. c o m*/
 * 
 * @param table
 */
protected void beginTableHeader(PdfPTable table) {
    // 
    if (this.getDisplayTableModel().getHeaders() != null) {
        Font headerFont = this.getDisplayTableModel().getHeadersFont();
        if (headerFont == null) {//footer
            headerFont = PdfUtils.createHeaderSongLightFont(10);
        }
        for (int i = 0; i < getDisplayTableModel().getColumnCount(); i++) {

            // TODO ??
            PdfPCell cell = new PdfPCell(new Phrase(getDisplayTableModel().getHeaders()[i], headerFont));

            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);// 
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);// 

            table.addCell(cell);
        }
    }

}

From source file:corner.orm.tapestry.pdf.components.AbstractPdfTableDisplay.java

License:Apache License

/**
 * PdfPTableFooter// w w w . j ava 2  s.  c o  m
 * 
 * @param table
 */
protected void beginTableFooter(PdfPTable table, PdfWriter writer) {
    if (this.getDisplayTableModel().getFooters() != null) {
        List<String> cells = this.getDisplayTableModel().getFooters();
        Font footerFont = this.getDisplayTableModel().getFootersFont();
        if (footerFont == null) {//footer
            footerFont = PdfUtils.createHeaderSongLightFont(10);
        }
        Iterator<String> it = cells.iterator();
        while (it.hasNext()) {
            String key = it.next();
            // TODO ??
            PdfPCell cell = new PdfPCell(new Phrase(key, footerFont));
            cell.setColspan(getDisplayTableModel().getColumnCount());
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);// ??
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);// 

            table.addCell(cell);
        }
    }
}

From source file:corner.orm.tapestry.pdf.components.AbstractPdfTableDisplay.java

License:Apache License

protected void createTableRow(PdfWriter writer, PdfPTable table, Object obj, int columnCount,
        IPdfTableModel model) {//  w  ww  .j  a va2  s.c  om
    Font contentFont = model.getContentFont();
    if (contentFont == null) {//model??
        contentFont = PdfUtils.createSongLightFont(10);
    }
    for (int i = 0; i < columnCount; i++) {
        // ??TableRow?.
        PdfPCell cell = new PdfPCell(new Phrase("", contentFont));
        // .
        cell.setCellEvent(
                new CreateTextFieldCellEvent(writer, getDisplayTableModel().getCurrentColumnValue(obj, i)));
        table.addCell(cell);
    }

}

From source file:corner.orm.tapestry.pdf.components.PdfColumnText.java

License:Apache License

/**
 * ColumnText.// ww w.  j av a 2 s  . c o  m
 * 
 * @param ct
 */
@Override
protected void renderColumnText(ColumnText ct, PdfWriterDelegate writer, Document doc) {
    ct.addText(new Phrase(getValue(), PdfUtils.createSongLightFont(0)));
}