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.goodoldai.jeff.report.pdf.PDFDataChunkBuilder.java

License:Open Source License

/**
 * This is a private method that is used to insert single data content into
 * the PDF document.// w ww  .java2 s .c  om
 *
 * @param data single data which needs to be transformed
 * @param document PDF document in which the transformed data will be
 * written
 */
private void inputSingleDataContent(SingleData data, Document document) {
    String value = String.valueOf(data.getValue());

    //Create table with only one column and set some formatting options
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(30);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.setSpacingBefore(15.0F);
    table.setSpacingAfter(15.0F);

    //Create the header cell
    PdfPCell cell1 = new PdfPCell(new Paragraph(turnDimensionIntoHeader(data.getDimension())));
    cell1.setBackgroundColor(Color.lightGray);

    //Create a single data cell
    PdfPCell cell2 = new PdfPCell(new Paragraph(value));

    //Insert cells into table
    table.addCell(cell1);
    table.addCell(cell2);

    try {
        document.add(table);
    } catch (DocumentException ex) {
        throw new ExplanationException(ex.getMessage());
    }

}

From source file:org.goodoldai.jeff.report.pdf.PDFDataChunkBuilder.java

License:Open Source License

/**
 * This is a private method that is used to insert one dimensional data 
 * content into the PDF document./*w w w  .  j  a  v a  2  s .  c  om*/
 *
 * @param data one dimensional data which needs to be transformed
 * @param document PDF document in which the transformed data will be
 * written
 */
private void inputOneDimDataContent(OneDimData data, Document document) {

    //Create table with only one column and set some formatting options
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(30);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.setSpacingBefore(15.0F);
    table.setSpacingAfter(15.0F);

    //Create the header cell
    PdfPCell cell1 = new PdfPCell(new Paragraph(turnDimensionIntoHeader(data.getDimension())));
    cell1.setBackgroundColor(Color.lightGray);
    table.addCell(cell1);

    //Create and insert data cells
    ArrayList<Object> values = data.getValues();

    for (int i = 0; i < values.size(); i++) {
        table.addCell(new Paragraph(transformValue(values.get(i))));
    }

    try {
        document.add(table);
    } catch (DocumentException ex) {
        throw new ExplanationException(ex.getMessage());
    }

}

From source file:org.goodoldai.jeff.report.pdf.PDFDataChunkBuilder.java

License:Open Source License

/**
 * This is a private method that is used to insert two dimensional data
 * content into the PDF document.//from  w  ww  . java  2  s .  c  o m
 *
 * @param data two dimensional data which needs to be transformed
 * @param document PDF document in which the transformed data will be
 * written
 */
private void inputTwoDimDataContent(TwoDimData data, Document document) {

    //Create table with two columns and set some formatting options
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(50);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.setSpacingBefore(15.0F);
    table.setSpacingAfter(15.0F);

    //Create the header cells
    PdfPCell cell1 = new PdfPCell(new Paragraph(turnDimensionIntoHeader(data.getDimension1())));
    cell1.setBackgroundColor(Color.lightGray);
    table.addCell(cell1);

    PdfPCell cell2 = new PdfPCell(new Paragraph(turnDimensionIntoHeader(data.getDimension2())));
    cell2.setBackgroundColor(Color.lightGray);
    table.addCell(cell2);

    //Create and insert data cells
    ArrayList<Tuple> values = data.getValues();

    for (int i = 0; i < values.size(); i++) {
        Tuple tuple = (Tuple) (values.get(i));
        table.addCell(new Paragraph(transformValue(tuple.getValue1())));
        table.addCell(new Paragraph(transformValue(tuple.getValue2())));
    }

    try {
        document.add(table);
    } catch (DocumentException ex) {
        throw new ExplanationException(ex.getMessage());
    }

}

From source file:org.goodoldai.jeff.report.pdf.PDFDataChunkBuilder.java

License:Open Source License

/**
 * This is a private method that is used to insert three dimensional data
 * content into the PDF document./*from   w w w .  j a  v  a  2 s .  co  m*/
 *
 * @param data three dimensional data which needs to be transformed
 * @param document PDF document in which the transformed data will be
 * written
 */
private void inputThreeDimDataContent(ThreeDimData data, Document document) {

    //Create table with three columns and set some formatting options
    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(80);
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    table.setSpacingBefore(15.0F);
    table.setSpacingAfter(15.0F);

    //Create the header cells
    PdfPCell cell1 = new PdfPCell(new Paragraph(turnDimensionIntoHeader(data.getDimension1())));
    cell1.setBackgroundColor(Color.lightGray);
    table.addCell(cell1);

    PdfPCell cell2 = new PdfPCell(new Paragraph(turnDimensionIntoHeader(data.getDimension2())));
    cell2.setBackgroundColor(Color.lightGray);
    table.addCell(cell2);

    PdfPCell cell3 = new PdfPCell(new Paragraph(turnDimensionIntoHeader(data.getDimension3())));
    cell3.setBackgroundColor(Color.lightGray);
    table.addCell(cell3);

    //Create and insert data cells
    ArrayList<Triple> values = data.getValues();

    for (int i = 0; i < values.size(); i++) {
        Triple triple = (Triple) (values.get(i));
        table.addCell(new Paragraph(transformValue(triple.getValue1())));
        table.addCell(new Paragraph(transformValue(triple.getValue2())));
        table.addCell(new Paragraph(transformValue(triple.getValue3())));
    }

    try {
        document.add(table);
    } catch (DocumentException ex) {
        throw new ExplanationException(ex.getMessage());
    }

}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

@Override
public void export(GTDModel model, ActionsCollection collection, OutputStream out,
        ExportAddOn.ExportOrder order, FileFilter ff, boolean compact) throws Exception {

    fontSelector = new FontSelector();
    fontSelectorB = new FontSelector();
    fontSelectorB2 = new FontSelector();
    fontSelectorB4 = new FontSelector();

    baseFont = fontModel.getBaseFont();/* w  ww .  ja v  a  2s .c o  m*/

    for (BaseFont bf : fontModel.getFonts()) {
        fontSelector.addFont(new Font(bf, baseFontSize));
        fontSelectorB.addFont(new Font(bf, baseFontSize, Font.BOLD));
        fontSelectorB2.addFont(new Font(bf, baseFontSize + 2, Font.BOLD));
        fontSelectorB4.addFont(new Font(bf, baseFontSize + 4, Font.BOLD));
    }

    boolean emptyH2 = false;
    boolean emptyH3 = false;

    PdfPTable actionTable = null;

    Document doc = new Document();

    if (sizeSet) {
        doc.setPageSize(pageSize);
    }
    if (marginSet) {
        doc.setMargins(marginLeft, marginRight, marginTop, marginBottom);
    }

    //System.out.println("PDF size "+doc.getPageSize().toString());
    //System.out.println("PDF m "+marginLeft+" "+marginRight+" "+marginTop+" "+marginBottom);

    @SuppressWarnings("unused")
    PdfWriter pw = PdfWriter.getInstance(doc, out);

    doc.addCreationDate();
    doc.addTitle("GTD-Free PDF");
    doc.addSubject("GTD-Free data exported as PDF");

    HeaderFooter footer = new HeaderFooter(newParagraph(), true);
    footer.setAlignment(HeaderFooter.ALIGN_CENTER);
    footer.setBorder(HeaderFooter.TOP);
    doc.setFooter(footer);

    doc.open();

    Phrase ch = newTitle("GTD-Free Data");
    Paragraph p = new Paragraph(ch);
    p.setAlignment(Paragraph.ALIGN_CENTER);

    PdfPTable t = new PdfPTable(1);
    t.setWidthPercentage(100f);
    PdfPCell c = newCell(p);
    c.setBorder(Table.BOTTOM);
    c.setBorderWidth(2.5f);
    c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    c.setPadding(5f);
    t.addCell(c);
    doc.add(t);

    Iterator<Object> it = collection.iterator(order);

    while (it.hasNext()) {
        Object o = it.next();

        if (o == ActionsCollection.ACTIONS_WITHOUT_PROJECT) {

            if (order == ExportAddOn.ExportOrder.FoldersProjectsActions) {

                doc.add(newSubSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT));

                emptyH2 = false;
                emptyH3 = true;
            } else {

                doc.add(newSection(ActionsCollection.ACTIONS_WITHOUT_PROJECT));

                emptyH2 = true;
                emptyH3 = false;
            }

            continue;
        }

        if (o instanceof Folder) {

            Folder f = (Folder) o;

            if (actionTable != null) {
                doc.add(actionTable);
                actionTable = null;
            }

            if (f.isProject()) {

                if (order == ExportAddOn.ExportOrder.ProjectsActions
                        || order == ExportAddOn.ExportOrder.ProjectsFoldersActions) {

                    if (emptyH2 || emptyH3) {
                        p = newParagraph(NONE_DOT);
                        doc.add(p);
                    }

                    doc.add(newSection(f.getName()));

                    if (compact) {
                        if (f.getDescription() != null && f.getDescription().length() > 0) {
                            p = newParagraph(f.getDescription());
                            p.setIndentationLeft(10f);
                            p.setIndentationRight(10f);
                            doc.add(p);
                        }
                    } else {
                        t = new PdfPTable(2);
                        t.setKeepTogether(true);
                        t.setSpacingBefore(5f);
                        t.setWidthPercentage(66f);
                        t.setWidths(new float[] { 0.33f, 0.66f });

                        c = newCell("ID");
                        t.addCell(c);
                        c = newCell(newStrongParagraph(String.valueOf(f.getId())));
                        t.addCell(c);
                        c = newCell("Type");
                        t.addCell(c);
                        c = newCell(newStrongParagraph("Project"));
                        t.addCell(c);
                        c = newCell("Open");
                        t.addCell(c);
                        c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount())));
                        t.addCell(c);
                        c = newCell("All");
                        t.addCell(c);
                        c = newCell(newStrongParagraph(String.valueOf(f.size())));
                        t.addCell(c);
                        c = newCell("Description");
                        t.addCell(c);
                        c = newDescriptionCell(f.getDescription());
                        t.addCell(c);

                        doc.add(t);
                    }

                    emptyH2 = true;
                    emptyH3 = false;

                } else {

                    if (emptyH3) {
                        p = newParagraph(NONE_DOT);
                        doc.add(p);
                    }

                    doc.add(newSubSection("Project:" + " " + f.getName()));

                    emptyH2 = false;
                    emptyH3 = true;
                }

                continue;

            }
            if (order == ExportAddOn.ExportOrder.FoldersActions
                    || order == ExportAddOn.ExportOrder.FoldersProjectsActions) {

                if (emptyH2 || emptyH3) {
                    p = newParagraph(NONE_DOT);
                    doc.add(p);
                }

                doc.add(newSection(f.getName()));

                if (compact) {
                    if (f.getDescription() != null && f.getDescription().length() > 0) {
                        p = newParagraph(f.getDescription());
                        p.setIndentationLeft(10f);
                        p.setIndentationRight(10f);
                        doc.add(p);
                    }
                } else {

                    t = new PdfPTable(2);
                    t.setKeepTogether(true);
                    t.setSpacingBefore(5f);
                    t.setWidthPercentage(66f);
                    t.setWidths(new float[] { 0.33f, 0.66f });

                    c = newCell("ID");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(String.valueOf(f.getId())));
                    t.addCell(c);

                    String type = "";
                    if (f.isAction()) {
                        type = "Action list";
                    } else if (f.isInBucket()) {
                        type = "In-Bucket";
                    } else if (f.isQueue()) {
                        type = "Next action queue";
                    } else if (f.isReference()) {
                        type = "Reference list";
                    } else if (f.isSomeday()) {
                        type = "Someday/Maybe list";
                    } else if (f.isBuildIn()) {
                        type = "Default list";
                    }

                    c = newCell("Type");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(type));
                    t.addCell(c);
                    c = newCell("Open");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(String.valueOf(f.getOpenCount())));
                    t.addCell(c);
                    c = newCell("All");
                    t.addCell(c);
                    c = newCell(newStrongParagraph(String.valueOf(f.size())));
                    t.addCell(c);
                    c = newCell("Description");
                    t.addCell(c);
                    c = newDescriptionCell(f.getDescription());
                    t.addCell(c);

                    doc.add(t);
                }

                emptyH2 = true;
                emptyH3 = false;

            } else {

                if (emptyH3) {
                    p = newParagraph(NONE_DOT);
                    doc.add(p);
                }

                doc.add(newSubSection("List:" + " " + f.getName()));

                emptyH2 = false;
                emptyH3 = true;

            }

            continue;

        }

        if (o instanceof Action) {
            emptyH2 = false;
            emptyH3 = false;

            Action a = (Action) o;

            if (compact) {

                if (actionTable == null) {
                    actionTable = new PdfPTable(5);
                    actionTable.setWidthPercentage(100f);
                    actionTable.setHeaderRows(1);
                    actionTable.setSpacingBefore(5f);
                    c = newHeaderCell("ID");
                    actionTable.addCell(c);
                    c = newHeaderCell("Pri.");
                    actionTable.addCell(c);
                    c = newHeaderCell("Description");
                    actionTable.addCell(c);
                    c = newHeaderCell("Reminder");
                    actionTable.addCell(c);
                    c = newHeaderCell(CHECK_RESOLVED);
                    actionTable.addCell(c);

                    float width = doc.getPageSize().getWidth() - doc.getPageSize().getBorderWidthLeft()
                            - doc.getPageSize().getBorderWidthRight();
                    int i = model.getLastActionID();
                    float step = baseFontSize - 1;
                    int steps = (int) Math.floor(Math.log10(i)) + 1;
                    // ID column
                    float col1 = 8 + steps * step;
                    // Priority column
                    float col2 = 4 + 3 * (baseFontSize + 4);
                    // Reminder column
                    float col4 = 10 + step * 11;
                    // Resolved column
                    float col5 = 8 + baseFontSize;
                    // Description column
                    float col3 = width - col1 - col2 - col4 - col5;
                    actionTable.setWidths(new float[] { col1, col2, col3, col4, col5 });

                }

                addSingleActionRow(a, actionTable);

            } else {
                addSingleActionTable(model, doc, a);
            }
        }

    }

    if (actionTable != null) {
        doc.add(actionTable);
        actionTable = null;
    }
    if (emptyH2 || emptyH3) {

        p = newParagraph(NONE_DOT);
        doc.add(p);
    }

    //w.writeCharacters("Exported: "+ApplicationHelper.toISODateTimeString(new Date()));

    doc.close();
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

/**
 * @param model//from   w  ww.  java  2  s. c om
 * @param doc
 * @param a
 * @throws DocumentException
 * @throws IOException
 * @throws BadElementException
 */
private void addSingleActionTable(GTDModel model, Document doc, Action a)
        throws DocumentException, IOException, BadElementException {
    Chunk ch;
    PdfPTable t;
    PdfPCell c;
    t = new PdfPTable(3);
    t.setSpacingBefore(5f);
    t.setWidthPercentage(100f);

    Paragraph ph = newParagraph();
    ch = newChunk(ID);
    ph.add(ch);
    ch = newChunk(String.valueOf(a.getId()));
    ch.getFont().setStyle(Font.BOLD);
    ph.add(ch);
    c = newCell(ph);
    t.addCell(c);

    ph = newParagraph();
    ch = newChunk(CREATED);
    ph.add(ch);
    ch = newChunk(ApplicationHelper.toISODateTimeString(a.getCreated()));
    ch.getFont().setStyle(Font.BOLD);
    ph.add(ch);
    c = newCell(ph);
    t.addCell(c);

    ph = newParagraph();
    if (a.isOpen()) {
        ch = newChunk(OPEN);
        ch.getFont().setStyle(Font.BOLD);
        ch.getFont().setColor(COLOR_OPEN);
        ph.add(ch);
        ch = newOpenChunk();
        ph.add(ch);
    } else if (a.isResolved()) {
        ch = newChunk(RESOLVED);
        ch.getFont().setStyle(Font.BOLD);
        ch.getFont().setColor(COLOR_RESOLVED);
        ph.add(ch);
        ch = newResolvedChunk();
        ph.add(ch);
    } else if (a.isDeleted()) {
        ch = newChunk(DELETED);
        ch.getFont().setStyle(Font.BOLD);
        ch.getFont().setColor(COLOR_DELETED);
        ph.add(ch);
        ch = newDeletedChunk();
        ph.add(ch);
    } else {
        ch = newChunk(STALLED);
        ch.getFont().setStyle(Font.BOLD);
        ch.getFont().setColor(COLOR_DELETED);
        ph.add(ch);
        ch = newStalledChunk();
        ph.add(ch);
    }
    c = newCell(ph);
    c.setHorizontalAlignment(Cell.ALIGN_RIGHT);
    t.addCell(c);

    ph = newParagraph();
    ch = newChunk(PRIORITY);
    ph.add(ch);
    ch = newChunk(a.getPriority() == null ? NONE : a.getPriority().toString());
    ch.getFont().setStyle(Font.BOLD);
    ph.add(ch);
    ch = newChunk(" ");
    ch.getFont().setStyle(Font.BOLD);
    ph.add(ch);

    if (a.getPriority() == null || a.getPriority() == Priority.None) {
        ch = newNoneStarChunk();
        ph.add(ch);
        ch = newNoneStarChunk();
        ph.add(ch);
        ch = newNoneStarChunk();
        ph.add(ch);
    } else if (a.getPriority() == Priority.Low) {
        ch = newLowStarChunk();
        ph.add(ch);
        ch = newNoneStarChunk();
        ph.add(ch);
        ch = newNoneStarChunk();
        ph.add(ch);
    } else if (a.getPriority() == Priority.Medium) {
        ch = newLowStarChunk();
        ph.add(ch);
        ch = newMediumStarChunk();
        ph.add(ch);
        ch = newNoneStarChunk();
        ph.add(ch);
    } else if (a.getPriority() == Priority.High) {
        ch = newLowStarChunk();
        ph.add(ch);
        ch = newMediumStarChunk();
        ph.add(ch);
        ch = newHighStarChunk();
        ph.add(ch);
    }

    c = newCell(ph);
    t.addCell(c);

    ph = newParagraph();
    ch = newChunk(REMINDER);
    ph.add(ch);
    ch = newChunk(a.getRemind() != null ? ApplicationHelper.toISODateString(a.getRemind()) : NONE);
    ch.getFont().setStyle(Font.BOLD);
    ph.add(ch);
    c = newCell(ph);
    t.addCell(c);

    ph = newParagraph();
    ch = newChunk(PROJECT);
    ph.add(ch);
    if (a.getProject() != null) {
        ch = newChunk(model.getProject(a.getProject()).getName());
    } else {
        ch = newChunk(NONE);
    }
    ch.getFont().setStyle(Font.BOLD);
    ph.add(ch);
    c = newCell(ph);
    t.addCell(c);

    c = newDescriptionCell(a.getDescription());
    c.setColspan(3);
    t.addCell(c);

    if (a.getUrl() != null) {

        ch = newChunk(a.getUrl().toString());
        ch.setAnchor(a.getUrl());
        ch.getFont().setColor(Color.BLUE);

        c = newCell(new Paragraph(ch));
        c.setColspan(3);
        t.addCell(c);
    }

    doc.add(t);
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

private Element newSection(String s) throws DocumentException, IOException {
    Phrase c = fontSelectorB2.process(s);
    Paragraph p = new Paragraph(c);

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(15f);//  w  w  w  . j  av a 2 s  . c o m
    t.setSpacingAfter(7f);
    t.setWidthPercentage(100f);

    PdfPCell ce = newCell(p);
    ce.setBorder(PdfPCell.BOTTOM);
    ce.setBorderWidth(1f);
    ce.setPaddingLeft(0);
    ce.setPaddingRight(0);

    t.addCell(ce);

    return t;
}

From source file:org.gtdfree.addons.PDFExportAddOn.java

License:Open Source License

private Element newSubSection(String s) throws DocumentException, IOException {
    Phrase c = fontSelectorB.process(s);
    Paragraph p = new Paragraph(c);

    PdfPTable t = new PdfPTable(1);
    t.setSpacingBefore(7f);// w  ww  . j a v a  2  s. c o  m
    t.setSpacingAfter(5f);
    t.setWidthPercentage(100f);

    PdfPCell ce = newCell(p);
    ce.setBorder(PdfPCell.BOTTOM);
    ce.setBorderWidth(0.75f);
    ce.setPaddingLeft(0);
    ce.setPaddingRight(0);

    t.addCell(ce);

    return t;
}

From source file:org.jsondoc.springmvc.pdf.PdfExportView.java

License:Open Source License

public File getPdfFile(String filename) {
    try {// w w w .java  2 s.  c  o m
        File file = new File(filename + "-v" + jsonDoc.getVersion() + FILE_EXTENSION);
        FileOutputStream fileout = new FileOutputStream(file);
        Document document = new Document();
        PdfWriter.getInstance(document, fileout);

        // Header
        HeaderFooter header = new HeaderFooter(new Phrase("Copyright "
                + Calendar.getInstance().get(Calendar.YEAR) + " Paybay Networks - All rights reserved"), false);
        header.setBorder(Rectangle.NO_BORDER);
        header.setAlignment(Element.ALIGN_LEFT);
        document.setHeader(header);

        // Footer
        HeaderFooter footer = new HeaderFooter(new Phrase("Page "), true);
        footer.setBorder(Rectangle.NO_BORDER);
        footer.setAlignment(Element.ALIGN_CENTER);
        document.setFooter(footer);

        document.open();

        //init documentation
        apiDocs = buildApiDocList();
        apiMethodDocs = buildApiMethodDocList(apiDocs);

        Phrase baseUrl = new Phrase("Base url: " + jsonDoc.getBasePath());
        document.add(baseUrl);
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);

        int pos = 1;
        for (ApiMethodDoc apiMethodDoc : apiMethodDocs) {
            Phrase phrase = new Phrase(/*"Description: " + */apiMethodDoc.getDescription());
            document.add(phrase);
            document.add(Chunk.NEWLINE);

            PdfPTable table = new PdfPTable(2);
            table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
            table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
            table.setWidthPercentage(100);

            table.setWidths(new int[] { 50, 200 });

            // HEADER CELL START TABLE
            table.addCell(ITextUtils.getHeaderCell("URL"));
            table.addCell(ITextUtils.getHeaderCell("<baseUrl> " + apiMethodDoc.getPath()));
            table.completeRow();

            // FIRST CELL
            table.addCell(ITextUtils.getCell("Http Method", 0));
            table.addCell(ITextUtils.getCell(apiMethodDoc.getVerb().name(), pos));
            pos++;
            table.completeRow();

            // PRODUCES
            if (!apiMethodDoc.getProduces().isEmpty()) {
                table.addCell(ITextUtils.getCell("Produces", 0));
                table.addCell(ITextUtils.getCell(buildApiMethodProduces(apiMethodDoc), pos));
                pos++;
                table.completeRow();
            }

            // CONSUMES
            if (!apiMethodDoc.getConsumes().isEmpty()) {
                table.addCell(ITextUtils.getCell("Consumes", 0));
                table.addCell(ITextUtils.getCell(buildApiMethodConsumes(apiMethodDoc), pos));
                pos++;
                table.completeRow();
            }

            // HEADERS
            if (!apiMethodDoc.getHeaders().isEmpty()) {
                table.addCell(ITextUtils.getCell("Request headers", 0));

                PdfPTable pathParamsTable = new PdfPTable(3);
                pathParamsTable.setWidths(new int[] { 30, 20, 40 });

                pathParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                pathParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

                for (ApiHeaderDoc apiHeaderDoc : apiMethodDoc.getHeaders()) {
                    PdfPCell boldCell = new PdfPCell();
                    Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
                    boldCell.setPhrase(new Phrase(apiHeaderDoc.getName(), fontbold));
                    boldCell.getPhrase().setFont(new Font(Font.BOLD));
                    boldCell.setBorder(Rectangle.NO_BORDER);
                    pathParamsTable.addCell(boldCell);

                    PdfPCell paramCell = new PdfPCell();

                    StringBuilder builder = new StringBuilder();

                    for (String value : apiHeaderDoc.getAllowedvalues())
                        builder.append(value).append(", ");

                    paramCell.setPhrase(new Phrase("Allowed values: " + builder.toString()));
                    paramCell.setBorder(Rectangle.NO_BORDER);

                    pathParamsTable.addCell(paramCell);

                    paramCell.setPhrase(new Phrase(apiHeaderDoc.getDescription()));

                    pathParamsTable.addCell(paramCell);
                    pathParamsTable.completeRow();
                }

                PdfPCell bluBorderCell = new PdfPCell(pathParamsTable);
                bluBorderCell.setBorder(Rectangle.NO_BORDER);
                bluBorderCell.setBorderWidthRight(1f);
                bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR);

                table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos));
                pos++;
                table.completeRow();
            }

            // PATH PARAMS
            if (!apiMethodDoc.getPathparameters().isEmpty()) {
                table.addCell(ITextUtils.getCell("Path params", 0));

                PdfPTable pathParamsTable = new PdfPTable(3);
                pathParamsTable.setWidths(new int[] { 30, 15, 40 });

                pathParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                pathParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

                for (ApiParamDoc apiParamDoc : apiMethodDoc.getPathparameters()) {
                    PdfPCell boldCell = new PdfPCell();
                    Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
                    boldCell.setPhrase(new Phrase(apiParamDoc.getName(), fontbold));
                    boldCell.getPhrase().setFont(new Font(Font.BOLD));
                    boldCell.setBorder(Rectangle.NO_BORDER);
                    pathParamsTable.addCell(boldCell);

                    PdfPCell paramCell = new PdfPCell();
                    paramCell.setPhrase(new Phrase(apiParamDoc.getJsondocType().getOneLineText()));
                    paramCell.setBorder(Rectangle.NO_BORDER);

                    pathParamsTable.addCell(paramCell);

                    paramCell.setPhrase(new Phrase(apiParamDoc.getDescription()));

                    pathParamsTable.addCell(paramCell);
                    pathParamsTable.completeRow();
                }

                PdfPCell bluBorderCell = new PdfPCell(pathParamsTable);
                bluBorderCell.setBorder(Rectangle.NO_BORDER);
                bluBorderCell.setBorderWidthRight(1f);
                bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR);

                table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos));
                pos++;
                table.completeRow();
            }

            // QUERY PARAMS
            if (!apiMethodDoc.getQueryparameters().isEmpty()) {
                table.addCell(ITextUtils.getCell("Query params", 0));

                PdfPTable queryParamsTable = new PdfPTable(3);
                queryParamsTable.setWidths(new int[] { 30, 15, 40 });

                queryParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                queryParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

                for (ApiParamDoc apiParamDoc : apiMethodDoc.getQueryparameters()) {
                    PdfPCell boldCell = new PdfPCell();
                    Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD);
                    boldCell.setPhrase(new Phrase(apiParamDoc.getName(), fontbold));
                    boldCell.getPhrase().setFont(new Font(Font.BOLD));
                    boldCell.setBorder(Rectangle.NO_BORDER);
                    queryParamsTable.addCell(boldCell);

                    PdfPCell paramCell = new PdfPCell();
                    paramCell.setPhrase(new Phrase(apiParamDoc.getJsondocType().getOneLineText()));
                    paramCell.setBorder(Rectangle.NO_BORDER);

                    queryParamsTable.addCell(paramCell);

                    paramCell.setPhrase(new Phrase(
                            apiParamDoc.getDescription() + ", mandatory: " + apiParamDoc.getRequired()));

                    queryParamsTable.addCell(paramCell);
                    queryParamsTable.completeRow();
                }

                PdfPCell bluBorderCell = new PdfPCell(queryParamsTable);
                bluBorderCell.setBorder(Rectangle.NO_BORDER);
                bluBorderCell.setBorderWidthRight(1f);
                bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR);

                table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos));
                pos++;
                table.completeRow();
            }

            // BODY OBJECT
            if (null != apiMethodDoc.getBodyobject()) {
                table.addCell(ITextUtils.getCell("Body object:", 0));
                String jsonObject = buildJsonFromTemplate(apiMethodDoc.getBodyobject().getJsondocTemplate());
                table.addCell(ITextUtils.getCell(jsonObject, pos));
                pos++;
                table.completeRow();
            }

            // RESPONSE OBJECT
            table.addCell(ITextUtils.getCell("Json response:", 0));
            table.addCell(
                    ITextUtils.getCell(apiMethodDoc.getResponse().getJsondocType().getOneLineText(), pos));
            pos++;
            table.completeRow();

            // RESPONSE STATUS CODE
            table.addCell(ITextUtils.getCell("Status code:", 0));
            table.addCell(ITextUtils.getCell(apiMethodDoc.getResponsestatuscode(), pos));
            pos++;
            table.completeRow();

            table.setSpacingAfter(10f);
            table.setSpacingBefore(5f);
            document.add(table);
        }

        document.close();
        return file;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.kuali.kfs.gl.report.TransactionReport.java

License:Open Source License

/**
 * Appends the scrubber totals/statistics and error report to the given (iText) document object.
 * /* w  ww .  j  av a  2s .  c  o m*/
 * @param document the PDF document
 * @param headerFont font for header
 * @param textFont font for report text
 * @param errorSortedList list of error'd transactions
 * @param reportErrors map containing transactions and the errors associated with each transaction
 * @param reportSummary list of summary objects
 * @param runDate date report was run
 * @throws DocumentException
 */
public void appendReport(Document document, Font headerFont, Font textFont, List<Transaction> errorSortedList,
        Map<Transaction, List<Message>> reportErrors, List<Summary> reportSummary, Date runDate)
        throws DocumentException {
    // Sort what we get
    Collections.sort(reportSummary);

    float[] summaryWidths = { 80, 20 };
    PdfPTable summary = new PdfPTable(summaryWidths);
    summary.setWidthPercentage(40);
    PdfPCell cell = new PdfPCell(new Phrase("S T A T I S T I C S", headerFont));
    cell.setColspan(2);
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    summary.addCell(cell);

    for (Iterator iter = reportSummary.iterator(); iter.hasNext();) {
        Summary s = (Summary) iter.next();

        cell = new PdfPCell(new Phrase(s.getDescription(), textFont));
        cell.setBorder(Rectangle.NO_BORDER);
        summary.addCell(cell);

        if ("".equals(s.getDescription())) {
            cell = new PdfPCell(new Phrase("", textFont));
            cell.setBorder(Rectangle.NO_BORDER);
            summary.addCell(cell);
        } else {
            DecimalFormat nf = new DecimalFormat("###,###,###,##0");
            cell = new PdfPCell(new Phrase(nf.format(s.getCount()), textFont));
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            summary.addCell(cell);
        }
    }
    cell = new PdfPCell(new Phrase(""));
    cell.setColspan(2);
    cell.setBorder(Rectangle.NO_BORDER);
    summary.addCell(cell);

    document.add(summary);

    if (reportErrors != null && reportErrors.size() > 0) {
        float[] warningWidths = { 4, 3, 6, 5, 5, 4, 5, 5, 4, 5, 5, 9, 4, 36 };
        PdfPTable warnings = new PdfPTable(warningWidths);
        warnings.setHeaderRows(2);
        warnings.setWidthPercentage(100);
        cell = new PdfPCell(new Phrase("W A R N I N G S", headerFont));
        cell.setColspan(14);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        warnings.addCell(cell);

        // Add headers
        cell = new PdfPCell(new Phrase("Year", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("COA", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("Account", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("Sacct", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("Obj", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("SObj", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("BalTyp", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("ObjTyp", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("Prd", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("DocType", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("Origin", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("DocNbr", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("Seq", headerFont));
        warnings.addCell(cell);
        cell = new PdfPCell(new Phrase("Warning", headerFont));
        warnings.addCell(cell);

        for (Iterator errorIter = errorSortedList.iterator(); errorIter.hasNext();) {
            Transaction tran = (Transaction) errorIter.next();
            boolean first = true;

            List errors = (List) reportErrors.get(tran);
            for (Iterator listIter = errors.iterator(); listIter.hasNext();) {
                String msg = null;
                Object m = listIter.next();
                if (m instanceof Message) {
                    Message mm = (Message) m;
                    msg = mm.getMessage();
                } else {
                    if (m == null) {
                        msg = "";
                    } else {
                        msg = m.toString();
                    }
                }

                if (first) {
                    first = false;

                    if (tran.getUniversityFiscalYear() == null) {
                        cell = new PdfPCell(new Phrase("NULL", textFont));
                    } else {
                        cell = new PdfPCell(new Phrase(tran.getUniversityFiscalYear().toString(), textFont));
                    }
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getChartOfAccountsCode(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getAccountNumber(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getSubAccountNumber(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getFinancialObjectCode(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getFinancialSubObjectCode(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getFinancialBalanceTypeCode(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getFinancialObjectTypeCode(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getUniversityFiscalPeriodCode(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getFinancialDocumentTypeCode(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getFinancialSystemOriginationCode(), textFont));
                    warnings.addCell(cell);
                    cell = new PdfPCell(new Phrase(tran.getDocumentNumber(), textFont));
                    warnings.addCell(cell);
                    if (tran.getTransactionLedgerEntrySequenceNumber() == null) {
                        cell = new PdfPCell(new Phrase("NULL", textFont));
                    } else {
                        cell = new PdfPCell(new Phrase(
                                tran.getTransactionLedgerEntrySequenceNumber().toString(), textFont));
                    }
                    warnings.addCell(cell);
                } else {
                    cell = new PdfPCell(new Phrase("", textFont));
                    cell.setColspan(13);
                    warnings.addCell(cell);
                }
                cell = new PdfPCell(new Phrase(msg, textFont));
                warnings.addCell(cell);
            }
        }
        document.add(warnings);
    }
}