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:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java

License:Mozilla Public License

/**
 * Build the matrix for the content of the crosstab
 * @param data/*from w ww  .j  a  v  a 2 s . c  o  m*/
 * @throws JSONException
 */
private void buildDataMatrix(JSONArray data) throws JSONException {
    logger.debug("IN: building the crosstab content");
    PdfPCell cell;
    for (int i = 0; i < data.length(); i++) {
        JSONArray array = (JSONArray) data.get(i);
        List<PdfPCell> dataRow = new ArrayList<PdfPCell>();
        for (int j = 0; j < array.length(); j++) {
            String text = (String) array.get(j);
            //Check if a cell is a sum
            if (text.length() > 5 && text.substring(0, 5).equals("[sum]")) {
                text = text.substring(5);
                cell = new PdfPCell(new Phrase(getFormattedString(text, i, j), cellFont));
                cell.setBackgroundColor(sumBackgroundColor);
            } else {
                cell = new PdfPCell(new Phrase(getFormattedString(text, i, j), cellFont));
            }

            cell.setBorderColor(cellsBorderColor);
            dataRow.add(cell);
        }
        dataMatrix.add(dataRow);
    }
    logger.debug("OUT: built the crosstab content");
}

From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java

License:Mozilla Public License

/**
 * Builds the row headers. This method performs a depth first visit
 * of the row headers tree/*from  ww  w . j  a v  a 2s .  c  o  m*/
 * @param siblings: a level (L) of headers
 * @return the cells from level L to the leafs
 * @throws JSONException
 * @throws BadElementException
 */
private List<PdfPCell> buildRowsHeaders(JSONArray siblings) throws JSONException, BadElementException {
    JSONArray childs;
    List<PdfPCell> rowNodes = new ArrayList<PdfPCell>();

    //For every node of the level..
    for (int i = 0; i < siblings.length(); i++) {
        JSONObject aNode = (JSONObject) siblings.get(i);
        String text = (String) aNode.opt(Node.CROSSTAB_NODE_JSON_DESCRIPTION);
        if (text == null) {
            // in case of calculated fields
            text = (String) aNode.get(CrossTab.CROSSTAB_NODE_JSON_KEY);
        }

        int descendants = aNode.getInt(CrosstabExporterUtility.CROSSTAB_JSON_DESCENDANTS_NUMBER);

        PdfPCell cell = new PdfPCell(new Phrase(text, cellFont));
        cell.setBackgroundColor(headersBackgroundColor);
        cell.setBorderColor(cellsBorderColor);

        if (descendants > 1) {
            cell.setRowspan(descendants);
        }

        //1) add the node name
        rowNodes.add(cell);

        //2) add the child node names
        childs = aNode.optJSONArray(CrossTab.CROSSTAB_NODE_JSON_CHILDS);
        if (childs != null && childs.length() > 0) {
            rowNodes.addAll(buildRowsHeaders(childs));
        } else {
            rowNodes.addAll(dataMatrix.remove(0));
        }
    }
    return rowNodes;
}

From source file:it.eng.spagobi.engines.qbe.crosstable.exporter.CrosstabPDFExporter.java

License:Mozilla Public License

/**
 * Builds cells for the column headers/*w w  w .ja v a  2 s .c o m*/
 * @param siblings the top level 
 * @return
 * @throws JSONException
 * @throws BadElementException
 */
private List<PdfPCell> buildColumnsHeader(JSONArray siblings, JSONArray rowHeadersDescription,
        int dataColumnNumber) throws JSONException, BadElementException {

    List<PdfPCell> cells = new ArrayList<PdfPCell>();

    List<JSONObject> columnNodes = getAllNodes(siblings);

    for (int i = 0; i < columnNodes.size(); i++) {
        //adds the row headers
        if (rowHeadersDescription != null && i == columnNodes.size() - dataColumnNumber) {
            for (int y = 0; y < rowHeadersDescription.length(); y++) {
                String text = rowHeadersDescription.getString(y);
                PdfPCell cell = new PdfPCell(new Phrase(text, cellFont));
                cell.setBorderColor(cellsBorderColor);
                cell.setBackgroundColor(headersBackgroundColor);
                cells.add(cell);
            }

        }
        JSONObject aNode = (JSONObject) columnNodes.get(i);
        String text = (String) aNode.get(Node.CROSSTAB_NODE_JSON_DESCRIPTION);
        int descendants = aNode.getInt(CrosstabExporterUtility.CROSSTAB_JSON_DESCENDANTS_NUMBER);

        PdfPCell cell = new PdfPCell(new Phrase(text, cellFont));
        cell.setBorderColor(cellsBorderColor);
        cell.setBackgroundColor(headersBackgroundColor);

        if (descendants > 1) {
            cell.setColspan(descendants);
        }
        cells.add(cell);
    }

    return cells;
}

From source file:it.prato.comune.tolomeo.web.TolomeoPrintPDFServlet.java

License:Open Source License

private void print(String riga, Font font, Paragraph par, Document doc) throws Exception {
    try {// w w w . jav  a 2  s. c om
        Phrase frase = new Phrase(riga + "\r\n", font);
        par.add(frase);
        doc.add(par);
        par.clear();
    } catch (Exception e) {
        throw e;
    }
}

From source file:jmemorize.core.io.PdfRtfBuilder.java

License:Open Source License

/**
 * Adds given card to document/*from w  w  w  .j  a va 2  s.  c  o  m*/
 * 
 * @param doc document to add to
 * @param card given card
 */
private static void writeCard(Document doc, Card card) throws DocumentException {
    Table table = new Table(2);

    table.setPadding(3f);
    table.setBorderWidth(1.0f);
    table.setTableFitsPage(true);
    table.complete();

    Phrase front = new Phrase(card.getFrontSide().getText().getUnformatted(), frontFont);
    table.addCell(front);
    Phrase back = new Phrase(card.getBackSide().getText().getUnformatted(), backFont);
    table.addCell(back);

    doc.add(table);
}

From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java

License:Apache License

private void writeClientInfo(Document doc) throws Exception {
    PdfPTable tb = new PdfPTable(2);
    tb.setWidthPercentage(100.0f);//from   ww  w .  j  a  va 2s  .  co  m
    tb.setSpacingAfter(20.0f);

    PdfPCell cl = new PdfPCell(
            new Phrase(this.client.getName() + "\n" + this.client.getAdress(), new Font(baseArial, 10)));
    tb.addCell(cl);

    cl = new PdfPCell(new Phrase(this.we.getName() + "\n" + this.we.getAdress(), new Font(baseArial, 10)));
    tb.addCell(cl);

    doc.add(tb);

}

From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java

License:Apache License

private void writeTicketInfo(Document doc) throws Exception {
    Paragraph pg = new Paragraph("#" + tt.getUniqueId(), new Font(baseArial, 12, Font.BOLD));
    doc.add(pg);/*from w w w  .j a  v a2  s. com*/

    PdfPTable tb = new PdfPTable(1);
    tb.setWidthPercentage(100.0f);
    tb.setSpacingBefore(5.0f);
    tb.setSpacingAfter(5.0f);

    PdfPCell cl = new PdfPCell(new Phrase(tt.getName(), new Font(baseArial, 10, Font.BOLD)));

    tb.addCell(cl);

    if (clientPerson != null) {
        cl = new PdfPCell(new Phrase(
                "Prane: " + clientPerson.getName() + " (Telefono Nr: " + clientPerson.getPhoneNo() + ")",
                new Font(baseArial, 10)));
        tb.addCell(cl);
    }

    cl = new PdfPCell(new Phrase("Uduoties informacija: ", new Font(baseArial, 10)));
    tb.addCell(cl);

    cl = new PdfPCell(new Phrase(tt.getDescription(), new Font(baseArial, 10)));

    tb.addCell(cl);

    doc.add(tb);
}

From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java

License:Apache License

private void writeWorkerInfo(Document doc) throws Exception {

    PdfPTable tb = new PdfPTable(2);
    tb.setWidthPercentage(100.0f);/* w  w  w  .  j a v  a2 s  . c om*/
    tb.setSpacingBefore(8.0f);
    tb.setSpacingAfter(8.0f);

    PdfPCell cl;

    cl = new PdfPCell(new Phrase("Atsakingas asmuo: " + me.getName(), new Font(baseArial, 10)));
    cl.setColspan(2);
    tb.addCell(cl);

    cl = new PdfPCell(new Phrase("vykdymo data: " + timeFormat(tt.getDateClosed()), new Font(baseArial, 10)));
    tb.addCell(cl);

    if (tt.getWorktime() != null) {
        cl = new PdfPCell(new Phrase("Darbo valandos:" + tt.getWorktime(), new Font(baseArial, 10)));
        tb.addCell(cl);
    } else {
        cl = new PdfPCell(new Phrase("Darbo valandos: ", new Font(baseArial, 10)));
        tb.addCell(cl);
    }

    doc.add(tb);

    tb = new PdfPTable(2);

    tb.setWidthPercentage(100.0f);
    tb.setSpacingBefore(50.0f);

    cl = new PdfPCell(new Phrase("Kliento paraas\n\n\n\n", new Font(baseArial, 10)));
    cl.setBorder(0);
    tb.addCell(cl);

    cl = new PdfPCell(new Phrase("Uduot atliks darbuotojas\n\n\n\n", new Font(baseArial, 10)));
    cl.setBorder(0);
    tb.addCell(cl);
    doc.add(tb);

}

From source file:lt.bsprendimai.ddesk.pdf.PDFTicket.java

License:Apache License

private void writeJobInfo(Document doc) throws Exception {

    Paragraph pg = new Paragraph("\nUDUOTIES ATLIKIMO INFORMACIJA", new Font(baseArial, 10, Font.BOLD));
    doc.add(pg);//from w ww  . j a va  2 s .co  m

    PdfPTable tb = new PdfPTable(3);
    tb.setWidthPercentage(100.0f);
    tb.setSpacingBefore(5.0f);
    tb.setSpacingAfter(12.0f);
    tb.setWidths(new float[] { 6.0f, 84.0f, 10.0f });

    PdfPCell cl;

    doc.add(new Phrase("\nAtlikti darbai", new Font(baseArial, 12, Font.BOLD)));

    cl = new PdfPCell(new Phrase("Eil.nr", new Font(baseArial, 10, Font.BOLD)));
    tb.addCell(cl);
    cl = new PdfPCell(new Phrase("Uduoties pavadinimas", new Font(baseArial, 10, Font.BOLD)));
    tb.addCell(cl);
    cl = new PdfPCell(new Phrase("Valandos", new Font(baseArial, 10, Font.BOLD)));
    tb.addCell(cl);

    doc.add(tb);

}

From source file:net.algem.contact.TeacherCtrl.java

License:Open Source License

private File getFollowUpAsPDF(String userId, String from, String to)
        throws IOException, BadElementException, DocumentException {
    String path = "/tmp/" + "suivi-" + userId + ".pdf";
    File f = new File(path);
    LOGGER.log(Level.INFO, f.getName());
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Document document = new Document(PageSize.A4.rotate());
    PdfWriter.getInstance(document, byteArrayOutputStream); // Do this BEFORE document.open()
    document.open();//from ww  w.  ja va  2s. com

    PdfPTable table = new PdfPTable(10);
    table.setWidthPercentage(100);
    table.setWidths(new float[] { 1.1f, 1.2f, 0.6f, 1.5f, 1.5f, 2f, 0.5f, 0.5f, 1.9f, 1.9f });

    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false);
    BaseFont bfb = BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.WINANSI, false);
    Font normalFont = new Font(bf, 10);
    Font boldFont = new Font(bfb, 10);

    String fromLabel = messageSource.getMessage("from.label", null, CTX_LOCALE);
    String toLabel = messageSource.getMessage("to.label", null, CTX_LOCALE);
    String prefix = messageSource.getMessage("follow-up.label", null, CTX_LOCALE) + " "
            + organization.get("name.label");
    String period = fromLabel.toLowerCase() + " " + from + " " + toLabel.toLowerCase() + " " + to;
    PdfPCell headerCell = new PdfPCell(new Phrase(prefix + " " + period, boldFont));

    headerCell.setBackgroundColor(Color.LIGHT_GRAY);
    headerCell.setColspan(10);
    table.addCell(headerCell);

    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("date.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("time.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("time.length.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(new Phrase(messageSource.getMessage("room.label", null, CTX_LOCALE), boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("course.label", null, CTX_LOCALE), boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("student.label", null, CTX_LOCALE), boldFont)));
    String abs = messageSource.getMessage("absence.label", null, CTX_LOCALE);
    table.addCell(new PdfPCell(new Phrase(abs != null ? abs.substring(0, 3) + "." : "", boldFont)));
    table.addCell(
            new PdfPCell(new Phrase(messageSource.getMessage("score.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("individual.logbook.label", null, CTX_LOCALE), boldFont)));
    table.addCell(new PdfPCell(
            new Phrase(messageSource.getMessage("collective.comment.label", null, CTX_LOCALE), boldFont)));

    List<ScheduleElement> items = getFollowUpSchedules(userId, from, to);
    //LOGGER.log(Level.INFO, items.toString());
    for (ScheduleElement e : items) {
        List<ScheduleRangeElement> ranges = new ArrayList<ScheduleRangeElement>(
                (Collection<? extends ScheduleRangeElement>) e.getRanges());

        for (ScheduleRangeElement r : ranges) {
            String status = CommonDao.getAbsenceFromNumberStatus(r.getFollowUp().getStatus());
            String note = r.getFollowUp().getNote();
            String content1 = r.getFollowUp().getContent();
            String content2 = e.getFollowUp().getContent();
            table.addCell(new Phrase(e.getDateFr().toString(), normalFont));
            table.addCell(new Phrase(r.getStart() + "-" + r.getEnd(), normalFont));
            table.addCell(new Phrase(new Hour(r.getLength()).toString(), normalFont));
            table.addCell(new Phrase(e.getDetail().get("room").getName(), normalFont));
            table.addCell(new Phrase(e.getDetail().get("course").getName(), normalFont));
            table.addCell(new Phrase(r.getPerson().getFirstName() + " " + r.getPerson().getName(), normalFont));
            table.addCell(new Phrase(status, normalFont));
            table.addCell(new Phrase(note == null ? "" : note, normalFont));
            table.addCell(new Phrase(content1 == null ? "" : content1.replaceAll("[\r\n]", " "), normalFont));
            table.addCell(new Phrase(content2 == null ? "" : content2.replaceAll("[\r\n]", " "), normalFont));
        }
    }

    document.add(table);
    document.close();
    byte[] pdfBytes = byteArrayOutputStream.toByteArray();
    Files.write(Paths.get(path), pdfBytes);
    return f;
}