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

private Phrase(boolean dummy) 

Source Link

Document

Constructs a Phrase that can be used in the static getInstance() method.

Usage

From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java

License:Apache License

public void setFooterText(final String value) {
    if (value == null) {
        footerPhrase = null;/*www .  j a va2s .  c o  m*/
        return;
    }
    footerPhrase = new Phrase(new Chunk(value, FONT));
}

From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java

License:Apache License

private static Phrase createPageAction(final String caption, final int action) {
    return new Phrase(new Chunk(caption, AFONT).setAction(new PdfAction(action)));
}

From source file:optika.sql.java

public void eksportoNePdf(String id) {
    Document document = new Document() {
    };//from   ww  w .java2 s .c om
    try {
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("receta.pdf"));
        document.open();
        document.setPageSize(PageSize.A3);

        Image img = Image.getInstance("receta.jpg");
        img.setAbsolutePosition(450f, 10f);

        img.scaleToFit(600, 849);

        img.setAlignment(Image.LEFT | Image.ALIGN_BOTTOM | Image.ALIGN_BASELINE);
        img.setAbsolutePosition(0, 0);
        document.add(img);
        String[][] receta = merrReceten("select * from recetat where id=" + parseInt(id) + ";");
        String[][] tabela = merrReceten("select * from tabela where recetat_id=" + parseInt(id) + ";");
        int[] white = new int[tabela.length];
        for (int i = 0; i < tabela.length; i++) {
            white[i] = 0;
            int bosh = 0;
            for (int j = 3; j < tabela[i].length; j++) {
                if (tabela[i][j] == tabela[i][6]) {
                    continue;
                }

                if (!tabela[i][j].isEmpty()) {
                    bosh = 1;
                }

            }

            if (bosh == 0) {
                white[i] = 1;
            }
        }
        Paragraph data = new Paragraph("Data: " + receta[0][7]);
        data.setSpacingBefore(38);
        data.setSpacingAfter(40);
        PdfPTable table = new PdfPTable(7);
        if (white[0] == 0) {
            table.addCell(getCellPadding("" + tabela[0][3], 1));
        } else {
            table.addCell(getCellWhite("_", 1, 30));
        }
        table.addCell(getCellPadding("" + tabela[0][4], 1));
        table.addCell(getCellPadding("" + tabela[0][5], 1));
        table.addCell(getCellPadding("", 1));
        table.addCell(getCellPadding("" + tabela[0][7], 1));
        table.addCell(getCellPadding("" + tabela[0][8], 1));
        table.addCell(getCellPadding("" + tabela[0][9], 1));
        table.setWidthPercentage(105);
        table.setHorizontalAlignment(-100);

        if (white[1] == 0) {
            table.addCell(getCellPadding("" + tabela[1][3], 1));
        } else {

            table.addCell(getCellWhite("_", 1, 36));
        }
        table.addCell(getCellPadding("" + tabela[1][4], 1));
        table.addCell(getCellPadding("" + tabela[1][5], 1));
        table.addCell(getCellPadding("", 1));
        table.addCell(getCellPadding("" + tabela[1][7], 1));
        table.addCell(getCellPadding("" + tabela[1][8], 1));
        table.addCell(getCellPadding("" + tabela[1][9], 1));
        table.setWidthPercentage(105);
        table.setHorizontalAlignment(-100);

        if (white[2] == 0) {
            if (white[1] == 0) {
                table.addCell(getCell("" + tabela[2][3], 1, 30));

            } else {
                table.addCell(getCellWhite("_", 1, 23));
            }
        } else {

            table.addCell(getCellWhite("_", 1, 28));

        }
        table.addCell(getCell("" + tabela[2][4], 1, 0));
        table.addCell(getCell("" + tabela[2][5], 1, 0));
        table.addCell(getCell("", 1, 0));
        table.addCell(getCell("" + tabela[2][7], 1, 0));
        table.addCell(getCell("" + tabela[2][8], 1, 0));
        table.addCell(getCell("" + tabela[2][9], 1, 0));
        table.setWidthPercentage(105);
        table.setSpacingBefore(27);
        table.setHorizontalAlignment(-100);

        String[][] distanca = merrReceten("select * from distanca where recetat_id=" + parseInt(id) + ";");

        PdfPTable largAfer = new PdfPTable(3);

        if (distanca[0][3].isEmpty()) {
            PdfPCell larg = getCellWhite("_", 2, 15);
            largAfer.addCell(larg);
        } else {
            PdfPCell larg = new PdfPCell(new Phrase("" + distanca[0][3]));
            larg.setPadding(0);
            larg.setHorizontalAlignment(2);
            larg.setBorder(PdfPCell.NO_BORDER);
            larg.setPaddingBottom(20);
            largAfer.addCell(larg);
        }
        largAfer.addCell(getCell("", PdfPCell.ALIGN_RIGHT, 25));

        if (distanca[0][8].isEmpty()) {
            largAfer.addCell(getCellWhite("_", PdfPCell.ALIGN_RIGHT, 15));
        } else {
            largAfer.addCell(getCell("" + distanca[0][8], PdfPCell.ALIGN_RIGHT, 25));
        }
        largAfer.setWidthPercentage(75);
        largAfer.setHorizontalAlignment(350);

        PdfPTable od_os = new PdfPTable(5);
        od_os.addCell(getCell("OD= " + distanca[0][4], 0, 195));
        od_os.addCell(getCell("OS= " + distanca[0][5], 2, 195));
        od_os.addCell(getCell("", 0, 0));
        od_os.addCell(getCell("OD= " + distanca[0][9], 0, 0));
        od_os.addCell(getCell("OS= " + distanca[0][10], 1, 0));
        od_os.setWidthPercentage(90);
        od_os.setHorizontalAlignment(150);

        PdfPTable visusi = new PdfPTable(2);
        if (distanca[0][6].isEmpty()) {
            PdfPCell od_pa = getCellWhite("_", 2, 17);
            od_pa.setPaddingRight(45);
            visusi.addCell(od_pa);
        } else {
            PdfPCell od_pa = getCell(distanca[0][6], 2, 17);
            od_pa.setPaddingRight(45);
            visusi.addCell(od_pa);
        }

        if (distanca[0][11].isEmpty()) {
            visusi.addCell(getCellWhite("_", 2, 17));
        } else {
            visusi.addCell(getCell(distanca[0][11], 2, 17));
        }

        if (distanca[0][7].isEmpty()) {
            PdfPCell os_pa = getCellWhite("_", 2, 17);
            os_pa.setPaddingRight(45);
            visusi.addCell(os_pa);
        } else {
            PdfPCell os_pa = getCell(distanca[0][7], 2, 17);
            os_pa.setPaddingRight(45);
            visusi.addCell(os_pa);
        }

        if (distanca[0][12].isEmpty()) {
            visusi.addCell(getCellWhite("_", 2, 17));
        } else {
            visusi.addCell(getCell(distanca[0][12], 2, 0));
        }
        visusi.setWidthPercentage(100);
        visusi.setHorizontalAlignment(50);

        String[][] admin = merrReceten("select * from admin where id=1;");
        PdfPTable klienti = new PdfPTable(3);
        klienti.addCell(getCell("", 0, 0));
        klienti.addCell(getCell("", 0, 0));
        klienti.addCell(getCell("Emri: " + receta[0][2], 0, 0));

        klienti.addCell(getCell("Celular: " + admin[0][4], 0, 0));
        klienti.addCell(getCell("", 0, 0));
        PdfPCell celReceta = getCell("Celular: " + receta[0][4], 0, 0);
        celReceta.setPaddingTop(5);
        klienti.addCell(celReceta);

        klienti.addCell(getCell("Email: " + admin[0][5], 0, 0));
        klienti.addCell(getCell("", 0, 0));
        PdfPCell emailReceta = getCell("Email: " + receta[0][5], 0, 0);
        emailReceta.setPaddingBottom(5);
        emailReceta.setPaddingTop(5);
        klienti.addCell(emailReceta);

        klienti.addCell(getCell("Adresa: " + admin[0][6], 0, 0));
        klienti.addCell(getCell("", 0, 0));
        klienti.addCell(getCell("Adresa: " + receta[0][6], 0, 0));
        klienti.setSpacingBefore(50);

        PdfPTable kreu = new PdfPTable(1);
        kreu.addCell(getCell(" ", 0, 0));

        document.add(kreu);
        document.add(klienti);
        document.add(data);
        document.add(table);
        document.add(largAfer);
        document.add(od_os);
        document.add(visusi);

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();

}

From source file:optika.sql.java

public PdfPCell getCellPadding(String text, int alignment) {
    PdfPCell cell = new PdfPCell(new Phrase(text));
    cell.setPadding(0);//from  w  ww . j a va  2 s  .  c om
    cell.setHorizontalAlignment(alignment);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingBottom(36);
    return cell;
}

From source file:optika.sql.java

public PdfPCell getCell(String text, int alignment, int bottom) {
    PdfPCell cell = new PdfPCell(new Phrase(text));
    cell.setPadding(0);/*from w ww  . j a v  a 2 s  . c  om*/
    cell.setHorizontalAlignment(alignment);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setPaddingBottom(bottom);
    return cell;
}

From source file:org.areasy.common.doclet.document.Destinations.java

License:Open Source License

/**
 * Creates a destination in the document. This method
 * does nothing if the given destination is invalid.
 * <p/>//from w ww. ja  v  a 2 s .  c  o  m
 * This method creates a phrase with one or two empty chunks
 * who only serve as holders for the destinations.
 *
 * @param label The label for the destination.
 * @param doc   The javadoc element for which to create a destination.
 * @param font  The font for the label.
 * @return The Phrase with the destination in it.
 */
public static Phrase createDestination(String label, ProgramElementDoc doc, Font font) {
    boolean multiPart = false;
    Chunk chunk = null;
    boolean canHaveParms = false;

    if (doc instanceof ConstructorDoc || doc instanceof MethodDoc)
        canHaveParms = true;

    if (canHaveParms)
        multiPart = true;

    chunk = new Chunk(label, font);
    Phrase phrase = new Phrase(chunk);

    String destination = doc.qualifiedName();
    phrase.add(PDFUtility.createAnchor(destination));

    if (multiPart) {
        ExecutableMemberDoc execDoc = (ExecutableMemberDoc) doc;
        String destinationTwo = destination + "()";
        phrase.add(PDFUtility.createAnchor(destinationTwo));

        String destinationThree = destination + execDoc.signature();
        phrase.add(PDFUtility.createAnchor(destinationThree));

        String destinationFour = destination + execDoc.flatSignature();
        phrase.add(PDFUtility.createAnchor(destinationFour));
    }

    return phrase;
}

From source file:org.areasy.common.doclet.document.Implementors.java

License:Open Source License

/**
 * Prints all known subclasses or implementing classes.
 *
 * @param title The label for the name list
 * @param names The names (classes or interfaces)
 * @throws Exception//  w  w w .  j ava 2 s  .  com
 */
public static void print(String title, String[] names) throws Exception {
    float[] widths = { (float) 6.0, (float) 94.0 };
    PdfPTable table = new PdfPTable(widths);
    table.setWidthPercentage((float) 100);

    PdfPCell spacingCell = new CellNoBorderNoPadding(new Phrase(""));
    spacingCell.setFixedHeight((float) 12.0);
    spacingCell.setColspan(2);
    table.addCell(spacingCell);

    PdfPCell titleCell = new CellNoBorderNoPadding(
            new Paragraph((float) 20.0, title, Fonts.getFont(TEXT_FONT, BOLD, 10)));
    titleCell.setColspan(2);
    table.addCell(titleCell);

    PdfPCell leftCell = PDFUtility.createElementCell(5, new Phrase(""));
    Paragraph descPg = new Paragraph((float) 24.0);

    for (int i = names.length - 1; i > -1; i--) {
        String subclassName = DocletUtility.getQualifiedNameIfNecessary(names[i]);
        Phrase subclassPhrase = new LinkPhrase(names[i], subclassName, 10, true);
        descPg.add(subclassPhrase);

        if (i > 0)
            descPg.add(new Chunk(", ", Fonts.getFont(TEXT_FONT, BOLD, 12)));
    }

    table.addCell(leftCell);
    table.addCell(new CellNoBorderNoPadding(descPg));

    table.addCell(spacingCell);
    Document.instance().add(table);
}

From source file:org.areasy.common.doclet.document.Summary.java

License:Open Source License

/**
 * Prints field summaries.//  w w  w . ja v a2  s.co  m
 * @param constantValue
 * @param isDeprecated
 * @param deprecatedPhrase
 * @param mainTable
 * @throws Exception
 */
private static void printField(FieldDoc fieldDoc, Object constantValue, boolean isDeprecated,
        Phrase deprecatedPhrase, PdfPTable mainTable) throws Exception {

    String name = fieldDoc.name();
    String modifier = fieldDoc.modifiers();
    String commentText = DocletUtility.getFirstSentence(fieldDoc);
    String destination = fieldDoc.qualifiedName();

    Element[] objs = HtmlParserWrapper.createPdfObjects(commentText);

    PdfPTable commentsTable = createColumnsAndDeprecated(objs, isDeprecated, deprecatedPhrase);

    if (constantValue != null) {
        // Add 2nd comment line (left cell empty, right cell text)
        commentsTable.addCell(new Phrase(""));
        Chunk valueTextChunk = new Chunk("Value: ", Fonts.getFont(TEXT_FONT, PLAIN, 10));
        Chunk valueContentChunk = new Chunk(constantValue.toString(), Fonts.getFont(CODE_FONT, BOLD, 10));
        Phrase constantValuePhrase = new Phrase("");
        constantValuePhrase.add(valueTextChunk);
        constantValuePhrase.add(valueContentChunk);
        commentsTable.addCell(constantValuePhrase);
    }

    PdfPTable anotherinnertable = new PdfPTable(1);
    anotherinnertable.setWidthPercentage(100f);
    anotherinnertable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    PdfPTable innerTable = addDeclaration(modifier, null);

    // Link to field
    LinkPhrase linkPhrase = new LinkPhrase(destination, name, Fonts.getFont(CODE_FONT, 9));

    // right part of the table
    PdfPCell cell = PDFUtility.createElementCell(2, linkPhrase);
    cell.setPaddingTop((float) 2.0);
    cell.setPaddingLeft((float) 7.0);
    anotherinnertable.addCell(cell);
    anotherinnertable.addCell(commentsTable);

    innerTable.addCell(anotherinnertable);
    mainTable.addCell(innerTable);
}

From source file:org.areasy.common.doclet.document.Summary.java

License:Open Source License

/**
 * Creates the two columns for the summary table and, if necessary,
 * fills in the "Deprecated" text. Otherwise, the given elements
 * are filled in.//from   w ww .  j a  va 2 s  .  c om
 *
 * @param objs             The description elements.
 * @param isDeprecated     If true, the whole class/method is deprecated.
 * @param deprecatedPhrase The phrase for the deprecated text.
 * @return The summary table columns.
 * @throws DocumentException If something failed.
 */
private static PdfPTable createColumnsAndDeprecated(Element[] objs, boolean isDeprecated,
        Phrase deprecatedPhrase) throws DocumentException {

    PdfPTable commentsTable = null;
    commentsTable = new PdfPTable(2);
    commentsTable.setWidths(new int[] { 5, 95 });
    commentsTable.setWidthPercentage(100f);
    commentsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    commentsTable.addCell(new Phrase(""));

    Phrase descPhr = new Phrase();

    CellNoBorderNoPadding cell = new CellNoBorderNoPadding(descPhr);

    commentsTable.addCell(cell);

    if (isDeprecated) {
        // if the method is deprecated...
        // do not print the comment text...
        // just print the deprecated text
        descPhr.add(new Phrase(AbstractConfiguration.LB_DEPRECATED_TAG, Fonts.getFont(TEXT_FONT, BOLD, 10)));
        descPhr.add(deprecatedPhrase);
    } else if (objs.length != 0) {
        for (int i = 0; i < objs.length; i++) {
            if (objs[i] instanceof List) {
                cell.addElement(objs[i]);
                descPhr = new Phrase("");
                cell.addElement(descPhr);
            } else {
                descPhr.add(objs[i]);
            }
        }
    }

    return commentsTable;
}

From source file:org.areasy.common.doclet.document.tags.TagA.java

License:Open Source License

public Element[] openTagElements() {
    String addr = getAttribute("href");
    String name = getAttribute("name");

    if (addr != null && addr.equalsIgnoreCase("newpage")) {
        Chunk anchor = new Chunk("");
        anchor.setNewPage();//ww  w .j  a v a 2  s  . co  m

        return new Element[] { anchor };
    } else if (name != null && name.equalsIgnoreCase("bookmark")) {
        String label = getAttribute("label");

        String destinationName = null;
        if (HtmlParserWrapper.getRootBookmarkEntry() != null) {
            String target = getAttribute("target");
            destinationName = HtmlParserWrapper.getRootBookmarkEntry().addBookmarkEntry(target, label);
        } else {
            destinationName = Destinations.createAnchorDestination(State.getCurrentFile(), label);
            Bookmarks.addRootBookmark(label, destinationName);
        }

        Chunk anchor = PDFUtility.createAnchor(destinationName);

        return new Element[] { anchor };
    } else if (name != null && name.length() > 0) {
        String dest = Destinations.createAnchorDestination(State.getCurrentFile(), name);

        setLink(false);
        Phrase anchor = new Phrase(PDFUtility.createAnchor(dest, getFont()));

        return new Element[] { anchor };
    }

    return null;
}