Example usage for com.lowagie.text.pdf PdfPTable setWidthPercentage

List of usage examples for com.lowagie.text.pdf PdfPTable setWidthPercentage

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable setWidthPercentage.

Prototype

public void setWidthPercentage(float widthPercentage) 

Source Link

Document

Sets the width percentage that the table will occupy in the page.

Usage

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

License:Open Source License

/**
 * Prints inner classes summaries./* w w  w  .  jav a  2s  . co m*/
 *
 * @param name
 * @param destination
 * @param isDeprecated
 * @param deprecatedPhrase
 * @param mainTable
 * @throws Exception
 */
private static void printInnerClass(String name, String destination, boolean isDeprecated,
        Phrase deprecatedPhrase, PdfPTable mainTable) throws Exception {

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

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

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

    PdfPTable innerTable = addDeclaration("class", null);

    // right part of the table
    PdfPCell cell = PDFUtility.createElementCell(2,
            new LinkPhrase(destination, name, Fonts.getFont(CODE_FONT, 9)));
    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

/**
 * Prints field summaries./* ww  w.  j  av  a2 s.  com*/
 * @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

/**
 * Prints constructor summaries.//  www.j a v a 2  s  .c  o m
 * @param isDeprecated
 * @param deprecatedPhrase
 * @param mainTable
 * @throws Exception
 */
private static void printConstructor(ConstructorDoc constructorDoc, boolean isDeprecated,
        Phrase deprecatedPhrase, PdfPTable mainTable) throws Exception {

    String name = constructorDoc.name();
    String modifier = constructorDoc.modifiers();
    String commentText = DocletUtility.getFirstSentence(constructorDoc);
    String destination = constructorDoc.qualifiedName() + constructorDoc.signature();
    Parameter[] parms = constructorDoc.parameters();

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

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

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

    // Link to constructor
    Font constructorFont = Fonts.getFont(CODE_FONT, 9);
    Phrase phrase = new Phrase("", constructorFont);
    phrase.add(new LinkPhrase(destination, name, constructorFont));

    phrase.add("(");
    if ((parms != null) && (parms.length > 0)) {
        for (int i = 0; i < parms.length; i++) {
            phrase.add(PDFUtility.getParameterTypePhrase(parms[i], 9));
            phrase.add(" ");
            phrase.add(parms[i].name());
            if (i != (parms.length - 1)) {
                phrase.add(", ");
            }
        }
    }
    phrase.add(")");

    PdfPCell cell = PDFUtility.createElementCell(2, phrase);
    cell.setPaddingLeft((float) 7.0);
    anotherinnertable.addCell(cell);
    anotherinnertable.addCell(commentsTable);

    PdfPTable innerTable = addDeclaration(modifier, null);
    innerTable.addCell(anotherinnertable);

    mainTable.addCell(innerTable);
}

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

License:Open Source License

/**
 * Prints the summary tables for a method.
 * @param modifier//from  w ww.  j a  v  a 2 s . c om
 * @param returnType
 * @param isDeprecated
 * @param deprecatedPhrase
 * @param mainTable
 * @throws Exception
 */
private static void printMethod(MethodDoc methodDoc, String modifier, Phrase returnType, boolean isDeprecated,
        Phrase deprecatedPhrase, PdfPTable mainTable) throws Exception {

    String name = methodDoc.name();
    String destination = methodDoc.qualifiedName() + methodDoc.signature();
    String commentText = DocletUtility.getFirstSentence(methodDoc);
    Parameter[] parms = methodDoc.parameters();

    // Create inner table for both columns (left column already filled in)
    PdfPTable rowTable = addDeclaration(modifier, returnType);

    // Inner table with 1st sentence of javadoc of this method.
    // We use a table in order to be able to create two cells
    // in it (1st an empty one for intendation)

    Element[] objs = HtmlParserWrapper.createPdfObjects(commentText);
    // Phrase descPhr = new Phrase();

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

    // Table with 1 column and 2 rows (row 1 is parameters etc.,
    // row 2 is the description
    PdfPTable rightColumnInnerTable = new PdfPTable(1);

    rightColumnInnerTable.setWidthPercentage(100f);
    rightColumnInnerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    // Link to method
    Font methodFont = Fonts.getFont(CODE_FONT, 9);
    Phrase phrase = new Phrase("", methodFont);
    phrase.add(new LinkPhrase(destination, name, methodFont));
    phrase.add("(");
    if ((parms != null) && (parms.length > 0)) {
        for (int i = 0; i < parms.length; i++) {
            phrase.add(PDFUtility.getParameterTypePhrase(parms[i], 9));
            phrase.add(" ");
            phrase.add(parms[i].name());
            if (i != (parms.length - 1)) {
                phrase.add(", ");
            }
        }
    }
    phrase.add(")");

    PdfPCell cell = PDFUtility.createElementCell(2, phrase);
    cell.setPaddingLeft((float) 7.0);
    rightColumnInnerTable.addCell(cell);
    rightColumnInnerTable.addCell(commentsTable);

    // Now fill in right column as well
    rowTable.addCell(rightColumnInnerTable);

    // And add inner table to main summary table as a new row
    mainTable.addCell(rowTable);
}

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

License:Open Source License

/**
 * Creates the inner table for both columns. The left column
 * already contains the declaration text part.
 *
 * @param text       The text (like "static final"..)
 *///w w  w  . j  a  va 2  s  .  c  o  m
private static PdfPTable addDeclaration(String text, Phrase returnType) throws DocumentException {
    PdfPTable innerTable = new PdfPTable(2);
    innerTable.setWidthPercentage(100f);
    innerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    innerTable.setWidths(new int[] { 24, 76 });
    Paragraph declarationParagraph = new Paragraph((float) 9.0);
    Chunk leftPart = new Chunk(text, Fonts.getFont(CODE_FONT, 9));
    declarationParagraph.add(leftPart);
    if (returnType != null) {
        declarationParagraph.add(returnType);
        declarationParagraph.add(new Chunk(" ", Fonts.getFont(CODE_FONT, 9)));
    }
    PdfPCell cell = new CustomPdfPCell(Rectangle.RIGHT, declarationParagraph, 1, Color.gray);
    cell.setPaddingTop((float) 4.0);
    cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);

    innerTable.addCell(cell);
    return 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 .  jav a  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.TagLists.java

License:Open Source License

/**
 * Prints tags of a class member (method, field).
 *
 * @param title    The bold face title text for the tag (like "Parameters:")
 * @param tags     The list of tags to be printed.
 * @param compress If true, the text of all the given tags will be concatenated
 *                 into one, comma separated. This is used for the author tag,
 *                 for example, where several separate author tags should be
 *                 printed as one only.//from w  w w  . j a va 2  s. co  m
 * @param isMember If true, the whole tag paragraph is printed with additional
 *                 intendation (because it's a tag of a method, like the
 *                 "Parameters:" tag).
 * @throws Exception
 */
private static void printTags(String title, Tag[] tags, boolean compress, boolean isMember) throws Exception {
    if ((tags != null) && (tags.length > 0)) {
        float[] widthsMember = { (float) 6.0, (float) 4.0, (float) 94.0 };
        float[] widthsClass = { (float) 6.0, (float) 94.0 };

        PdfPTable table = null;
        if (isMember) {
            table = new PdfPTable(widthsMember);
        } else {
            table = new PdfPTable(widthsClass);
        }
        table.setWidthPercentage((float) 100);

        Paragraph empty = new Paragraph(" ");

        // Add empty line after the title ("Parameters:" etc.)
        if (isMember) {
            table.addCell(new CellNoBorderNoPadding(empty));
            table.addCell(new CellNoBorderNoPadding(empty));
            table.addCell(new CellNoBorderNoPadding(empty));
        }

        PdfPCell titleCell = new CellNoBorderNoPadding(
                new Paragraph((float) 24.0, title, Fonts.getFont(TEXT_FONT, BOLD, 10)));
        titleCell.setColspan(2);
        if (isMember) {
            table.addCell(new CellNoBorderNoPadding(empty)); // indentation
            // column
        }
        table.addCell(titleCell);

        int number = tags.length;
        String tagText = "";
        if (compress) {
            number = 1;
            for (int i = 0; i < tags.length; i++) {
                tagText = tagText + getTagText(tags[i]);
                if (i < tags.length - 1) {
                    tagText = tagText + ", ";
                }
            }
        }

        for (int i = 0; i < number; i++) {

            // indentation columns
            if (isMember) {
                table.addCell(new CellNoBorderNoPadding(empty));
                table.addCell(new CellNoBorderNoPadding(empty));
            } else {
                table.addCell(new CellNoBorderNoPadding(empty));
            }

            if (!compress) {
                tagText = getTagText(tags[i]);
            }

            Element[] elements = HtmlParserWrapper.createPdfObjects(tagText);
            table.addCell(PDFUtility.createElementCell(0, Element.ALIGN_LEFT, elements));
        }

        // Add whole method block to document
        Document.instance().add(table);
    }
}

From source file:org.caisi.tickler.web.TicklerPrinter.java

License:Open Source License

public void printTicklerInfo() throws DocumentException {

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(50f);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    addStandardTableEntry(table, "Created By", tickler.getProvider().getFormattedName());
    addStandardTableEntry(table, "Last Updated", formatter.format(tickler.getUpdateDate()));
    addStandardTableEntry(table, "Service Date", formatter.format(tickler.getServiceDate()));
    addStandardTableEntry(table, "Assigned To", tickler.getAssignee().getFormattedName());
    addStandardTableEntry(table, "Priority", tickler.getPriority().toString());
    addStandardTableEntry(table, "Status", tickler.getStatusWeb());
    addStandardTableEntry(table, "Program",
            (tickler.getProgram() != null) ? tickler.getProgram().getName() : "N/A");

    getDocument().add(table);//from w w w. j ava2 s.  co m

    table = new PdfPTable(1);
    table.setWidthPercentage(70f);

    PdfPCell cell1 = new PdfPCell(getParagraph("Message"));

    cell1.setBorder(PdfPCell.NO_BORDER);
    cell1.setHorizontalAlignment(Element.ALIGN_LEFT);

    table.addCell(cell1);

    cell1 = new PdfPCell(getParagraph(tickler.getMessage()));
    cell1.setHorizontalAlignment(Element.ALIGN_LEFT);

    table.addCell(cell1);

    getDocument().add(table);

}

From source file:org.cocktail.superplan.server.gestionimpression.TabularEdtReport.java

License:CeCILL license

public NSData genererPdf(NSArray creneaux, NSTimestamp debutSemaine, String semaine, String libelleFormation)
        throws DocumentException {

    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Document document = new Document();
    PdfWriter.getInstance(document, os);
    document.open();//from  ww  w  . ja  va2  s. com
    document.setMargins(0, 0, 0, 0);

    Font font = new Font(Font.TIMES_ROMAN, 12, Font.BOLD, Color.DARK_GRAY);

    PdfPTable headerTable = new PdfPTable(1);

    PdfPCell cell = new PdfPCell();
    Phrase ph = new Phrase();
    ph.add(new Chunk(libelleFormation, font));
    cell.setPhrase(ph);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerTable.addCell(cell);

    font = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL, Color.DARK_GRAY);
    cell = new PdfPCell();
    ph = new Phrase();
    ph.add(new Chunk(semaine, font));
    cell.setPhrase(ph);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerTable.addCell(cell);

    headerTable.setWidthPercentage(100);
    headerTable.setSpacingAfter(5.0f);

    document.add(headerTable);

    PdfPTable pdfTable = creerCreneauxTable(creneaux, debutSemaine);

    pdfTable.setWidthPercentage(100);

    document.add(pdfTable);
    document.close();
    return new NSData(os.toByteArray());
}

From source file:org.egov.works.web.actions.contractorBill.ContractorBillPDFGenerator.java

License:Open Source License

public void generatePDF() throws ApplicationException {
    logger.debug("FA1---inside generate pdf ");
    generateDisplayData(mbHeader, egBillRegister);
    try {/*from   w  w w. j a  v a2  s  .c  o  m*/
        // start header Part
        final PdfPTable contractorBillMainTable = new PdfPTable(11);
        contractorBillMainTable.setWidthPercentage(100);
        contractorBillMainTable
                .setWidths(new float[] { 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f, 1.5f });
        contractorBillMainTable.getDefaultCell().setPadding(4);
        contractorBillMainTable.getDefaultCell().setBorderWidth(1);
        createHeaderRow(contractorBillMainTable);
        createDetailsRows(contractorBillMainTable);
        document.add(contractorBillMainTable);
        document.add(spacer());

        // ---approval details for workflow
        final PdfPTable approvaldetailsTable = createApprovalDetailsTable(egBillRegister);

        if (approvaldetailsTable.getRows().size() != 1) {
            document.add(makePara("Approval Details"));
            document.add(spacer());
            document.add(approvaldetailsTable);
            document.add(spacer());
        }
        if (contractorBillMainTable.getRows().size() > 11)
            document.newPage();
        createFooter();
        // create certificate page
        document.newPage();
        createCertificate();
        document.close();
    } catch (final DocumentException e) {
        throw new ApplicationRuntimeException(CONTRACTOR_PDF_ERROR, e);
    }
}