Example usage for com.itextpdf.text.pdf PdfPTable addCell

List of usage examples for com.itextpdf.text.pdf PdfPTable addCell

Introduction

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

Prototype

public void addCell(final Phrase phrase) 

Source Link

Document

Adds a cell element.

Usage

From source file:com.devox.GUI.PDF.ExportarAPDF.java

private static PdfPTable createTable() {
    PdfPTable table = new PdfPTable(6);
    PdfPCell cell;/* w w w . ja  va2  s .c  om*/
    cell = new PdfPCell(new Phrase("DESCRIPCIN", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setFixedHeight(20f);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("LOTE", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CDIGO", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CANTIDAD", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRECIO UNITARIO", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("SUBTOTAL", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(AMARILLO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    try {
        table.setWidths(new float[] { 5f, 2f, 3f, 1.2f, 1.4f, 1.5f });
        table.setWidthPercentage(98);

    } catch (DocumentException ex) {
        Log.print(ex);
        Log.print(ex);
    }
    return table;
}

From source file:com.devox.GUI.PDF.ExportarAPDF.java

private static PdfPTable createSigningTable() {
    PdfPTable table = new PdfPTable(4);
    PdfPCell cell;//www.  j a  v  a 2  s.c  om
    cell = new PdfPCell(new Phrase("RMA", font_headertable2));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setFixedHeight(25f);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("ORDEN", font_headertable2));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("ELABOR", font_headertable2));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("DICTAMIN QA", font_headertable2));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("  "));
    cell.setFixedHeight(50f);
    for (int i = 0; i < 4; i++) {
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase("  "));
    cell.setFixedHeight(25f);
    cell.setBackgroundColor(GRIS_CLARO);
    for (int i = 0; i < 2; i++) {
        table.addCell(cell);
    }

    cell = new PdfPCell(new Phrase("NOMBRE Y FIRMA", font_table));
    cell.setFixedHeight(25f);
    cell.setBackgroundColor(GRIS_CLARO);
    for (int i = 0; i < 2; i++) {
        table.addCell(cell);
    }

    table.setTotalWidth(500);
    return table;
}

From source file:com.devox.GUI.PDF.ExportarAPDF.java

private PdfPTable setUpInformationTarimas() {
    PdfPTable table = new PdfPTable(2);
    try {//from w w w. j  a va  2  s. c o m
        PdfPCell cell;
        Phrase tarima = new Phrase();
        tarima.add(new Chunk("TARIMA\n", font_tarimota));
        tarima.add(new Chunk(datosTarima.getNombreTarima(), font_tarimota_gris));
        cell = new PdfPCell(tarima);
        cell.setRowspan(5);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        cell.setFixedHeight(200f);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("DIVISIN ", datosTarima.getDivision()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("ALMACN ", datosTarima.getAlmacen()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("FECHA DE APERTURA ",
                Funciones.getOtherDate(datosTarima.getFecha_Apertura())));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(
                getPhraseFromChunks("FECHA DE CIERRE ", Funciones.getOtherDate(datosTarima.getFecha_Cierra())));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("DESTRUCCIN FISCAL ",
                Integer.toString(datosTarima.getDestruccionFiscal())));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);

        table.setWidthPercentage(100);
        table.setWidths(new int[] { 2, 1 });
    } catch (DocumentException de) {
        Log.print(de);
    }
    return table;
}

From source file:com.devox.GUI.PDF.ExportarAPDF.java

private PdfPTable createTableTarimas() {
    PdfPTable table = new PdfPTable(4);
    PdfPCell cell;/*from w w w . jav  a  2s  .c o m*/
    cell = new PdfPCell(new Phrase("FOLIO DHL", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setFixedHeight(20f);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("PRODUCTO (Descripcin)", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CDIGO INTERNO", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase("CANTIDAD", font_headertable1));
    cell.setBackgroundColor(AMARILLO);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderColorLeft(GRIS_CLARO);
    cell.setBorderColorRight(GRIS_CLARO);
    cell.setBorderColorTop(AMARILLO);
    table.addCell(cell);

    try {
        table.setWidths(new float[] { 1f, 1.5f, 2.5f, 1f });
        table.setWidthPercentage(100);

    } catch (DocumentException ex) {
        Log.print(ex);
        Log.print(ex);
    }
    return table;
}

From source file:com.devox.GUI.PDF.ExportarAPDF.java

private void addProductosTarimas(PdfPTable table) {
    int rows = datosTarima.getListaProductos().size();
    int total = 0;

    for (int i = 0; i < rows; i++) {
        PdfPCell cell = new PdfPCell();
        cell.addElement(new Phrase(datosTarima.getListaProductos().get(i)[0]));

        table.addCell(cell);
        table.addCell(new Phrase(datosTarima.getListaProductos().get(i)[1]));

        table.addCell(new Phrase(datosTarima.getListaProductos().get(i)[2]));
        int c = Integer.parseInt(datosTarima.getListaProductos().get(i)[3]);
        total += c;/*from  w ww  . j  a v  a 2s .c  o  m*/
        table.addCell(datosTarima.getListaProductos().get(i)[3]);

    }
    table.addCell(new Phrase("  ", font_bottomtable));
    table.addCell(new Phrase("Total ", font_bottomtable));
    table.addCell(new Phrase("  ", font_bottomtable));
    table.addCell(new Phrase("" + total, font_bottomtable));

}

From source file:com.devox.GUI.PDF.ExportarAPDF.java

public void addProductos(DefaultTableModel model, PdfPTable table) {
    int rows = model.getRowCount();
    int total = 0;
    float monto = 0f;

    for (int i = 0; i < rows; i++) {
        PdfPCell cell = new PdfPCell();
        cell.addElement(new Phrase((String) model.getValueAt(i, 2)));

        table.addCell(cell);
        if (ANI) {
            String lote = ((String) model.getValueAt(i, 3));
            String[] l = lote.split("  ");
            String[] l2;/*  w w  w . j a v  a  2s  .  c  om*/
            l2 = l[0].split("00");

            table.addCell(l2[0]);

        } else {
            table.addCell((String) model.getValueAt(i, 3));
        }
        table.addCell((String) model.getValueAt(i, 1));
        int c = (Integer) model.getValueAt(i, 5);
        total += c;
        table.addCell(Integer.toString(c));
        table.addCell("$ " + model.getValueAt(i, 4).toString());
        Float p = new Float(model.getValueAt(i, 6).toString());
        monto += p;
        table.addCell("$ " + String.format("%.2f", p));
    }
    table.addCell(new Phrase("  ", font_bottomtable));
    table.addCell(new Phrase("Total ", font_bottomtable));
    table.addCell(new Phrase("  ", font_bottomtable));
    table.addCell(new Phrase("" + total, font_bottomtable));
    table.addCell(new Phrase("  ", font_bottomtable));
    table.addCell(new Phrase("$ " + String.format("%.2f", monto), font_bottomtable));

}

From source file:com.dexter.fms.mbean.ReportsMBean.java

@SuppressWarnings("unchecked")
public void createPDF(int type, String filename, int pageType) {
    try {//  w w w. jav a 2s  .  co m
        FacesContext context = FacesContext.getCurrentInstance();
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FMS");
        document.addCreationDate();
        document.addCreator("FMS");
        document.addSubject("Report");
        document.addTitle(getReport_title());

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        Hashtable<String, Object> params = new Hashtable<String, Object>();
        params.put("partner", dashBean.getUser().getPartner());
        GeneralDAO gDAO = new GeneralDAO();
        Object pSettingsObj = gDAO.search("PartnerSetting", params);
        PartnerSetting setting = null;
        if (pSettingsObj != null) {
            Vector<PartnerSetting> pSettingsList = (Vector<PartnerSetting>) pSettingsObj;
            for (PartnerSetting e : pSettingsList) {
                setting = e;
            }
        }
        gDAO.destroy();

        PdfPCell c = null;
        if (setting != null && setting.getLogo() != null) {
            Image logoImg = Image.getInstance(setting.getLogo());
            logoImg.scaleToFit(212, 51);
            c = new PdfPCell(logoImg);
        } else
            c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(getReport_title(), font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (getReport_start_dt() != null && getReport_end_dt() != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("From " + getReport_start_dt() + " to " + getReport_end_dt(), font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = exportPDFTable(type);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();
        String fileName = filename + ".pdf";

        writeFileToResponse(context.getExternalContext(), baos, fileName, "application/pdf");

        context.responseComplete();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dexter.fms.mbean.ReportsMBean.java

@SuppressWarnings("deprecation")
private PdfPTable exportPDFTable(int type) {
    int numberOfColumns = 0;
    PdfPTable pdfTable = null;
    switch (type) {
    case 1: // all users report
    {/*w  ww  .  j  ava 2s .c  o m*/
        numberOfColumns = 7;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("User name", font));
        pdfTable.addCell(new Paragraph("Full name", font));
        pdfTable.addCell(new Paragraph("Email", font));
        pdfTable.addCell(new Paragraph("Department", font));
        pdfTable.addCell(new Paragraph("Region", font));
        pdfTable.addCell(new Paragraph("Phone", font));
        pdfTable.addCell(new Paragraph("Position", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getAllUsers() != null) {
            for (PartnerUser e : getAllUsers()) {
                pdfTable.addCell(new Paragraph(e.getUsername(), font));
                pdfTable.addCell(new Paragraph(
                        e.getPersonel().getFirstname() + " " + e.getPersonel().getLastname(), font));
                pdfTable.addCell(new Paragraph(e.getPersonel().getEmail(), font));
                pdfTable.addCell(new Paragraph(
                        (e.getPersonel().getDepartment() != null) ? e.getPersonel().getDepartment().getName()
                                : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(
                        (e.getPersonel().getRegion() != null) ? e.getPersonel().getRegion().getName() : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(e.getPersonel().getPhone(), font));
                pdfTable.addCell(new Paragraph(e.getPersonel().getPosition(), font));
            }
        }
        break;
    }
    case 2: // due driver's license
    {
        numberOfColumns = 6;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Full Name", font));
        pdfTable.addCell(new Paragraph("Dept", font));
        pdfTable.addCell(new Paragraph("Region", font));
        pdfTable.addCell(new Paragraph("Phone", font));
        pdfTable.addCell(new Paragraph("Position", font));
        pdfTable.addCell(new Paragraph("License Due Date", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getDueDriversLic() != null) {
            for (DriverLicense e : getDueDriversLic()) {
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getFirstname() + " "
                        + e.getDriver().getPersonel().getLastname(), font));
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getDepartment() != null
                        ? e.getDriver().getPersonel().getDepartment().getName()
                        : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getRegion() != null
                        ? e.getDriver().getPersonel().getRegion().getName()
                        : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getPhone(), font));
                pdfTable.addCell(new Paragraph(e.getDriver().getPersonel().getPosition(), font));
                pdfTable.addCell(new Paragraph(e.getLic_end_dt().toLocaleString(), font));
            }
        }
        break;
    }
    case 3: // accidents
    {
        numberOfColumns = 8;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Accident Date", font));
        pdfTable.addCell(new Paragraph("Description", font));
        pdfTable.addCell(new Paragraph("Driver", font));
        pdfTable.addCell(new Paragraph("Driver Comment", font));
        pdfTable.addCell(new Paragraph("Police Officer", font));
        pdfTable.addCell(new Paragraph("Police Station", font));
        pdfTable.addCell(new Paragraph("Police Comment", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getVehicleAccidents() != null) {
            for (VehicleAccident e : getVehicleAccidents()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getAccident_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getAccidentDescription(), font));
                pdfTable.addCell(new Paragraph(e.getDriver_name(), font));
                pdfTable.addCell(new Paragraph(e.getDriverComment(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceOfficer(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceStation(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceComment(), font));
            }
        }
        break;
    }
    case 4: // vehicles by brand
    {
        numberOfColumns = 4;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Make", font));
        pdfTable.addCell(new Paragraph("Model", font));
        pdfTable.addCell(new Paragraph("Year", font));
        pdfTable.addCell(new Paragraph("Reg No.", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getVehiclesByBrand() != null) {
            for (Vehicle e : getVehiclesByBrand()) {
                pdfTable.addCell(new Paragraph(e.getModel().getMaker().getName(), font));
                pdfTable.addCell(new Paragraph(e.getModel().getName(), font));
                pdfTable.addCell(new Paragraph(e.getModel().getYear(), font));
                pdfTable.addCell(new Paragraph(e.getRegistrationNo(), font));
            }
        }
        break;
    }
    case 5: // routine maintenance
    {
        numberOfColumns = 8;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Requester", font));
        pdfTable.addCell(new Paragraph("Description", font));
        pdfTable.addCell(new Paragraph("Start Date", font));
        pdfTable.addCell(new Paragraph("Initial Cost", font));
        pdfTable.addCell(new Paragraph("Status", font));
        pdfTable.addCell(new Paragraph("Close Date", font));
        pdfTable.addCell(new Paragraph("Final Cost", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getRmaints() != null) {
            for (VehicleRoutineMaintenance e : getRmaints()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getCreatedBy().getPersonel().getFirstname() + " "
                        + e.getCreatedBy().getPersonel().getLastname(), font));
                pdfTable.addCell(new Paragraph(e.getDescription(), font));
                pdfTable.addCell(new Paragraph(e.getStart_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getInitial_amount().toPlainString(), font));
                pdfTable.addCell(new Paragraph(e.getStatus(), font));
                pdfTable.addCell(new Paragraph(e.getClose_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getClosed_amount().toPlainString(), font));
            }
        }
        break;
    }
    case 6: // ad hoc maintenance
    {
        numberOfColumns = 8;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Requester", font));
        pdfTable.addCell(new Paragraph("Description", font));
        pdfTable.addCell(new Paragraph("Start Date", font));
        pdfTable.addCell(new Paragraph("Initial Cost", font));
        pdfTable.addCell(new Paragraph("Status", font));
        pdfTable.addCell(new Paragraph("Close Date", font));
        pdfTable.addCell(new Paragraph("Final Cost", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getAdhocmaints() != null) {
            for (VehicleAdHocMaintenance e : getAdhocmaints()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getCreatedBy().getPersonel().getFirstname() + " "
                        + e.getCreatedBy().getPersonel().getLastname(), font));
                pdfTable.addCell(new Paragraph(e.getDescription(), font));
                pdfTable.addCell(new Paragraph(e.getStart_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getInitial_cost().toPlainString(), font));
                pdfTable.addCell(new Paragraph(e.getStatus(), font));
                pdfTable.addCell(new Paragraph(e.getClose_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getClosed_cost().toPlainString(), font));
            }
        }
        break;
    }
    case 7: // active accidents
    {
        numberOfColumns = 8;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Accident Date", font));
        pdfTable.addCell(new Paragraph("Description", font));
        pdfTable.addCell(new Paragraph("Driver Name", font));
        pdfTable.addCell(new Paragraph("Driver Comment", font));
        pdfTable.addCell(new Paragraph("Police Name", font));
        pdfTable.addCell(new Paragraph("Station Name", font));
        pdfTable.addCell(new Paragraph("Police Comment", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getActiveAccidents() != null) {
            for (VehicleAccident e : getActiveAccidents()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getAccident_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getAccidentDescription(), font));
                pdfTable.addCell(new Paragraph(e.getDriver_name(), font));
                pdfTable.addCell(new Paragraph(e.getDriverComment(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceOfficer(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceStation(), font));
                pdfTable.addCell(new Paragraph(e.getPoliceComment(), font));
            }
        }
        break;
    }
    case 8: // coporate trips
    {
        numberOfColumns = 9;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 6, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Requester", font));
        pdfTable.addCell(new Paragraph("Department", font));
        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Departure Location", font));
        pdfTable.addCell(new Paragraph("Arrival Location", font));
        pdfTable.addCell(new Paragraph("Departure Date and Time", font));
        pdfTable.addCell(new Paragraph("Est. Arrival Date and Time", font));
        pdfTable.addCell(new Paragraph("Act. Arrival Date and Time", font));
        pdfTable.addCell(new Paragraph("Status", font));

        font = new Font(helvetica, 6, Font.NORMAL);

        if (getCorTrips() != null) {
            for (CorporateTrip e : getCorTrips()) {
                pdfTable.addCell(
                        new Paragraph(e.getStaff().getFirstname() + " " + e.getStaff().getLastname(), font));
                pdfTable.addCell(new Paragraph(
                        (e.getStaff().getDepartment() != null) ? e.getStaff().getDepartment().getName() : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(
                        e.getVehicle() != null ? e.getVehicle().getRegistrationNo() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getDepartureLocation(), font));
                pdfTable.addCell(new Paragraph(e.getArrivalLocation(), font));
                pdfTable.addCell(new Paragraph(e.getDepartureDateTime().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getEstimatedArrivalDateTime().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(
                        e.getCompleteRequestDateTime() != null ? e.getCompleteRequestDateTime().toLocaleString()
                                : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(e.getTripStatus(), font));
            }
        }
        break;
    }
    case 9: // expense report
    {
        numberOfColumns = 4;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Type", font));
        pdfTable.addCell(new Paragraph("Date", font));
        pdfTable.addCell(new Paragraph("Amount", font));
        pdfTable.addCell(new Paragraph("Detail", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getExpenses() != null) {
            for (Expense e : getExpenses()) {
                pdfTable.addCell(new Paragraph(e.getType().getName(), font));
                pdfTable.addCell(new Paragraph(e.getExpense_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph("" + e.getAmount(), font));
                pdfTable.addCell(new Paragraph(e.getRemarks(), font));
            }
        }
        break;
    }
    case 10: // vehicle ages
    {
        numberOfColumns = 6;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Make", font));
        pdfTable.addCell(new Paragraph("Model", font));
        pdfTable.addCell(new Paragraph("Year", font));
        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Date of Purchase", font));
        pdfTable.addCell(new Paragraph("Age (in years)", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getVehiclesAges() != null) {
            for (Vehicle e : getVehiclesAges()) {
                pdfTable.addCell(new Paragraph(
                        e.getModel().getMaker() != null ? e.getModel().getMaker().getName() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getModel() != null ? e.getModel().getName() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getModel() != null ? e.getModel().getYear() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(
                        e.getPurchaseDate() != null ? e.getPurchaseDate().toLocaleString() : "N/A", font));
                pdfTable.addCell(new Paragraph("" + e.getAge(), font));
            }
        }
        break;
    }
    case 11: // vehicle fuelings
    {
        numberOfColumns = 5;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Date", font));
        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Litres", font));
        pdfTable.addCell(new Paragraph("Amount", font));
        pdfTable.addCell(new Paragraph("Source", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getFuelings() != null) {
            for (VehicleFueling e : getFuelings()) {
                pdfTable.addCell(new Paragraph(e.getCaptured_dt().toLocaleString(), font));
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph("" + e.getLitres(), font));
                pdfTable.addCell(new Paragraph("" + e.getAmt(), font));
                pdfTable.addCell(new Paragraph(e.getSource(), font));
            }
        }
        break;
    }
    case 12: // due vehicle licenses
    {
        numberOfColumns = 5;
        pdfTable = new PdfPTable(numberOfColumns);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        Font font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Reg No.", font));
        pdfTable.addCell(new Paragraph("Fleet", font));
        pdfTable.addCell(new Paragraph("Make", font));
        pdfTable.addCell(new Paragraph("Model", font));
        pdfTable.addCell(new Paragraph("License Due Date", font));

        font = new Font(helvetica, 8, Font.NORMAL);

        if (getDueVehicleLicenses() != null) {
            for (VehicleLicense e : getDueVehicleLicenses()) {
                pdfTable.addCell(new Paragraph(e.getVehicle().getRegistrationNo(), font));
                pdfTable.addCell(new Paragraph(e.getVehicle().getFleet().getName(), font));
                pdfTable.addCell(new Paragraph(
                        e.getVehicle().getModel() != null ? e.getVehicle().getModel().getMaker().getName()
                                : "N/A",
                        font));
                pdfTable.addCell(new Paragraph(
                        e.getVehicle().getModel() != null ? e.getVehicle().getModel().getName() : "N/A", font));
                pdfTable.addCell(new Paragraph(e.getLic_end_dt().toLocaleString(), font));
            }
        }
        break;
    }
    }

    pdfTable.setWidthPercentage(100);

    return pdfTable;
}

From source file:com.dexter.fuelcard.mbean.UtilMBean.java

public byte[] createInvoicePDF(int pageType, String title, String dateperiod, String amount, String chargeType,
        String chargeAmount, String total) {
    try {//from   ww w  .  j ava2  s  .com
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setPageEvent(new HeaderFooter());
        writer.setBoxSize("footer", new Rectangle(36, 54, 559, 788));
        if (!document.isOpen()) {
            document.open();
        }

        switch (pageType) {
        case 1:
            document.setPageSize(PageSize.A4);
            break;
        case 2:
            document.setPageSize(PageSize.A4.rotate());
            break;
        }
        document.addAuthor("FUELCARD");
        document.addCreationDate();
        document.addCreator("FUELCARD");
        document.addSubject("Invoice");
        document.addTitle(title);

        PdfPTable headerTable = new PdfPTable(1);

        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
                + File.separator + "satraklogo.jpg";

        PdfPCell c = new PdfPCell(Image.getInstance(logo));
        c.setBorder(0);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        headerTable.addCell(c);

        Paragraph stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        BaseFont helvetica = null;
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
            //font exception
        }
        Font font = new Font(helvetica, 16, Font.NORMAL | Font.BOLD);

        c = new PdfPCell(new Paragraph(title, font));
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);

        if (dateperiod != null) {
            stars = new Paragraph(20);
            stars.add(Chunk.NEWLINE);
            stars.setSpacingAfter(10);

            c = new PdfPCell(stars);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            c.setBorder(0);
            headerTable.addCell(c);

            new Font(helvetica, 12, Font.NORMAL);
            Paragraph ch = new Paragraph("For " + dateperiod, font);
            c = new PdfPCell(ch);
            c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            headerTable.addCell(c);
        }
        stars = new Paragraph(20);
        stars.add(Chunk.NEWLINE);
        stars.setSpacingAfter(20);

        c = new PdfPCell(stars);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setBorder(0);
        headerTable.addCell(c);
        document.add(headerTable);

        PdfPTable pdfTable = new PdfPTable(4);
        try {
            helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
        } catch (Exception e) {
        }
        font = new Font(helvetica, 8, Font.BOLDITALIC);

        pdfTable.addCell(new Paragraph("Charge Type", font)); // % per transaction or flat per license
        pdfTable.addCell(new Paragraph("Charge Amount", font)); // the amount of the charge setting

        if (chargeType.equalsIgnoreCase("Percent-Per-Tran")) {
            pdfTable.addCell(new Paragraph("Total Amount", font)); // the amount of the charge setting
        } else {
            pdfTable.addCell(new Paragraph("Total License", font)); // the amount of the charge setting
        }
        //pdfTable.addCell(new Paragraph("Description", font)); // the 
        pdfTable.addCell(new Paragraph("Amount Due", font));

        font = new Font(helvetica, 8, Font.NORMAL);
        pdfTable.addCell(new Paragraph(chargeType, font));
        pdfTable.addCell(new Paragraph(chargeAmount, font));
        pdfTable.addCell(new Paragraph(total, font));
        pdfTable.addCell(new Paragraph(amount, font));

        pdfTable.setWidthPercentage(100);
        if (pdfTable != null)
            document.add(pdfTable);

        //Keep modifying your pdf file (add pages and more)

        document.close();

        return baos.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.docdoku.server.extras.TitleBlockGenerator.java

License:Open Source License

protected void generateTable(Paragraph preface, ResourceBundle bundle) {
    // Author + date
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(TABLE_PERCENT_WIDTH);

    PdfPCell cell;/* w w w.  j  a v a  2 s  .c  o m*/

    cell = new PdfPCell(new Phrase(authorName, NORMAL_12));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(creationDate, NORMAL_12));
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    table.addCell(cell);

    preface.add(table);

    addEmptyLine(preface, 1);

    preface.add(new Paragraph(bundle.getString("iteration"), BOLD_12));
    addEmptyLine(preface, 1);

    PdfPTable iterationTable = new PdfPTable(5);
    iterationTable.setWidthPercentage(TABLE_PERCENT_WIDTH);

    // Table header
    cell = new PdfPCell(new Phrase(bundle.getString("iteration.version"), BOLD_12));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    iterationTable.addCell(cell);
    cell = new PdfPCell(new Phrase(bundle.getString("iteration.iteration"), BOLD_12));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    iterationTable.addCell(cell);
    cell = new PdfPCell(new Phrase(bundle.getString("iteration.date"), BOLD_12));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    iterationTable.addCell(cell);
    cell = new PdfPCell(new Phrase(bundle.getString("iteration.author"), BOLD_12));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    iterationTable.addCell(cell);
    cell = new PdfPCell(new Phrase(bundle.getString("iteration.Notes"), BOLD_12));
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    iterationTable.addCell(cell);

    // Table body
    cell = new PdfPCell(new Phrase(version, NORMAL_12));
    iterationTable.addCell(cell);
    cell = new PdfPCell(new Phrase(currentIteration, NORMAL_12));
    iterationTable.addCell(cell);
    cell = new PdfPCell(new Phrase(iterationDate, NORMAL_12));
    iterationTable.addCell(cell);
    cell = new PdfPCell(new Phrase(authorName, NORMAL_12));
    iterationTable.addCell(cell);
    cell = new PdfPCell(new Phrase(revisionNote, NORMAL_12));
    iterationTable.addCell(cell);

    preface.add(iterationTable);
}