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

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

Introduction

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

Prototype

public void deleteBodyRows() 

Source Link

Document

Removes all of the rows except headers

Usage

From source file:com.krawler.esp.servlets.ExportPDFServlet.java

License:Open Source License

private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        String[] colIndex1, Document document) {
    float[] f = new float[(stpcol - stcol)];
    for (int k = 0; k < f.length; k++)
        f[k] = 20;//from  w ww.j a v a  2  s.  c  o  m
    PdfPTable table = new PdfPTable(f);
    PdfPCell cell = new PdfPCell(new Paragraph("Agenda Details"));
    cell.setColspan(6);
    table.addCell(cell);
    Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK);
    Font font1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, Color.BLACK);
    Font f1;
    int stpcol1 = 0;
    for (int hcol = stcol; hcol < stpcol; hcol++) {
        PdfPCell h1 = new PdfPCell(new Paragraph(colwidth2[hcol], font)); // new
        // Paragraph(colwidth2[hcol],font);
        table.addCell(h1);
    }
    table.setHeaderRows(1);
    try {
        for (int row = strow; row < stprow; row++) {
            if (row % 62 == 61) {
                document.add(table);
                table.deleteBodyRows();
                table.setSkipFirstHeader(true);
            }
            f1 = font1;
            for (int col = stcol; col < stpcol; col++) {
                table.addCell(new Paragraph(store.getJSONObject(row).getString(colIndex1[col]), f1));
            }
        }
        document.newPage();
        document.add(table);

        if (stpcol != colIndex1.length) {
            if ((colIndex1.length - stpcol) > 5) // column limit
                stpcol1 = stpcol + 5;
            else
                stpcol1 = (colIndex1.length - stpcol) + stpcol;
            addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, colIndex1, document);
        }
    } catch (Exception e) {
        e.toString();
    }
    return stpcol;
}

From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java

License:Open Source License

private int addTableTimeLine(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        int maxlevel, Document document) throws JSONException, DocumentException {
    float[] f = new float[(stpcol - stcol) + 1];
    for (int k = 0; k < f.length; k++) {
        f[k] = 20;//from  w w w .  j a v  a  2  s . co  m
    }
    f[0] = f[0] + 10 * maxlevel;
    PdfPTable table = new PdfPTable(f);

    java.awt.Color tColor = new Color(Integer.parseInt(config.getString("textColor"), 16));

    Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, tColor);
    Font font1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, tColor);
    Font f1;

    table.setWidthPercentage(90);
    PdfPCell h2 = new PdfPCell(new Paragraph("Name", font)); // new
    if (config.getBoolean("gridBorder"))
        h2.setBorder(PdfPCell.BOX);
    else
        h2.setBorder(0);
    h2.setPadding(2);
    //                h2.setHorizontalAlignment(Element.ALIGN_UNDEFINED);
    // Paragraph(colwidth2[hcol],font);
    table.addCell(h2);
    int stpcol1 = 0;
    for (int hcol = stcol; hcol < stpcol; hcol++) {
        PdfPCell h1 = new PdfPCell(new Paragraph(colwidth2[hcol], font)); // new
        h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        if (config.getBoolean("gridBorder"))
            h1.setBorder(PdfPCell.BOX);
        else
            h1.setBorder(0);
        h1.setPadding(2);
        // Paragraph(colwidth2[hcol],font);
        table.addCell(h1);
    }
    table.setHeaderRows(1);

    for (int row = strow; row < stprow; row++) {
        if (row % 62 == 61) {
            document.add(table);
            table.deleteBodyRows();
            table.setSkipFirstHeader(true);
        }
        if (store.getJSONObject(row).getBoolean("flag"))
            f1 = font;
        else
            f1 = font1;
        if (store.getJSONObject(row).getString("info").compareTo("") != 0) {
            h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
            //                    h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
        } else {
            h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
            //                    h2.setPaddingTop(9);
            //                    h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
        }

        //                h2.setBorder(0);
        //                h2.setPadding(1);
        //                Color bColor = Color.decode("DDDDDD");

        if (config.getBoolean("gridBorder")) {
            if (store.getJSONObject(row).getBoolean("flag")) {
                h2.setBackgroundColor(new Color(0xEEEEEE));
                h2.setBorder(PdfPCell.LEFT | PdfPCell.BOTTOM);
            } else
                h2.setBorder(PdfPCell.BOX);
        } else {
            h2.setBorder(0);
        }
        h2.setPadding(2);
        h2.setBorderColor(Color.GRAY);
        if (store.getJSONObject(row).getBoolean("flag"))
            h2.setHorizontalAlignment(Element.ALIGN_LEFT);
        else
            h2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        h2.setVerticalAlignment(Element.ALIGN_CENTER);
        table.addCell(h2);
        for (int col = stcol; col < stpcol; col++) {
            Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
            PdfPCell h1 = new PdfPCell(para);
            //                    h1.setBorder(0);
            //                    h1.setPadding(1);

            h1.setMinimumHeight(15);
            h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
            h1.setVerticalAlignment(Element.ALIGN_CENTER);
            if (config.getBoolean("gridBorder")) {
                if (store.getJSONObject(row).getBoolean("flag")) {
                    h1.setBorder(PdfPCell.BOTTOM);
                    h1.setBackgroundColor(new Color(0xEEEEEE));
                    if (col == stpcol - 1)
                        h1.setBorder(PdfPCell.BOTTOM | PdfPCell.RIGHT);
                } else
                    h1.setBorder(PdfPCell.BOX);
            } else {
                h1.setBorder(0);
            }
            h1.setPadding(2);
            h1.setBorderColor(Color.GRAY);
            table.addCell(h1);
            //               table.addCell(new Paragraph(store.getJSONObject(row)
            //                     .getString(colwidth2[col]), f1));
        }

    }
    document.add(table);
    document.newPage();
    if (stpcol != colwidth2.length) {
        if ((colwidth2.length - stpcol) > 5) // column limit
            stpcol1 = stpcol + 5;
        else
            stpcol1 = (colwidth2.length - stpcol) + stpcol;
        addTableTimeLine(stpcol, stpcol1, strow, stprow, store, colwidth2, maxlevel, document);
    }

    return stpcol;
}

From source file:com.krawler.esp.servlets.ExportReportServlet.java

License:Open Source License

private int addTable(int stcol, int stpcol, int strow, int stprow, JSONArray store, String[] colwidth2,
        int maxlevel, Document document) {
    float[] f = new float[(stpcol - stcol) + 1];
    for (int k = 0; k < f.length; k++) {
        f[k] = 20;//w ww .  j  av a 2  s.c o  m
    }
    f[0] = f[0] + 10 * maxlevel;
    PdfPTable table = new PdfPTable(f);
    Font font = FontFactory.getFont("Helvetica", 8, Font.BOLD, Color.BLACK);
    Font font1 = FontFactory.getFont("Helvetica", 8, Font.NORMAL, Color.BLACK);
    Font f1;
    PdfPCell h2 = new PdfPCell(new Paragraph("", font)); // new
    h2.setBorder(0);
    h2.setPadding(1);
    //                h2.setHorizontalAlignment(Element.ALIGN_UNDEFINED);                                       
    // Paragraph(colwidth2[hcol],font);
    table.addCell(h2);
    int stpcol1 = 0;
    for (int hcol = stcol; hcol < stpcol; hcol++) {
        PdfPCell h1 = new PdfPCell(new Paragraph(colwidth2[hcol], font)); // new
        h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        h1.setBorder(0);
        h1.setPadding(1);
        // Paragraph(colwidth2[hcol],font);
        table.addCell(h1);
    }
    table.setHeaderRows(1);
    try {
        for (int row = strow; row < stprow; row++) {
            if (row % 62 == 61) {
                document.add(table);
                table.deleteBodyRows();
                table.setSkipFirstHeader(true);
            }
            if (store.getJSONObject(row).getBoolean("flag"))
                f1 = font;
            else
                f1 = font1;
            if (store.getJSONObject(row).getString("info").compareTo("") != 0) {
                h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
                h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
            } else {
                h2 = new PdfPCell(new Paragraph(store.getJSONObject(row).getString("info"), f1));
                h2.setPaddingTop(9);
                h2.setPaddingLeft((Integer.parseInt(store.getJSONObject(row).getString("level")) * 10) + 5);
            }
            h2.setBorder(0);
            h2.setPadding(1);
            if (store.getJSONObject(row).getBoolean("flag"))
                h2.setHorizontalAlignment(Element.ALIGN_LEFT);
            else
                h2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            h2.setVerticalAlignment(Element.ALIGN_CENTER);
            table.addCell(h2);
            for (int col = stcol; col < stpcol; col++) {
                Paragraph para = null;
                if (store.getJSONObject(row).has(colwidth2[col]))
                    para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
                else
                    para = new Paragraph("", f1);
                //                    Paragraph para = new Paragraph(store.getJSONObject(row).getString(colwidth2[col]), f1);
                PdfPCell h1 = new PdfPCell(para);
                h1.setBorder(0);
                h1.setPadding(1);
                h1.setHorizontalAlignment(Element.ALIGN_RIGHT);
                h1.setVerticalAlignment(Element.ALIGN_CENTER);
                table.addCell(h1);
                //               table.addCell(new Paragraph(store.getJSONObject(row)
                //                     .getString(colwidth2[col]), f1));
            }

        }
        document.add(table);
        document.newPage();
        if (stpcol != colwidth2.length) {
            if ((colwidth2.length - stpcol) > 5) // column limit
                stpcol1 = stpcol + 5;
            else
                stpcol1 = (colwidth2.length - stpcol) + stpcol;
            addTable(stpcol, stpcol1, strow, stprow, store, colwidth2, maxlevel, document);
        }

    } catch (com.krawler.utils.json.base.JSONException j) {
        KrawlerLog.op.warn("Problem During Creating JSON Object :" + j.toString());
    } catch (com.lowagie.text.DocumentException de) {
        KrawlerLog.op.warn("Problem While Creating PDF :" + de.toString());
    }
    return stpcol;
}

From source file:ispyb.common.util.export.PdfExporterSample.java

License:Open Source License

/**
 * Exports the file for viewSample for shipment
 * /* www.j a va 2 s  .  c om*/
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportAsPdf() throws Exception {

    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    document.addTitle("exportSamplesView");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);
    HeaderFooter header;

    // header + footer
    if (viewName != null)
        header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc + "  ---  " + viewName),
                false);

    else
        header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc), false);

    header.setAlignment(Element.ALIGN_CENTER);
    header.setBorderWidth(1);
    header.getBefore().getFont().setSize(8);
    HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true);
    footer.setAlignment(Element.ALIGN_RIGHT);
    footer.setBorderWidth(1);
    footer.getBefore().getFont().setSize(6);

    document.setHeader(header);
    document.setFooter(footer);

    document.open();

    if (aList.isEmpty()) {
        document.add(new Paragraph("There is no samples in this report"));
        document.close();
        return baos;
    }
    // Create first table for samples

    int NumColumns = 19;
    PdfPTable table = new PdfPTable(NumColumns);
    int headerwidths[] = { 6, 6, 6, 6, 6, 4, 6, 4, 4, 4, 4, 4, 4, 8, 5, 5, 5, 10, 6 }; // percentage
    table.setWidths(headerwidths);

    table.setWidthPercentage(100); // percentage
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setBorderWidth(1);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    // header
    PdfPCell cell = new PdfPCell();
    table.addCell(new Paragraph("Protein", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample name", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Smp code", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Dewar", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Container", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Loc. in cont.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Space group", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell a", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell b", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell c", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell alpha", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell beta", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell gamma", new Font(Font.HELVETICA, 8)));

    cell = new PdfPCell(new Paragraph("Crystal comments", new Font(Font.HELVETICA, 8)));
    table.addCell(cell);

    table.addCell(new Paragraph("Already observed resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Required resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Min. resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample comments", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample status", new Font(Font.HELVETICA, 8)));

    table.setHeaderRows(1); // this is the end of the table header

    table.getDefaultCell().setBorderWidth(1);
    DecimalFormat df1 = new DecimalFormat("#####0.0");
    DecimalFormat df2 = new DecimalFormat("#####0.00");

    Iterator it = aList.iterator();
    int i = 1;
    String currentContainer = "next";
    String nextContainer = "next";

    while (it.hasNext()) {
        table.getDefaultCell().setGrayFill(0.99f);
        if (i % 2 == 1) {
            table.getDefaultCell().setGrayFill(0.9f);
        }
        BLSample3VO samplefv = (BLSample3VO) it.next();
        LOG.debug("table of datacollections pdf " + samplefv.getBlSampleId());

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null)
            nextContainer = samplefv.getContainerVO().getCode();
        else
            nextContainer = "next";

        // in the case of view sorted by dewar/container, we add a page break afetr each container
        if (sortView.equals("2") && !currentContainer.equals(nextContainer)) {
            document.add(table);
            table.deleteBodyRows();
            document.newPage();
        }

        if (samplefv.getCrystalVO().getProteinVO().getAcronym() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getProteinVO().getAcronym(),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getName() != null)
            table.addCell(new Paragraph(samplefv.getName(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCode() != null)
            table.addCell(new Paragraph(samplefv.getCode(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getDewarVO() != null
                && samplefv.getContainerVO().getDewarVO().getCode() != null)
            table.addCell(new Paragraph(samplefv.getContainerVO().getDewarVO().getCode(),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null) {
            currentContainer = samplefv.getContainerVO().getCode();
            table.addCell(new Paragraph(currentContainer, new Font(Font.HELVETICA, 8)));
        } else {
            currentContainer = "current";
            table.addCell("");
        }

        if (samplefv.getLocation() != null)
            table.addCell(new Paragraph(samplefv.getLocation(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getSpaceGroup() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getSpaceGroup(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellA() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellA()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellB() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellB()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellC() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellC()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellAlpha() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellAlpha()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellBeta() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellBeta()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellGamma() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellGamma()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getComments() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getComments(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getObservedResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getObservedResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getRequiredResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getRequiredResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getMinimalResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getMinimalResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getComments() != null && samplefv.getComments() != "")
            table.addCell(new Paragraph(samplefv.getComments(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getBlSampleStatus() != null)
            table.addCell(new Paragraph(samplefv.getBlSampleStatus(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (i % 2 == 1) {
            table.getDefaultCell().setGrayFill(0.0f);
        }

        i++;
    }

    document.add(table);

    document.close();

    return baos;
}