Example usage for com.itextpdf.text Document add

List of usage examples for com.itextpdf.text Document add

Introduction

In this page you can find the example usage for com.itextpdf.text Document add.

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

From source file:com.leenmeij.app.utils.CreatePdf.java

/**
 * Create the content page of the PDF file
 * @param document/*from  www.  j  a va2s .c  o  m*/
 * @param invoice
 * @throws DocumentException
 */
private static void contentPage(Document document, Invoice invoice) throws DocumentException {
    // Get the customer information
    User user = new User();
    user = user.getById(invoice.getUser_id());

    // Create a chapter
    Chapter catPart = new Chapter(new Paragraph("LeenMeij Factuur gegevens", catFont), 1);

    // Add a sub paragraph
    Paragraph subParagraph = new Paragraph("Klantgegevens", subFont);
    Section subCatPart = catPart.addSection(subParagraph);

    // Set the user information
    subCatPart.add(new Paragraph("Naam: " + user.getFirstName() + " " + user.getLastName()));
    subCatPart.add(new Paragraph("Adres: " + user.getAddressLineOne() + " " + user.getAddressLineTwo()));
    subCatPart.add(new Paragraph("Woonplaats:" + user.getCity()));
    subCatPart.add(new Paragraph("Land: " + user.getCountry()));

    // Add another subparagraph
    subParagraph = new Paragraph("Huurgegevens:", subFont);
    subCatPart = catPart.addSection(subParagraph);
    // Format the date for showing purposes
    SimpleDateFormat format = new SimpleDateFormat("MM/dd/YYYY");
    // Add the dates
    subCatPart.add(new Paragraph("Startdatum: " + format.format(invoice.getStartdate())));
    subCatPart.add(new Paragraph("Einddatum: " + format.format(invoice.getEnddate())));

    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // add a table
    createTable(subCatPart, invoice);

    // now add all this to the document
    document.add(catPart);
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

private void createPdf(Map rpt, Map<String, String> i18n, File pdf) throws Exception {
    OutputStream out = new FileOutputStream(pdf);

    ThreadHelper.set("_fonts_", new HashMap<String, BaseFont>());
    ThreadHelper.set("_defaultFont_", BaseFont.createFont());

    String pageSize = MapUtil.getStr(rpt, "pageSize", "A4");
    int defaultFontSize = MapUtil.getInt(rpt, "defaultFontSize", 6);
    ThreadHelper.set("_defaultFontSize_", defaultFontSize);
    ThreadHelper.set("_rpt_", rpt);

    int i = pageSize.indexOf(';');
    String margins = "36 36 36 36";
    if (i > 0) {
        margins = pageSize.substring(i + 1);
        pageSize = pageSize.substring(0, i);
    }/*  w  w w . ja  v  a2  s.c om*/
    boolean rotate = false;
    if (pageSize.startsWith("@")) {
        rotate = true;
        pageSize = pageSize.substring(1);
    }
    Rectangle pSize = PageSize.getRectangle(pageSize);
    if (rotate)
        pSize = pSize.rotate();

    String mars[] = margins.split(" ");
    float ml = 0, mt = 0, mr = 0, mb = 0;
    mr = mt = mb = ml = LightUtil.decodeFloat(mars[0]);
    if (mars.length > 1) {
        mt = mb = LightUtil.decodeFloat(mars[1]);
    }
    if (mars.length > 2) {
        mr = LightUtil.decodeFloat(mars[2]);
    }
    if (mars.length > 3) {
        mb = LightUtil.decodeFloat(mars[3]);
    }
    Document doc = new Document(pSize, ml, mr, mt, mb);
    MapUtil.setIfStr(rpt, "author", doc, "addAuthor");
    MapUtil.setIfStr(rpt, "creator", doc, "addCreator");
    MapUtil.setIfStr(rpt, "title", doc, "addTitle");
    MapUtil.setIfStr(rpt, "keyWords", doc, "addKeywords");
    MapUtil.setIfStr(rpt, "subject", doc, "addSubject");

    PdfWriter writer = PdfWriter.getInstance(doc, out);
    writer.setPageEvent(this);
    writer.setStrictImageSequence(true);
    ThreadHelper.set("_writer_", writer);
    ThreadHelper.set("_doc_", doc);
    doc.open();

    List<Map> items = (List) rpt.get("items");
    for (Map row : items) {
        Element el = getElement(row);
        if (el != null)
            doc.add(el);
    }
    doc.close();
    out.close();
    writer.close();

    ThreadHelper.set("_writer_", null);
    ThreadHelper.set("_doc_", null);

}

From source file:com.maxl.java.amikodesk.SaveBasket.java

License:Open Source License

public void generatePdf(Author author, String filename, String type) {
    // A4: 8.267in x 11.692in => 595.224units x 841.824units (72units/inch)

    // marginLeft, marginRight, marginTop, marginBottom
    Document document = new Document(PageSize.A4, 50, 50, 80, 50);
    try {/*from www  .  j  a  v a2s .  c  o  m*/
        if (m_shopping_basket.size() > 0) {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
            writer.setBoxSize("art", new Rectangle(50, 50, 560, 790));

            HeaderFooter event = new HeaderFooter();
            writer.setPageEvent(event);

            document.open();

            PdfContentByte cb = writer.getDirectContent();

            document.addAuthor("ywesee GmbH");
            document.addCreator("AmiKo for Windows");
            document.addCreationDate();

            // Logo
            String logoImageStr = m_prefs.get(LogoImageID, Constants.IMG_FOLDER + "empty_logo.png");
            File logoFile = new File(logoImageStr);
            if (!logoFile.exists())
                logoImageStr = Constants.IMG_FOLDER + "empty_logo.png";

            Image logo = Image.getInstance(logoImageStr);
            logo.scalePercent(30);
            logo.setAlignment(Rectangle.ALIGN_RIGHT);
            document.add(logo);
            document.add(Chunk.NEWLINE);

            // Bestelladresse
            // --> String bestellAdrStr = m_prefs.get(BestellAdresseID, m_rb.getString("noaddress1")); 
            String bestellAdrStr = getAddressAsString(BestellAdresseID);
            Paragraph p = new Paragraph(12);
            // p.setIndentationLeft(60);
            p.add(new Chunk(bestellAdrStr, font_norm_10));
            document.add(p);
            document.add(Chunk.NEWLINE);

            // Title
            p = new Paragraph(m_rb.getString("order"), font_bold_16);
            document.add(p);

            // Date
            DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
            Date date = new Date();
            p = new Paragraph(m_rb.getString("date") + ": " + dateFormat.format(date), font_bold_10);
            p.setSpacingAfter(20);
            document.add(p);

            // document.add(Chunk.NEWLINE);

            // Add addresses (Lieferadresse + Rechnungsadresse)
            /* --> OLD
            String lieferAdrStr = m_prefs.get(LieferAdresseID, m_rb.getString("noaddress2"));
            String rechnungsAdrStr = m_prefs.get(RechnungsAdresseID, m_rb.getString("noaddress3"));              
            */
            // --> NEW
            String lieferAdrStr = getAddressAsString(LieferAdresseID);
            String rechnungsAdrStr = getAddressAsString(RechnungsAdresseID);

            PdfPTable addressTable = new PdfPTable(new float[] { 1, 1 });
            addressTable.setWidthPercentage(100f);
            addressTable.getDefaultCell().setPadding(5);
            addressTable.setSpacingAfter(5f);
            addressTable.addCell(getStringCell(m_rb.getString("shipaddress"), font_bold_10, PdfPCell.NO_BORDER,
                    Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(getStringCell(m_rb.getString("billaddress"), font_bold_10, PdfPCell.NO_BORDER,
                    Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(
                    getStringCell(lieferAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
            addressTable.addCell(
                    getStringCell(rechnungsAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1));
            document.add(addressTable);

            document.add(Chunk.NEWLINE);

            // Add shopping basket
            if (type.equals("specific"))
                document.add(getShoppingBasketForAuthor(author, cb));
            else if (type.equals("all"))
                document.add(getFullShoppingBasket(cb, "all"));
            else if (type.equals("rest"))
                document.add(getFullShoppingBasket(cb, "rest"));
            LineSeparator separator = new LineSeparator();
            document.add(separator);
        }
    } catch (IOException e) {

    } catch (DocumentException e) {

    }

    document.close();
    // System.out.println("Saved PDF to " + filename);
}

From source file:com.microware.intrahealth.Createpdf2.java

private static void addTitlePage(Document document) throws DocumentException {

    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/* ww w.j a va  2 s .  co m*/
    // Lets write a big header
    preface.add(new Paragraph("Break Even Master Input", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Community profile", subFont));
    //      addEmptyLine(preface, 3);
    //      preface.add(new Paragraph("This document describes something which is very important ",
    //            smallBold));
    //
    //      addEmptyLine(preface, 8);
    //
    //      preface.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:com.microware.intrahealth.Createpdf2.java

private static void addContent(Document document, String Header[], ArrayList<HashMap<String, String>> data,
        String[] sHeader2, int Flag) throws Exception {

    Paragraph preface = new Paragraph();

    //  preface.setAlignment(Element.ALIGN_CENTER);

    addEmptyLine(preface, 1);//  w w  w .ja va  2  s . c  o  m
    preface.add(mypara(sHeader[0], 1));
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader[1], 1));
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader[2], 2));
    addEmptyLine(preface, 1);
    createTable(preface, Header, data);
    preface.add(mypara(sHeader2[0], 2));
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader2[1] + " " + data.size(), 2));
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader2[2] + " " + data.size(), 2));
    addEmptyLine(preface, 1);
    addEmptyLine(preface, 1);
    preface.add(mypara(sHeader2[3], 3));
    addEmptyLine(preface, 1);

    //

    document.add(preface);

}

From source file:com.microware.intrahealth.Createpdfall.java

private static void addContent(Document document, String Header1[], String[] Page1, String[] Page1Value,
        String heading1, String Page1Remark,

        String[] Header2, String[] Page2_1, String[] Page2_1source, String[] Page2_1value, String[] Page2_2,
        String[] Page2_2source, String[] Page2_2value, String[] Page2_3, String[] Page2_3source,
        String[] Page2_3value, String heading2, String heading3, String heading4, String heading5,
        String Remark2Value,/*ww w.j  ava  2 s .  c  o m*/

        String[] Header3, String[] Page31, String[] Page3Census1, String[] Page3Value1, String[] Page32,
        String[] Page3Census2, String[] Page3Value2, String heading6, String heading7, String heading8,
        String Page3Remark,

        String[] Header4, String[] Page4_1, String[] Page4Value1, String[] Page4_2, String[] Page4Value2,
        String[] Page4_3, String[] Page4Value3, String heading9, String heading10, String heading11,
        String heading12, String Page4Remark1, String Page4Remark3,

        String[] Header5, String[] Page5Value1, String[] Page5Value2, String[] Page5Value3,
        String[] Page5Value4, String[] Page5_2, String[] Page5Value5, String[] Page5_3, String[] Page5Value6,
        String text5, String value5, String heading13, String heading14, String heading15, String Page5Remark1,
        String Page5Remark2,

        String[] Header6, String[] Page6Value1, String[] Page6Value2, String[] Page6Value3,
        String[] Page6Value4, String text6, String value6, String heading16,

        String[] Header7_1, String[] Page7Value1, String[] Page7Value2, String[] Page7Value3,
        String[] Page7Value4, String[] Page7Value5, String[] Header7_2, String[] Page7Value6,
        String[] Page7Value7, String[] Page7Value8, String[] Page7Value9, String[] Page7Value10,
        String[] Page7Value11, String text7_1, String value7_1, String text7_2, String value7_2,
        String heading17, String heading18, String heading19, String pdf1, String pdf2, int Flag)
        throws Exception {

    Paragraph preface = new Paragraph();
    Image img;
    sHeader[0] = "Question";
    sHeader[1] = "Source";
    sHeader[2] = "Data";

    // We add one empty line

    if (iflag == 26) {
        iflag = 0;
    }

    if (Flag == 2) {

    }

    if (iflag == 0) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(pdf1, catFont1));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(pdf2, catFont2));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading1, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page1, Page1Value);
        addEmptyLine(preface, 1);
        iflag = 1;
    }
    if (iflag == 1) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page1Remark);
        addEmptyLine(preface, 1);
        iflag = 2;
    }

    if (iflag == 2) {
        preface.add(new Paragraph(heading2, catFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header2, Page2_1, Page2_1source, Page2_1value);
        addEmptyLine(preface, 1);
        iflag = 3;
    }
    if (iflag == 3) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading3, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading4, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header2, Page2_2, Page2_2source, Page2_2value);
        addEmptyLine(preface, 1);
        iflag = 4;
    }
    if (iflag == 4) {
        preface.add(new Paragraph(heading5, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header2, Page2_3, Page2_3source, Page2_3value);
        addEmptyLine(preface, 1);
        iflag = 5;
    }
    if (iflag == 5) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Remark2Value);
        addEmptyLine(preface, 1);
        iflag = 6;
    }

    if (iflag == 6) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading6, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading7, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header3, Page31, Page3Census1, Page3Value1);
        addEmptyLine(preface, 1);
        iflag = 7;
    }
    if (iflag == 7) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page3Remark);
        addEmptyLine(preface, 1);
        iflag = 8;
    }
    if (iflag == 8) {
        preface.add(new Paragraph(heading8, subFont));
        addEmptyLine(preface, 1);
        createTable2(preface, Header3, Page32, Page3Census2, Page3Value2);
        addEmptyLine(preface, 1);
        iflag = 9;
    }

    if (iflag == 9) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading9, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page4_1, Page4Value1);
        addEmptyLine(preface, 1);
        iflag = 10;
    }
    if (iflag == 10) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page4Remark1);
        addEmptyLine(preface, 1);
        iflag = 11;
    }
    if (iflag == 11) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading10, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading11, subFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page4_2, Page4Value2);
        addEmptyLine(preface, 1);
        iflag = 12;
    }
    if (iflag == 12) {
        preface.add(new Paragraph(heading12, subFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page4_3, Page4Value3);
        addEmptyLine(preface, 1);
        iflag = 13;
    }
    if (iflag == 13) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page4Remark3);
        addEmptyLine(preface, 1);
        iflag = 14;
    }

    if (iflag == 14) {
        preface.add(new Paragraph(heading13, catFont));
        addEmptyLine(preface, 1);
        createTable3(preface, Header5, Page5Value1, Page5Value2, Page5Value3, Page5Value4);
        addEmptyLine(preface, 1);
        iflag = 15;
    }
    if (iflag == 15) {
        createTable7(preface, text5, value5);
        addEmptyLine(preface, 1);
        iflag = 16;
    }
    if (iflag == 16) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading14, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page5_2, Page5Value5);
        addEmptyLine(preface, 1);
        iflag = 17;
    }
    if (iflag == 17) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page5Remark1);
        addEmptyLine(preface, 1);
        iflag = 18;
    }
    if (iflag == 18) {
        preface.add(new Paragraph(heading15, catFont));
        addEmptyLine(preface, 1);
        createTable1(preface, Header1, Page5_3, Page5Value6);
        addEmptyLine(preface, 1);
        iflag = 19;
    }
    if (iflag == 19) {
        addEmptyLine(preface, 1);
        createTable7(preface, text7_2, Page5Remark2);
        addEmptyLine(preface, 1);
        iflag = 20;
    }

    if (iflag == 20) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading16, catFont));
        addEmptyLine(preface, 1);
        createTable3(preface, Header6, Page6Value1, Page6Value2, Page6Value3, Page6Value4);
        addEmptyLine(preface, 1);
        iflag = 21;
    }
    if (iflag == 21) {
        createTable7(preface, text6, value6);
        addEmptyLine(preface, 1);
        iflag = 22;
    }

    if (iflag == 22) {
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading17, catFont));
        addEmptyLine(preface, 1);
        preface.add(new Paragraph(heading18, subFont));
        addEmptyLine(preface, 1);
        createTable4(preface, Header1, text7_1, value7_1);
        addEmptyLine(preface, 1);
        iflag = 23;
    }
    if (iflag == 23) {
        createTable5(preface, Header7_1, Page7Value1, Page7Value2, Page7Value3, Page7Value4, Page7Value5);
        addEmptyLine(preface, 1);
        iflag = 24;
    }
    if (iflag == 24) {
        preface.add(new Paragraph(heading19, subFont));
        addEmptyLine(preface, 1);
        createTable6(preface, Header7_2, Page7Value6, Page7Value7, Page7Value8, Page7Value9, Page7Value10,
                Page7Value11);
        addEmptyLine(preface, 1);
        iflag = 25;
    }
    if (iflag == 25) {
        createTable7(preface, text7_2, value7_2);
        addEmptyLine(preface, 1);
        iflag = 26;
    }

    document.add(preface);

}

From source file:com.mim.controllers.HomeCtrl.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3//www.j av a2 s  .  c  o  m

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    String area;
    if (lugar.getNombre().contains("linea")) {
        area = "envasado";
    } else if (lugar.getNombre().contains("otro")) {
        area = "Tecate 500";
    } else if (lugar.getNombre().contains("PD")) {
        area = "concretos";
    } else if (lugar.getNombre().contains("planta agua")) {
        area = "cerveceria";
    } else {
        area = "elaboracion";
    }

    PdfPCell areaValor = new PdfPCell(new Paragraph(area));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                PdfPCell paramCell = new PdfPCell();
                paramCell.setColspan(3);
                paramCell.addElement(new Paragraph(historial.getParametro()));
                paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                paramCell.setPaddingLeft(10);
                paramCell.setPaddingBottom(10);

                PdfPCell valueParamCell = new PdfPCell();
                valueParamCell.setColspan(5);
                valueParamCell.setPaddingLeft(10);
                valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                valueParamCell.addElement(new Paragraph(historial.getValor()));
                valueParamCell.setPaddingBottom(10);

                if (historial.getValor() != null) {
                    if (historial.getValor().length() > 0) {
                        table.addCell(paramCell);
                        table.addCell(valueParamCell);
                    }
                }
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.mim.controllers.OrdenCtrl.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3/*from  ww  w  .  jav a2  s.  co  m*/

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    PdfPCell areaValor = new PdfPCell(new Paragraph("concretera"));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                PdfPCell paramCell = new PdfPCell();
                paramCell.setColspan(3);
                paramCell.addElement(new Paragraph(historial.getParametro()));
                paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                paramCell.setPaddingLeft(10);
                paramCell.setPaddingBottom(10);

                PdfPCell valueParamCell = new PdfPCell();
                valueParamCell.setColspan(5);
                valueParamCell.setPaddingLeft(10);
                valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                valueParamCell.addElement(new Paragraph(historial.getValor()));
                valueParamCell.setPaddingBottom(10);

                table.addCell(paramCell);
                table.addCell(valueParamCell);
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.mim.servlet.ReportGen.java

private void ordenReport(Document document, Lugar lugar)
        throws BadElementException, DocumentException, IOException {
    document.addTitle(current.getNumeroOrden());
    // step 3/*from  ww w .j a va 2s .c  om*/

    // step 4
    PdfPTable table = new PdfPTable(8);

    //LEFT HEADER CONTENT
    PdfPTable leftHeaderTable = new PdfPTable(4);

    PdfPCell imgCell = new PdfPCell();
    imgCell.setBorder(Rectangle.NO_BORDER);
    imgCell.setPaddingTop(14);
    imgCell.setColspan(1);
    imgCell.setFixedHeight(25);

    //Image img = Image.getInstance("/opt/shared/home/logo.png");
    Image img = Image.getInstance("http://mimconstructions.com/img/mim%20trendy.png");

    imgCell.addElement(img);

    PdfPCell reportTitleCell = new PdfPCell(new Paragraph("REPORTE MANTENIMIENTO"));
    reportTitleCell.setPaddingTop(14);
    reportTitleCell.setPaddingLeft(20);
    reportTitleCell.setColspan(3);
    reportTitleCell.setBorder(Rectangle.NO_BORDER);

    leftHeaderTable.addCell(imgCell);
    leftHeaderTable.addCell(reportTitleCell);

    PdfPCell leftHeaderMainCell = new PdfPCell(leftHeaderTable);
    leftHeaderMainCell.setColspan(4);

    //END CONTENT
    //RIGHT HEADER WITH INFO ABOUT ORDER AND DATE
    PdfPTable infHeader = new PdfPTable(3);

    PdfPCell numberOrderLabel = new PdfPCell(new Paragraph("#ORDEN"));
    numberOrderLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderLabel.setColspan(1);
    String numeroOrden = null;
    if (current.getNumeroOrden() != null) {
        numeroOrden = current.getNumeroOrden();
    } else {
        numeroOrden = current.getActividad();
    }

    PdfPCell numberOrderValue = new PdfPCell(new Paragraph(numeroOrden));
    numberOrderValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    numberOrderValue.setColspan(2);

    PdfPCell prioridadLabel = new PdfPCell(new Paragraph("PRIORIDAD"));
    prioridadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadLabel.setColspan(1);

    PdfPCell prioridadValue = new PdfPCell(new Paragraph(current.getPrioridad()));
    prioridadValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    prioridadValue.setColspan(2);

    PdfPCell fechaLabel = new PdfPCell(new Paragraph("FECHA"));
    fechaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaLabel.setColspan(1);
    //dd-MM-yyyy
    SimpleDateFormat format1 = new SimpleDateFormat("dd-MM-yyyy");
    Date startDate = current.getStartDate();
    if (startDate == null) {
        startDate = new Date();
    }
    String fecha = format1.format(startDate);

    PdfPCell fechaValue = new PdfPCell(new Paragraph(fecha));
    fechaValue.setHorizontalAlignment(Element.ALIGN_CENTER);
    fechaValue.setColspan(2);

    infHeader.addCell(numberOrderLabel);
    infHeader.addCell(numberOrderValue);
    infHeader.addCell(prioridadLabel);
    infHeader.addCell(prioridadValue);
    infHeader.addCell(fechaLabel);
    infHeader.addCell(fechaValue);

    PdfPCell cellHeaderRight = new PdfPCell(infHeader);
    cellHeaderRight.setColspan(4);
    //END HEADER

    PdfPCell areaLabel = new PdfPCell(new Paragraph("AREA"));
    areaLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    areaLabel.setFixedHeight(30);
    areaLabel.setPaddingTop(5);
    areaLabel.setColspan(2);

    PdfPCell actividadLabel = new PdfPCell(new Paragraph("ACTIVIDAD"));
    actividadLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setFixedHeight(30);
    actividadLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    actividadLabel.setPaddingTop(5);
    actividadLabel.setColspan(3);

    PdfPCell responsableLabel = new PdfPCell(new Paragraph("RESPONSABLE DE OPERACION"));
    responsableLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setFixedHeight(30);
    responsableLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    responsableLabel.setPaddingTop(5);
    responsableLabel.setColspan(3);

    PdfPCell areaValor = new PdfPCell(new Paragraph("concretera"));
    areaValor.setFixedHeight(25);
    areaValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    areaValor.setColspan(2);

    PdfPCell actividadValor = new PdfPCell(new Paragraph(current.getActividad()));
    actividadValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    actividadValor.setFixedHeight(25);
    actividadValor.setColspan(3);

    PdfPCell responsableValor = new PdfPCell(new Paragraph(current.getEncargado()));
    responsableValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    responsableValor.setFixedHeight(25);
    responsableValor.setColspan(3);

    // 2 FILAS PARA INF. EQUIPO Y LUGAR
    PdfPCell equipoLabel = new PdfPCell(new Paragraph("EQUIPO/CONJUNTO"));
    equipoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    equipoLabel.setFixedHeight(30);
    equipoLabel.setPaddingTop(5);
    equipoLabel.setColspan(4);

    PdfPCell lugarLabel = new PdfPCell(new Paragraph("LUGAR"));
    lugarLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setFixedHeight(30);
    lugarLabel.setVerticalAlignment(Element.ALIGN_CENTER);
    lugarLabel.setPaddingTop(5);
    lugarLabel.setColspan(4);

    String numeroEquipo = null;
    if (equipo.getNumeroEquipo() != null) {
        numeroEquipo = equipo.getNumeroEquipo();
    } else {
        numeroEquipo = "n/a";
    }

    PdfPCell equipoValor = new PdfPCell(new Paragraph(numeroEquipo));
    equipoValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    equipoValor.setFixedHeight(25);
    equipoValor.setColspan(4);

    PdfPCell lugarValor = new PdfPCell(new Paragraph(lugar.getNombre()));
    lugarValor.setHorizontalAlignment(Element.ALIGN_CENTER);
    lugarValor.setFixedHeight(25);
    lugarValor.setColspan(4);

    //END INFO EQUIPO
    // 4 ROW and 5 ROW
    PdfPCell descripcionLabel = new PdfPCell(new Paragraph("DESCRIPCION"));
    descripcionLabel.setPadding(12);
    descripcionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    descripcionLabel.setColspan(8);

    PdfPCell descripcionValor = new PdfPCell(new Paragraph(current.getDescripcion()));
    descripcionValor.setPadding(10);
    descripcionValor.setColspan(8);
    //END ROWS

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell historialLabel = new PdfPCell(new Paragraph("OBSERVACIONES"));
    historialLabel.setPadding(12);
    historialLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    historialLabel.setColspan(8);
    //END HISTORIAL

    table.addCell(leftHeaderMainCell);
    table.addCell(cellHeaderRight);
    table.addCell(areaLabel);
    table.addCell(actividadLabel);
    table.addCell(responsableLabel);

    table.addCell(areaValor);
    table.addCell(actividadValor);
    table.addCell(responsableValor);
    table.addCell(equipoLabel);
    table.addCell(lugarLabel);
    table.addCell(equipoValor);
    table.addCell(lugarValor);
    table.addCell(descripcionLabel);
    table.addCell(descripcionValor);

    List<HistorialDetalles> observaciones = hisFacade.findAllByOrder(current.getIdorden());

    if (observaciones != null) {
        if (observaciones.size() > 0) {
            table.addCell(historialLabel);

            //LOOP HISTORIAL_DETALLES
            for (int i = 0; i < observaciones.size(); i++) {
                HistorialDetalles historial = observaciones.get(i);

                if (historial.getValor() != null) {
                    if (historial.getValor().length() > 0) {
                        PdfPCell paramCell = new PdfPCell();
                        paramCell.setColspan(3);
                        paramCell.addElement(new Paragraph(historial.getParametro()));
                        paramCell.setVerticalAlignment(Element.ALIGN_CENTER);
                        paramCell.setPaddingLeft(10);
                        paramCell.setPaddingBottom(10);

                        PdfPCell valueParamCell = new PdfPCell();
                        valueParamCell.setColspan(5);
                        valueParamCell.setPaddingLeft(10);
                        valueParamCell.setVerticalAlignment(Element.ALIGN_CENTER);
                        valueParamCell.addElement(new Paragraph(historial.getValor()));
                        valueParamCell.setPaddingBottom(10);

                        table.addCell(paramCell);
                        table.addCell(valueParamCell);
                    }
                }
            }
        }
    }
    //END LOOP HISTORIAL

    // FIRST ROWS OF FOTOGRAPHIC REPORT
    PdfPCell pasoLabel = new PdfPCell(new Paragraph("PASO"));
    pasoLabel.setFixedHeight(20);
    pasoLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    pasoLabel.setColspan(1);

    PdfPCell accionLabel = new PdfPCell(new Paragraph("ACCION"));
    accionLabel.setFixedHeight(20);
    accionLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    accionLabel.setColspan(3);

    PdfPCell imagenLabel = new PdfPCell(new Paragraph("IMAGENES"));
    imagenLabel.setFixedHeight(20);
    imagenLabel.setHorizontalAlignment(Element.ALIGN_CENTER);
    imagenLabel.setColspan(4);
    //END ROWS

    PdfPTable table2 = new PdfPTable(8);

    //ROW BEFORE HISTORIAL_DETALLES
    PdfPCell headerPictures = new PdfPCell(new Paragraph("PROCEDIMIENTO"));
    headerPictures.setPadding(12);
    headerPictures.setHorizontalAlignment(Element.ALIGN_CENTER);
    headerPictures.setColspan(8);

    table2.addCell(headerPictures);
    //END HISTORIAL

    table2.addCell(pasoLabel);
    table2.addCell(accionLabel);
    table2.addCell(imagenLabel);

    //fotos loop
    List<Fotos> fotos = fotoFacade.findAllByOrder(current.getIdorden());

    for (int i = 0; i < fotos.size(); i++) {
        Fotos foto = fotos.get(i);
        PdfPCell pasoVal = new PdfPCell(new Paragraph(String.valueOf(i)));
        pasoVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        pasoVal.setColspan(1);

        PdfPCell detail = new PdfPCell(new Paragraph(foto.getTitulo()));
        detail.setPadding(5);
        detail.setBorder(Rectangle.NO_BORDER);

        PdfPCell accionVal = new PdfPCell();
        accionVal.addElement(new Paragraph(foto.getDescripcion()));
        accionVal.setHorizontalAlignment(Element.ALIGN_CENTER);
        accionVal.setBorder(Rectangle.NO_BORDER);
        //accionVal.setColspan(3);

        PdfPTable infoTable = new PdfPTable(1);
        infoTable.addCell(detail);
        infoTable.addCell(accionVal);

        PdfPCell infiCell = new PdfPCell();
        infiCell.setColspan(3);
        infiCell.addElement(infoTable);

        //Table collumn
        //System.getenv("OPENSHIFT_DATA_DIR") + "imagenes/" + name)
        //Image imgFoto = Image.getInstance("http://mantenimiento-contactres.rhcloud.com/MantenimientoRest/webresources/com.mim.entities.fotos/api/" + foto.getIdfotos());
        String archivo = foto.getArchivo();
        String[] split = archivo.split("/");
        int size = split.length;
        final String name = split[size - 1];
        System.out.println("Valor " + name);

        Image imgFoto = Image.getInstance("/opt/shared/home/" + "imagenes/" + name);

        PdfPTable imagenTable = new PdfPTable(1);

        PdfPCell fotoCell = new PdfPCell();
        fotoCell.setColspan(1);
        fotoCell.addElement(imgFoto);
        fotoCell.setFixedHeight(310);
        fotoCell.setHorizontalAlignment(Element.ALIGN_CENTER);
        fotoCell.setBorder(Rectangle.NO_BORDER);

        imagenTable.addCell(fotoCell);

        PdfPCell imagenVal = new PdfPCell();
        imagenVal.setColspan(4);
        imagenVal.addElement(imagenTable);

        table2.addCell(pasoVal);
        table2.addCell(infiCell);
        table2.addCell(imagenVal);
    }
    //end loop

    //table.addCell(tiempoLabel);
    document.add(table);
    document.newPage();
    document.add(table2);
}

From source file:com.miraflorescarwash.controller.PdfController.java

private void crearPdfLavadasPendientes(Document doc, List<Lavada> lavadas) {
    Paragraph parrafo;/*from   w  w  w  . ja  v  a2s. co m*/
    PdfPTable tabla;
    String txt;
    PdfPCell cell;
    Phrase frase;
    String fuente;
    int i;
    JFreeChart chart;
    int w, h;
    int pos;
    pos = 0;
    w = h = 500;

    fuente = "arial";
    if (lavadas.isEmpty()) {
        return;
    }
    try {
        //

        // Se abre el documento.
        doc.open();

        txt = "Miraflores Car Wash";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 10, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_LEFT);
        doc.add(parrafo);

        txt = "Lavadas Pendientes";
        parrafo = new Paragraph(txt, FontFactory.getFont(fuente, 30, Font.BOLD, BaseColor.BLACK));
        parrafo.setAlignment(Element.ALIGN_CENTER);

        doc.add(parrafo);
        LineSeparator ls = new LineSeparator();
        doc.add(new Chunk(ls));

        tabla = new PdfPTable(3);

        frase = new Phrase("Id", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Fecha", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Placa de Carro", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Modelo de Carro", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        frase = new Phrase("Cliente", FontFactory.getFont(fuente, 12, Font.BOLD, BaseColor.WHITE));
        cell = new PdfPCell(frase);
        cell.setBackgroundColor(BaseColor.RED);
        tabla.addCell(cell);

        i = 1;

        for (Lavada lavada : lavadas) {

            if (i % 2 == 0) {
                cell = new PdfPCell();
                cell.setBackgroundColor(new BaseColor(244, 119, 119));

                frase = new Phrase(lavada.getId() + "");
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(lavada.getFechaLavado() + "");
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(lavada.getCarro().getPlaca());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(lavada.getCarro().getModelo().getNombre());
                cell.setPhrase(frase);
                tabla.addCell(cell);

                frase = new Phrase(lavada.getCarro().getCliente().getApellidos() + ", "
                        + lavada.getCarro().getCliente().getNombres());
                cell.setPhrase(frase);
                tabla.addCell(cell);

            } else {
                tabla.addCell(lavada.getId() + "");
                tabla.addCell(lavada.getFechaLavado() + "");
                tabla.addCell(lavada.getCarro().getPlaca());
                tabla.addCell(lavada.getCarro().getModelo().getNombre());
                tabla.addCell(lavada.getCarro().getCliente().getApellidos() + ", "
                        + lavada.getCarro().getCliente().getNombres());
            }
            i++;
        }
        doc.add(tabla);

        doc.close();
    } catch (DocumentException ex) {

    }
}