Example usage for com.itextpdf.text Phrase Phrase

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

Introduction

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

Prototype

public Phrase(final float leading, final String string) 

Source Link

Document

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

Usage

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

private Phrase getPhraseText(String text) {
    return new Phrase(text, FontFactory.getFont(fontNameStandard, fontSizeText, Font.NORMAL));
}

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

private Phrase getPhraseTextBold(String text) {
    return new Phrase(text, FontFactory.getFont(fontNameStandard, fontSizeText, Font.BOLD));
}

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

private Phrase getPhraseChapter(String text) {
    return new Phrase(text, FontFactory.getFont(fontNameStandard, fontSizeChapter, Font.BOLD));
}

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

private Phrase getPhraseChapterItalic(String text) {
    return new Phrase(text, FontFactory.getFont(fontNameStandard, fontSizeChapter, Font.BOLDITALIC));
}

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

private Phrase getPhraseHeaderFooter(String text) {
    return new Phrase(text, FontFactory.getFont(fontNameStandard, fontSizeFooter, Font.NORMAL));
}

From source file:de.fau.osr.util.matrix.MatrixTools.java

License:Open Source License

/**
 * adds new cell to table/*from w  w  w .j a  v a  2  s.co m*/
 * @param table table to work with
 * @param text content of cell
 * @param fontSize font fontSize
 * @param alignment enum alignment
 * @param rowFixedHeight cell fixed height
 * @return added cell
 */
private static PdfPCell addCell(PdfPTable table, String text, int fontSize, int alignment,
        float rowFixedHeight) {
    Phrase ph = new Phrase(text, getFont(fontSize));
    PdfPCell cell = new PdfPCell(ph);
    cell.setHorizontalAlignment(alignment);
    if (rowFixedHeight > 0)
        cell.setFixedHeight(rowFixedHeight);
    table.addCell(cell);
    return cell;
}

From source file:de.jost_net.JVerein.io.HeaderFooter.java

License:Open Source License

/**
 * Adds the header and the footer.//from w w  w.  j  ava2  s  .  c  om
 * 
 */
@Override
public void onEndPage(PdfWriter writer, Document document) {
    Rectangle rect = document.getPageSize();
    switch (writer.getPageNumber() % 2) {
    case 0:
        // ColumnText.showTextAligned(writer.getDirectContent(),
        // Element.ALIGN_RIGHT, header[0], rect.getRight(), rect.getTop(), 0);
        break;
    case 1:
        // ColumnText.showTextAligned(writer.getDirectContent(),
        // Element.ALIGN_LEFT,
        // header[1], rect.getLeft(), rect.getTop(), 0);
        break;
    }
    float left = rect.getLeft() + document.leftMargin();
    float right = rect.getRight() - document.rightMargin();
    float bottom = rect.getBottom() + document.bottomMargin();
    PdfContentByte pc = writer.getDirectContent();
    pc.setColorStroke(BaseColor.BLACK);
    pc.setLineWidth(0.5f);
    pc.moveTo(left, bottom - 5);
    pc.lineTo(right, bottom - 5);
    pc.stroke();
    pc.moveTo(left, bottom - 25);
    pc.lineTo(right, bottom - 25);
    pc.stroke();

    ColumnText.showTextAligned(pc, Element.ALIGN_CENTER,
            new Phrase(footer + " " + pagenumber, Reporter.getFreeSans(7)), (left + right) / 2, bottom - 18, 0);
}

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

/**
 * Erzeugt eine Zelle fuer die uebergebene Zahl.
 * /*from ww w. j a va2 s .c  o  m*/
 * @param value
 *          die Zahl.
 * @return die erzeugte Zelle.
 */
private PdfPCell getDetailCell(double value) {
    Font f = null;
    if (value >= 0) {
        f = getFreeSans(8, BaseColor.BLACK);
    } else {
        f = getFreeSans(8, BaseColor.RED);
    }
    PdfPCell cell = new PdfPCell(new Phrase(Einstellungen.DECIMALFORMAT.format(value), f));
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return cell;
}

From source file:de.tuttas.servlets.DokuServlet.java

private Document createUmfrageauswertung(List<UmfrageResult> res1, List<UmfrageResult> res2, int idUmfrage1,
        int idUmfrage2, String filter1, String filter2, String kopf, OutputStream out)
        throws DocumentException, BadElementException, IOException {
    Document document = new Document();
    /* Basic PDF Creation inside servlet */
    Umfrage u1 = em.find(Umfrage.class, idUmfrage1);
    Umfrage u2 = em.find(Umfrage.class, idUmfrage2);

    // Bild einfgen
    String url = "http://www.mmbbs.de/fileadmin/template/mmbbs/gfx/mmbbs_logo_druck.gif";
    Image image = Image.getInstance(url);
    image.setAbsolutePosition(45f, 720f);
    image.scalePercent(50f);//from www.j  a  v a2 s. c  om

    StringBuilder htmlString = new StringBuilder();
    htmlString.append(kopf);
    htmlString.append("<br></br>");

    int maxRows = res1.size();
    if (res2.size() > maxRows) {
        maxRows = res2.size();
    }
    PdfWriter writer = PdfWriter.getInstance(document, out);
    document.open();
    writer.setPageEmpty(false);
    Font boldFont = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD);
    Font normalFont = new Font(Font.FontFamily.HELVETICA, 10, Font.ITALIC);
    PdfPTable table = new PdfPTable(new float[] { 1, 2, 2 });
    PdfPCell qestionCell;
    PdfPCell group1Cell;
    PdfPCell group2Cell;
    int i = 0;
    for (i = 0; i < maxRows; i++) {
        Log.d("Print Row " + i);
        if (i % 5 == 0) {
            if (i != 0) {
                document.add(table);
                document.newPage();
                document = printHead(writer, document, htmlString, out, image);
            } else {
                document = printHead(writer, document, htmlString, out, image);
            }

            table = new PdfPTable(new float[] { 1, 2, 2 });
            table.setWidthPercentage((float) 100.0);
            qestionCell = new PdfPCell(new Phrase("\nFragen", boldFont));
            group1Cell = new PdfPCell();
            group1Cell.addElement(new Phrase("Hauptgruppe:", boldFont));
            group1Cell.addElement(new Phrase(u1.getNAME() + "\n" + filter1, normalFont));
            group2Cell = new PdfPCell();
            group2Cell.addElement(new Phrase("Vergleichsgruppe:", boldFont));
            group2Cell.addElement(new Phrase(u2.getNAME() + "\n" + filter2, normalFont));
            qestionCell.setBorderWidth(2.0f);
            group1Cell.setBorderWidth(2.0f);
            group2Cell.setBorderWidth(2.0f);
            table.addCell(qestionCell);
            table.addCell(group1Cell);
            table.addCell(group2Cell);
        }
        String url1 = UmfrageUtil.getCharUrl(res1.get(i));
        Log.d("URL1=" + url1);
        Image image1 = Image.getInstance(url1);

        Image image2 = null;
        if (res2.size() > i) {
            String url2 = UmfrageUtil.getCharUrl(res2.get(i));
            Log.d("URL2=" + url2);
            image2 = Image.getInstance(url2);
        }
        Log.d("Write to pdf:" + res1.get(i).getFrage());
        qestionCell = new PdfPCell(new Phrase(res1.get(i).getFrage(), normalFont));
        qestionCell.setBorderWidth(1.0f);
        group1Cell = new PdfPCell(image1, true);
        group1Cell.setBorderWidth(1.0f);
        group1Cell.setPadding(10);
        if (image2 != null)
            group2Cell = new PdfPCell(image2, true);
        else
            group2Cell = new PdfPCell();
        group2Cell.setBorderWidth(1.0f);
        group2Cell.setPadding(10);

        table.addCell(qestionCell);
        table.addCell(group1Cell);
        table.addCell(group2Cell);
    }
    if (!(i % 5 == 0)) {
        document.add(table);
    }

    document.close();
    return document;
}

From source file:direccion.GeneradorFormato.java

@Override
public void onEndPage(PdfWriter writer, Document document) {

    Rectangle rect = writer.getBoxSize("art");
    Image imghead = null;/*from  w  w w .  jav  a 2  s . co m*/
    PdfContentByte cbhead = null;

    //        try {
    //            imghead = Image.getInstance("LogoSapito5.png");
    //            imghead.setAbsolutePosition(0, 0);
    //            imghead.setAlignment(Image.ALIGN_CENTER);
    //            imghead.scalePercent(10f);
    //            cbhead = writer.getDirectContent();
    //            PdfTemplate tp = cbhead.createTemplate(100, 150);
    //            tp.addImage(imghead);
    //            cbhead.addTemplate(tp, 100, 715);
    //        } catch (BadElementException e) {
    //            e.printStackTrace();
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        } catch (DocumentException e) {
    //            e.printStackTrace();
    //        }

    Phrase headPhraseImg = new Phrase(cbhead + "",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.NORMAL));

    Calendar c1 = Calendar.getInstance();
    Calendar c2 = new GregorianCalendar();
    String dia, mes, annio;
    dia = Integer.toString(c1.get(Calendar.DATE));
    mes = Integer.toString(c1.get(Calendar.MONTH));
    annio = Integer.toString(c1.get(Calendar.YEAR));
    Date fecha = new Date();
    String fechis = dia + "/" + mes + "/" + annio;

    Paragraph parrafo5 = new Paragraph(fechis,
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo5),
            rect.getRight(450), rect.getTop(-80), 0);

    Paragraph parrafo7 = new Paragraph("Empresa Sapito S.A. de C.V.",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo7),
            rect.getBottom(250), rect.getTop(-60), 0);

    Paragraph parrafo8 = new Paragraph("Reporte algoooooo",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo8),
            rect.getBottom(250), rect.getTop(-40), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase(
            "      _____________________________________________________________________________________    "),
            rect.getBorder(), rect.getTop(650), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase(
            "      _____________________________________________________________________________________    "),
            rect.getBorder(), rect.getTop(-24), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase(
            "      _____________________________________________________________________________________    "),
            rect.getBorder(), rect.getTop(-20), 0);

    Paragraph parrafo6 = new Paragraph(String.format("Pg %d", writer.getPageNumber()),
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo6),
            rect.getRight(-35), rect.getTop(-80), 0);
}