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

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

Introduction

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

Prototype

public PdfPTable(PdfPTable table) 

Source Link

Document

Constructs a copy of a PdfPTable.

Usage

From source file:beans.ManagedBeanProducto.java

License:Open Source License

public String CreatePdf() throws IOException, DocumentException {
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    //System.out.println(" test: "+extContext);
    //System.out.println(" esta es la ruta" + extContext.getRealPath("//pdfs//"));
    // step 1//ww w.j a  v  a 2 s.  c  o  m
    String ruta_pdfs = extContext.getRealPath("//pdfs//");
    Document document = new Document(PageSize.A4);
    document.setMargins(5, 5, 25, 25);
    document.setMarginMirroring(true);

    // step 2
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(ruta_pdfs + "//CB" + Producto.getIdProducto() + ".pdf"));
    // step 3
    document.open();
    // step 4
    PdfContentByte cb = writer.getDirectContent();

    Paragraph Titulo = new Paragraph(
            "PRODUCTO : " + Producto.getNombreProducto().substring(14).toUpperCase() + "\n\n");
    Titulo.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(Titulo);

    // EAN 13
    // document.add(new Paragraph("Barcode EAN.UCC-13"));
    BarcodeEAN codeEAN = new BarcodeEAN();

    codeEAN.setCode(CodigoBarrasFinal());
    String nombre_producto = "";
    if (Producto.getNombreProducto().length() >= 41) {
        nombre_producto = Producto.getNombreProducto().substring(14, 41);
    } else {
        nombre_producto = Producto.getNombreProducto().substring(14);
    }
    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // document.add(codeEAN.createImageWithBarcode(cb,Color.BLUE , Color.BLUE));
    // codeEAN.setGuardBars(false);

    // document.add(new Paragraph(nombre_producto,new Font(Font.COURIER, 5, Font.NORMAL)));
    // codeEAN.setGuardBars(false);
    Image imagen = codeEAN.createImageWithBarcode(cb, null, null);
    imagen.scaleAbsolute(87, 45);
    //document.add(imagen);

    PdfPTable table = new PdfPTable(5);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    // table.setTotalWidth(1800);
    PdfPCell cell;
    Phrase nombre = new Phrase(nombre_producto.toUpperCase(),
            new Font(Font.COURIER, 5, Font.BOLD, Color.BLACK));

    cell = new PdfPCell();
    cell.addElement(nombre);
    //cell.addElement(new Chunk("\n"));
    cell.addElement(imagen);
    //cell.addElement(new Chunk("\n"));

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    //table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);

    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    // EAN 8 "6987";
    // String inicio ="345";
    //  int intermedio =1000+Producto.getIdProducto();
    //  String fin ="0";
    // document.add(new Paragraph(Producto.getNombreProducto(),new Font(Font.COURIER, 4, Font.NORMAL)));
    // codeEAN.setCodeType(Barcode.EAN8);
    // codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
    // codeEAN.setCode(inicio.concat(intermedio+fin));
    // document.add(codeEAN.createImageWithBarcode(cb, null, null));
    document.close();

    return "codigo_barras_productos";
}

From source file:biblivre3.administration.reports.AllUsersReport.java

License:Open Source License

private final PdfPTable createSummaryTable(Map<String, Integer> tipos) {
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(50f);/*from w  ww.  ja  v a2s .co  m*/
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);

    int total = 0;
    PdfPCell cell;
    for (String description : tipos.keySet()) {
        total += tipos.get(description);
        cell = new PdfPCell(new Paragraph(this.getHeaderChunk(description.toUpperCase())));
        cell.setBackgroundColor(headerBgColor);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getNormalChunk(String.valueOf(tipos.get(description)))));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
    }
    cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TOTAL"))));
    cell.setBackgroundColor(headerBgColor);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph(this.getNormalChunk(String.valueOf(total))));
    cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    return table;
}

From source file:biblivre3.administration.reports.AllUsersReport.java

License:Open Source License

private final ArrayList<PdfPTable> createListTable(Map<String, List<String>> data) {
    try {/*from  w  w w  .  j  a  va 2 s .  c  o m*/
        ArrayList<PdfPTable> tabelas = new ArrayList<PdfPTable>();
        PdfPTable table = null;
        PdfPCell cell;
        for (String description : data.keySet()) {
            table = new PdfPTable(4);
            table.setWidthPercentage(100f);
            cell = new PdfPCell(new Paragraph(this.getHeaderChunk(description.toUpperCase())));
            cell.setColspan(4);
            cell.setBorder(PdfPCell.NO_BORDER);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_NAME"))));
            cell.setBackgroundColor(headerBgColor);
            cell.setBorderWidth(headerBorderWidth);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_ENROL"))));
            cell.setBackgroundColor(headerBgColor);
            cell.setBorderWidth(headerBorderWidth);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_INSERTION_DATE"))));
            cell.setBackgroundColor(headerBgColor);
            cell.setBorderWidth(headerBorderWidth);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);

            cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_UPDATE_DATE"))));
            cell.setBackgroundColor(headerBgColor);
            cell.setBorderWidth(headerBorderWidth);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);

            for (String line : data.get(description)) {
                String[] dados = line.split("\t");
                //Nome
                cell = new PdfPCell(new Paragraph(this.getNormalChunk(dados[0])));
                cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                table.addCell(cell);

                //Matricula
                cell = new PdfPCell(new Paragraph(this.getNormalChunk(dados[1])));
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                table.addCell(cell);

                //Data de Inclusao
                cell = new PdfPCell(new Paragraph(this.getNormalChunk(dados[2])));
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                table.addCell(cell);

                //Data de Cancelamento/Alteracao
                cell = new PdfPCell(new Paragraph(this.getNormalChunk(dados[3])));
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                table.addCell(cell);
            }
            if (table != null) {
                tabelas.add(table);
            }
        }
        return tabelas;
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}

From source file:biblivre3.administration.reports.AssetHoldingByDateReport.java

License:Open Source License

@Override
protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception {
    AssetHoldingByDateDto dto = (AssetHoldingByDateDto) reportData;
    Paragraph p1 = new Paragraph(this.getText("REPORTS_ASSET_HOLDING_BY_DATE_TITLE"));
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(p1);//ww w  . j  a  v a  2 s.  co  m
    document.add(new Phrase("\n"));
    PdfPTable table = new PdfPTable(8);
    table.setWidthPercentage(100f);
    createHeader(table);
    PdfPCell cell;
    List<String[]> dataList = dto.getData();
    for (String[] data : dataList) {
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[0])));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[1])));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[2])));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[3])));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[4])));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[5])));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
    }
    document.add(table);
}

From source file:biblivre3.administration.reports.AssetHoldingFullReport.java

License:Open Source License

@Override
protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception {
    AssetHoldingDto dto = (AssetHoldingDto) reportData;
    String title = "";
    if (this.topographic) {
        title = this.getText("REPORTS_TOPOGRAPHIC_TITLE");
    } else {//from  ww w  .  j  a  va2s . c o  m
        title = this.getText("REPORTS_ASSET_HOLDING_TITLE");
    }
    Paragraph p1 = new Paragraph(title);
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(p1);
    document.add(new Phrase("\n"));
    PdfPTable table = new PdfPTable(20);
    table.setWidthPercentage(100f);
    createHeader(table);
    PdfPCell cell;
    List<String[]> dataList = dto.getData();
    Collections.sort(dataList, this);
    for (String[] data : dataList) {
        PdfContentByte cb = getWriter().getDirectContent();

        String holdingSerial = StringUtils.leftPad(data[0], 10, "0");
        Barcode39 code39 = new Barcode39();
        code39.setExtended(true);
        code39.setCode(holdingSerial);
        code39.setStartStopText(false);

        Image image39 = code39.createImageWithBarcode(cb, null, null);
        image39.scalePercent(100f);
        cell = new PdfPCell(new Paragraph(new Phrase(new Chunk(image39, 0, 0))));
        cell.setColspan(6);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[1])));
        cell.setColspan(3);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);

        Paragraph para = new Paragraph();
        para.add(new Phrase(this.getSmallFontChunk(data[2] + "\n")));
        para.add(new Phrase(this.getSmallFontChunk(data[3] + "\n")));

        if (StringUtils.isNotBlank(data[4])) {
            para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_LOCATION") + ": ")));
            para.add(new Phrase(this.getSmallFontChunk(data[4] + " ")));
        }

        if (StringUtils.isNotBlank(data[5])) {
            para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_EDITION") + ": ")));
            para.add(new Phrase(this.getSmallFontChunk(data[5] + " ")));
        }

        if (StringUtils.isNotBlank(data[6])) {
            para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_DATE") + ": ")));
            para.add(new Phrase(this.getSmallFontChunk(data[6])));
        }

        cell = new PdfPCell(para);
        cell.setColspan(11);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
        cell.setPaddingTop(5f);
        cell.setPaddingLeft(7f);
        cell.setPaddingBottom(4f);
        table.addCell(cell);
    }
    document.add(table);
}

From source file:biblivre3.administration.reports.AssetHoldingReport.java

License:Open Source License

@Override
protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception {
    AssetHoldingDto dto = (AssetHoldingDto) reportData;
    Paragraph p1 = new Paragraph(this.getText("REPORTS_ASSET_HOLDING_TITLE"));
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(p1);/*from  w  w w  . j a  v a 2  s .  com*/
    document.add(new Phrase("\n"));
    PdfPTable table = new PdfPTable(7);
    table.setWidthPercentage(100f);
    createHeader(table);
    PdfPCell cell;
    List<String[]> dataList = dto.getData();
    Collections.sort(dataList, this);
    for (String[] data : dataList) {
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[0])));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[1])));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[2])));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[3])));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[4])));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
    }
    document.add(table);
}

From source file:biblivre3.administration.reports.BaseBiblivreReport.java

License:Open Source License

@Override
public void onEndPage(PdfWriter writer, Document document) {
    try {//from w  ww . ja  v  a2s  .c o m
        Rectangle page = document.getPageSize();

        PdfPTable head = new PdfPTable(1);
        PdfPCell cell = new PdfPCell(new Paragraph(this.getText("REPORTS_HEADER")));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.BOTTOM);
        head.addCell(cell);
        head.setTotalWidth((page.width() / 2) - document.leftMargin());
        head.writeSelectedRows(0, -1, document.leftMargin(),
                page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        PdfPTable date = new PdfPTable(1);
        PdfPCell dateCell = new PdfPCell(new Paragraph(dateFormat.format(generationDate)));
        dateCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        dateCell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        dateCell.setBorder(Rectangle.BOTTOM);
        date.addCell(dateCell);
        date.setTotalWidth((page.width() / 2) - document.rightMargin());
        date.writeSelectedRows(0, -1, (page.width() / 2),
                page.height() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent());

        PdfPTable foot = new PdfPTable(1);
        Chunk pageNumber = new Chunk(String.valueOf(document.getPageNumber()));
        pageNumber.setFont(footerFont);
        cell = new PdfPCell(new Paragraph(pageNumber));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setBorder(Rectangle.TOP);
        foot.addCell(cell);
        foot.setTotalWidth(page.width() - document.leftMargin() - document.rightMargin());
        foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
                writer.getDirectContent());
    } catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}

From source file:biblivre3.administration.reports.BibliographyReport.java

License:Open Source License

@Override
protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception {
    BibliographyReportDto dto = (BibliographyReportDto) reportData;
    Paragraph p1 = new Paragraph(this.getText("REPORTS_BIBLIOGRAPHY_TITLE"));
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(p1);/*w w  w  .j  a v a2  s .c  o  m*/
    document.add(new Phrase("\n"));
    Paragraph p2 = new Paragraph(
            this.getHeaderChunk(this.getText("REPORTS_AUTHOR") + ":  " + dto.getAuthorName()));
    p2.setAlignment(Paragraph.ALIGN_LEFT);
    document.add(p2);
    document.add(new Phrase("\n"));
    if (dto.getData() != null) {
        PdfPTable table = new PdfPTable(8);
        table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        createHeader(table);
        PdfPCell cell;
        for (String[] data : dto.getData()) {
            cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0])));
            cell.setColspan(3);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[1])));
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[2])));
            cell.setColspan(2);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[3])));
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[4])));
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
        }
        document.add(table);
        document.add(new Phrase("\n"));
    }
}

From source file:biblivre3.administration.reports.DeweyReport.java

License:Open Source License

@Override
protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception {
    DeweyReportDto dto = (DeweyReportDto) reportData;
    Paragraph p1 = new Paragraph(this.getText("REPORTS_DEWEY_TITLE"));
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(p1);//from   www.ja  v  a  2s  . c  o m
    document.add(new Phrase("\n\n"));
    PdfPTable table = new PdfPTable(6);
    table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
    createHeader(table);
    PdfPCell cell;
    int totalRecords = 0;
    int totalHoldings = 0;
    List<String[]> dataList = dto.getData();
    Collections.sort(dataList, this);
    for (String[] data : dataList) {
        if (StringUtils.isBlank(data[0])) {
            data[0] = this.getText("REPORTS_DEWEY_UNCLASSIFIED");
        }
        totalRecords += Integer.parseInt(data[1]);
        totalHoldings += Integer.parseInt(data[2]);
    }
    if (totalRecords > 0) {
        dataList.add(new String[] { this.getText("REPORTS_TOTAL"), String.valueOf(totalRecords),
                String.valueOf(totalHoldings) });
    }

    for (String[] data : dataList) {
        cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[0])));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[1])));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getNormalChunk(data[2])));
        cell.setColspan(2);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
    }
    document.add(table);
}

From source file:biblivre3.administration.reports.HoldingCreationByDatetReport.java

License:Open Source License

@Override
protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception {
    HoldingCreationByDateReportDto dto = (HoldingCreationByDateReportDto) reportData;
    totalUsuario = new HashMap<String, Integer>();
    Paragraph p1 = new Paragraph(this.getText("REPORTS_INSERTION_BY_DATE_TITLE"));
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(p1);//from w  ww  .  ja v  a2  s. com
    document.add(new Phrase("\n"));
    String dateSpan = this.getText("REPORTS_FROM") + " " + dto.getInitialDate() + " "
            + this.getText("REPORTS_TO") + " " + dto.getFinalDate();
    Paragraph p2 = new Paragraph(this.getHeaderChunk(dateSpan));
    p2.setAlignment(Paragraph.ALIGN_LEFT);
    document.add(p2);
    document.add(new Phrase("\n"));

    if (dto.getData() != null) {
        PdfPTable table = createTable(dto.getData());
        document.add(table);
        document.add(new Phrase("\n"));
    }

    if (totalUsuario.size() > 0) {
        Paragraph p3 = new Paragraph(this.getHeaderChunk(this.getText("REPORTS_INSERTION_BY_DATE_USER_TOTAL")));
        p3.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p3);
        document.add(new Phrase("\n"));
        PdfPTable table = new PdfPTable(2);
        PdfPCell cell;
        cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_NAME"))));
        cell.setBackgroundColor(headerBgColor);
        cell.setBorderWidth(headerBorderWidth);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TOTAL"))));
        cell.setBackgroundColor(headerBgColor);
        cell.setBorderWidth(headerBorderWidth);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        for (String nome : totalUsuario.keySet()) {
            cell = new PdfPCell(new Paragraph(this.getNormalChunk(nome)));
            cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
            cell = new PdfPCell(new Paragraph(this.getNormalChunk(String.valueOf(totalUsuario.get(nome)))));
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            table.addCell(cell);
        }
        document.add(table);
        document.add(new Phrase("\n"));
    }

    //Database totals table
    Paragraph p3 = new Paragraph(
            this.getHeaderChunk(this.getText("REPORTS_INSERTION_BY_DATE_DATABASE_TOTALS")));
    p3.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(p3);
    document.add(new Phrase("\n"));
    PdfPTable table = new PdfPTable(3);
    PdfPCell cell;
    cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_DATABASE"))));
    cell.setBackgroundColor(headerBgColor);
    cell.setBorderWidth(headerBorderWidth);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_BIBLIO"))));
    cell.setBackgroundColor(headerBgColor);
    cell.setBorderWidth(headerBorderWidth);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_HOLDING"))));
    cell.setBackgroundColor(headerBgColor);
    cell.setBorderWidth(headerBorderWidth);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);

    cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_MAIN"))));
    cell.setBackgroundColor(headerBgColor);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    String biblio = dto.getTotalBiblioMain();
    biblio = biblio != null ? biblio : "";
    cell = new PdfPCell(new Paragraph(this.getNormalChunk(biblio)));
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    String tombos = dto.getTotalHoldingMain();
    tombos = tombos != null ? tombos : "";
    PdfPCell cell2 = new PdfPCell(new Paragraph(this.getNormalChunk(tombos)));
    cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell2);

    cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_WORK"))));
    cell.setBackgroundColor(headerBgColor);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    biblio = dto.getTotalBiblioWork();
    biblio = biblio != null ? biblio : "";
    cell = new PdfPCell(new Paragraph(this.getNormalChunk(biblio)));
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    tombos = dto.getTotalHoldingWork();
    tombos = tombos != null ? tombos : "";
    cell2 = new PdfPCell(new Paragraph(this.getNormalChunk(tombos)));
    cell2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell2);

    document.add(table);

}