Example usage for com.itextpdf.text.pdf PdfPCell setMinimumHeight

List of usage examples for com.itextpdf.text.pdf PdfPCell setMinimumHeight

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setMinimumHeight.

Prototype

public void setMinimumHeight(float minimumHeight) 

Source Link

Document

Set a minimum height for the cell.

Usage

From source file:net.digitstar.vanadio.helpers.PdfHelper.java

License:Apache License

public static PdfPCell newCell(CellStyle style) {
    PdfPCell cell = new PdfPCell();
    if (style != null) {
        if (style.getNestedTable() != null) {
            cell = new PdfPCell(style.getNestedTable());
            style.setNestedTable(null);/*w w w .  j ava 2 s .  c  o  m*/
        } else if (style.getImage() != null) {
            cell = new PdfPCell(style.getImage(), style.isFitImage());
            style.setImage(null);
        } else if (style.getText() != null) {
            cell = new PdfPCell(style.getText());
            style.setText((String) null);
        }

        cell.setColspan(style.getColspan());
        cell.setRowspan(style.getRowspan());

        cell.setMinimumHeight(style.getMinimumHeight());
        cell.setFixedHeight(style.getFixedHeight());

        cell.setNoWrap(style.isNoWrap());

        cell.setRotation(style.getRotation().getValue());

        style = Alignment.assign(style);

        cell.setHorizontalAlignment(style.getHorizAlign().getValue());
        cell.setVerticalAlignment(style.getVertAlign().getValue());

        cell.setUseVariableBorders(style.isUseVariableBorders());
        cell.setUseBorderPadding(style.isUseBorderPadding());

        if (!style.getBorderWidth().isAllSideEqual()) {
            cell.setBorderWidthBottom(style.getBorderWidth().getBottom());
            cell.setBorderWidthLeft(style.getBorderWidth().getLeft());
            cell.setBorderWidthRight(style.getBorderWidth().getRight());
            cell.setBorderWidthTop(style.getBorderWidth().getTop());
        } else {
            cell.setBorderWidth(style.getBorderWidth().getValue());
        }

        cell.setPaddingBottom(style.getPadding().getBottom());
        cell.setPaddingLeft(style.getPadding().getLeft());
        cell.setPaddingRight(style.getPadding().getRight());
        cell.setPaddingTop(style.getPadding().getTop());

        cell.setBorderColorBottom(style.getBorderColor().getBottom());
        cell.setBorderColorLeft(style.getBorderColor().getLeft());
        cell.setBorderColorRight(style.getBorderColor().getRight());
        cell.setBorderColorTop(style.getBorderColor().getTop());

        cell.setBorder(style.getBorder().getValue());

        cell.setBackgroundColor(style.getBackgroundColor());
        if (style.getGreyFill() >= 0) {
            cell.setGrayFill(style.getGreyFill());
        }
    }
    return cell;
}

From source file:nl.avans.C3.BusinessLogic.InvoiceService.java

private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) {
    //create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));
    //set the cell alignment
    cell.setHorizontalAlignment(align);/* w  w w.  j a  va  2  s .c  o  m*/
    //set the cell column span in case you want to merge two or more cells
    cell.setColspan(colspan);
    //in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }
    //add the call to the table
    table.addCell(cell);
}

From source file:org.cidte.sii.negocio.PDFWriter.java

private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) {

    // create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));
    // set the cell alignment
    cell.setHorizontalAlignment(align);//  ww  w  .j a v  a  2 s  .c  o m

    // some padding
    cell.setPaddingLeft(10);

    // set the cell column span in case you want to merge two or more cells
    cell.setColspan(colspan);
    // in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }
    // add the call to the table
    table.addCell(cell);

}

From source file:org.smap.sdal.managers.PDFSurveyManager.java

License:Open Source License

private PdfPTable addDisplayItem(Parser parser, DisplayItem di, String basePath, String serverRoot,
        boolean generateBlank, GlobalVariables gv, String remoteUser, int oId)
        throws BadElementException, MalformedURLException, IOException {

    PdfPCell labelCell = new PdfPCell();
    PdfPCell valueCell = new PdfPCell();
    labelCell.setBorderColor(BaseColor.LIGHT_GRAY);
    valueCell.setBorderColor(BaseColor.LIGHT_GRAY);

    PdfPTable tItem = null;//from  ww  w.j a  va  2  s  . c o  m

    // Add label
    StringBuffer html = new StringBuffer();
    html.append("<span class='label ");
    if (di.labelbold) {
        html.append(" lbold");
    }

    // Get text value
    String textValue = "";
    if (di.text != null && di.text.trim().length() > 0) {
        textValue = di.text;
    } else {
        textValue = di.name;
    }
    textValue = textValue.trim();
    if (textValue.charAt(textValue.length() - 1) != ':') {
        textValue += ":";
    }
    if (di.labelcaps) {
        textValue = textValue.toUpperCase();
    }

    // Add language class
    html.append(GeneralUtilityMethods.getLanguage(textValue));
    html.append("'>");

    // Add text value
    html.append(GeneralUtilityMethods.unesc(textValue));
    html.append("</span>");

    // Only include hints if we are generating a blank template
    if (generateBlank) {
        html.append("<span class='hint ");
        if (di.hint != null) {
            html.append(GeneralUtilityMethods.getLanguage(di.hint));
            html.append("'>");
            html.append(GeneralUtilityMethods.unesc(di.hint));
        }
        html.append("</span>");
    }

    parser.elements.clear();
    try {
        parser.xmlParser.parse(new StringReader(html.toString()));

        for (Element element : parser.elements) {
            if (textValue != null && textValue.length() > 0) {
                if (GeneralUtilityMethods.isRtlLanguage(textValue)) {
                    labelCell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
                }
            } else if (di.hint != null && di.hint.length() > 0) {
                if (GeneralUtilityMethods.isRtlLanguage(textValue)) {
                    labelCell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
                }
            }
            labelCell.addElement(element);
        }
    } catch (Exception e) {
        log.info("Error parsing: " + html.toString() + " : " + e.getMessage());
        lm.writeLog(sd, survey.getId(), remoteUser, LogManager.ERROR,
                e.getMessage() + " for: " + html.toString());
        labelCell.addElement(getPara(html.toString(), di, gv, null, null));
    }

    // Set the content of the value cell
    try {
        updateValueCell(parser, remoteUser, valueCell, di, generateBlank, basePath, serverRoot, gv, oId);
    } catch (Exception e) {
        log.info("Error updating value cell, continuing: " + basePath + " : " + di.value);
        log.log(Level.SEVERE, "Exception", e);
    }

    int widthValue = 5;
    if (di.widthLabel == 10) {
        widthValue = 1; // Label and value in 1 column
        di.widthLabel = 1;
        tItem = new PdfPTable(1);
    } else {
        // Label and value in 2 columns
        widthValue = 10 - di.widthLabel;
        tItem = new PdfPTable(10);
    }
    // Format label cell
    labelCell.setColspan(di.widthLabel);
    if (di.labelbg != null) {
        labelCell.setBackgroundColor(di.labelbg);
    }

    // Format value cell
    valueCell.setColspan(widthValue);
    if (di.valueHeight > -1.0) {
        valueCell.setMinimumHeight((float) di.valueHeight);
    }
    if (di.valuebg != null) {
        valueCell.setBackgroundColor(di.valuebg);
    }

    tItem.addCell(labelCell);
    tItem.addCell(valueCell);
    return tItem;
}

From source file:PDF.Reportes.java

public static ArrayList<PdfPTable> tablaAspAula(String usuario, String contra, String horario, int opc)
        throws DocumentException {
    ArrayList<PdfPTable> tablas = new ArrayList();
    //        IngresoAbd bd = new IngresoAbd(usuario, contra);
    List<Beans.Reportes> reportes = ReportesDAO.AspPAula(usuario, contra, horario, opc);
    PdfPTable table = new PdfPTable(2);
    //        reportes = bd.AspPAula(horario, opc);
    PdfPCell cell;
    String carrera = "", fecha = "";
    if (reportes.isEmpty()) {

        cell = new PdfPCell(
                new Phrase("Lo sentimos, por el momento an no existe informacin para este reporte."));
        cell.setColspan(5);/*from   www .java 2  s . c  o m*/
        table.addCell(cell);
        tablas.add(table);

    } else if (reportes.get(0).getCodError() != 0) {

        if (reportes.get(0).getCodError() == -1) {
            cell = new PdfPCell(new Phrase(Constants.ERROR1));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -2) {
            cell = new PdfPCell(new Phrase(Constants.ERROR3));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -3) {
            cell = new PdfPCell(new Phrase(Constants.ERROR2));
            cell.setColspan(5);
            table.addCell(cell);
        }
        tablas.add(table);
    } else {
        table = new PdfPTable(5);
        BaseColor color = new BaseColor(217, 217, 217);
        BaseColor colorB = new BaseColor(0, 0, 0);
        cell = new PdfPCell(new Phrase("Ficha(5)", FontFactory.getFont("arial", 12, colorB)));
        cell.setMinimumHeight(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);

        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Folio Ceneval(6)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Nombre(7)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        //            cell = new PdfPCell(new Phrase("Nombre carrera", FontFactory.getFont("arial", 12, colorB)));
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //             cell.setBackgroundColor(color);
        //             cell.setBorderColor(colorB);
        //            table.addCell(cell);
        cell = new PdfPCell(new Phrase("Asistencia(8)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        cell.setColspan(2);
        table.addCell(cell);
        //            cell = new PdfPCell(new Phrase("Firma", FontFactory.getFont("arial", 12, colorB)));
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //             cell.setBackgroundColor(color);
        //             cell.setBorderColor(colorB);
        //            table.addCell(cell);

        for (int i = 0; i < reportes.size(); i++) {

            cell = new PdfPCell(new Phrase(reportes.get(i).getFicha()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getFolio()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getNombre(), FontFactory.getFont("arial", 10)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);

            carrera = reportes.get(i).getNom_carrera();
            //               
            cell = new PdfPCell(new Phrase(reportes.get(i).getAsist()));
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getFirma()));
            table.addCell(cell);
            fecha = reportes.get(i).getFecha();
            if ((i % 34 == 0 || (i + 1) == reportes.size()) && i != 0) {

                table.setWidthPercentage(110);
                table.setWidths(new int[] { 25, 30, 120, 15, 15 });
                tablas.add(table);
                table = new PdfPTable(5);
            }
        }
        String datos[] = horario.split(" ");
        String edificio = datos[0];
        String aula = "";
        if (edificio.length() == 2) {
            edificio = datos[0].charAt(0) + "";
            aula = datos[0].charAt(1) + "";
        }
        if (edificio.length() == 4) {

            edificio = datos[0].charAt(0) + "" + datos[0].charAt(1);
            aula = "" + datos[0].charAt(3);
        }
        if (edificio.length() == 5) {

            edificio = datos[0].charAt(0) + "" + datos[0].charAt(1);
            aula = "" + datos[0].charAt(3) + datos[0].charAt(4);
        }
        PdfPTable tableH = new PdfPTable(7);
        tableH.setTotalWidth(500);
        cell.setMinimumHeight(20);
        cell = new PdfPCell(new Phrase("CARRERA:(1)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(carrera));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(5);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("FECHA DE EXAMEN:(2)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(fecha));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("EDIFICIO:(3)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(edificio));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("AULA:(4)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(aula));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);

        tablas.add(tableH);
    }

    return tablas;
}

From source file:PDF.Reportes.java

public static ArrayList<PdfPTable> firmasAspAula(String usuario, String contra, String horario, int opc)
        throws DocumentException {
    ArrayList<PdfPTable> tablas = new ArrayList();
    //        IngresoAbd bd = new IngresoAbd(usuario, contra);
    List<Beans.Reportes> reportes;
    PdfPTable table = new PdfPTable(2);
    reportes = ReportesDAO.AspPAula(usuario, contra, horario, opc);
    //        reportes = bd.AspPAula(horario, opc);
    String carrera = "", fecha = "";
    if (reportes.isEmpty()) {
        PdfPCell cell;
        cell = new PdfPCell(
                new Phrase("Lo sentimos, por el momento an no existe informacin para este reporte."));
        cell.setColspan(5);/*from w ww . j  a  v  a 2s . c  o  m*/
        table.addCell(cell);
        tablas.add(table);
    } else if (reportes.get(0).getCodError() != 0) {
        PdfPCell cell;
        if (reportes.get(0).getCodError() == -1) {
            cell = new PdfPCell(new Phrase(Constants.ERROR1));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -2) {
            cell = new PdfPCell(new Phrase(Constants.ERROR3));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -3) {
            cell = new PdfPCell(new Phrase(Constants.ERROR2));
            cell.setColspan(5);
            table.addCell(cell);
        }
        tablas.add(table);
    } else {
        PdfPCell cell;
        table = new PdfPTable(6);
        BaseColor color = new BaseColor(217, 217, 217);
        BaseColor colorB = new BaseColor(0, 0, 0);
        cell = new PdfPCell(new Phrase("Ficha(5)", FontFactory.getFont("arial", 12, colorB)));
        cell.setMinimumHeight(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);

        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Folio Ceneval(6)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Nombre(7)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        //            cell = new PdfPCell(new Phrase("Nombre carrera", FontFactory.getFont("arial", 12, colorB)));
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //             cell.setBackgroundColor(color);
        //             cell.setBorderColor(colorB);
        //            table.addCell(cell);
        cell = new PdfPCell(new Phrase("Asistencia(8)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        cell.setColspan(2);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Firma(9)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        for (int i = 0; i < reportes.size(); i++) {
            cell = new PdfPCell(new Phrase(reportes.get(i).getFicha()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getFolio()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getNombre(), FontFactory.getFont("arial", 10)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);

            carrera = reportes.get(i).getNom_carrera();
            //               
            cell = new PdfPCell(new Phrase(reportes.get(i).getAsist()));
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getFirma()));
            table.addCell(cell);

            table.addCell(cell);
            fecha = reportes.get(i).getFecha();

            if ((i % 34 == 0 || (i + 1) == reportes.size()) && i != 0) {

                table.setWidthPercentage(110);
                table.setWidths(new int[] { 25, 30, 90, 15, 15, 30 });
                tablas.add(table);
                table = new PdfPTable(6);
            }
        }
        String datos[] = horario.split(" ");
        String edificio = datos[0];
        String aula = "";
        if (edificio.length() == 2) {
            edificio = datos[0].charAt(0) + "";
            aula = datos[0].charAt(1) + "";
        }
        if (edificio.length() == 4) {

            edificio = datos[0].charAt(0) + "" + datos[0].charAt(1);
            aula = "" + datos[0].charAt(3);
        }
        if (edificio.length() == 5) {

            edificio = datos[0].charAt(0) + "" + datos[0].charAt(1);
            aula = "" + datos[0].charAt(3) + datos[0].charAt(4);
        }
        PdfPTable tableH = new PdfPTable(7);
        tableH.setTotalWidth(500);
        cell.setMinimumHeight(20);
        cell = new PdfPCell(new Phrase("CARRERA:(1)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(carrera));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(5);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("FECHA DE EXAMEN:(2)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(fecha));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("EDIFICIO:(3)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(edificio));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("AULA:(4)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(aula));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);

        tablas.add(tableH);

    }

    return tablas;
}

From source file:ro.nextreports.engine.exporter.PdfExporter.java

License:Apache License

private PdfPCell renderPdfCell(BandElement bandElement, Object value, int gridRow, int rowSpan, int colSpan,
        boolean image, int column) {
    Map<String, Object> style = buildCellStyleMap(bandElement, value, gridRow, column, colSpan);

    FontFactoryImp fact = new FontFactoryImp();
    com.itextpdf.text.Font fnt;/*from www  .  jav  a  2s . co  m*/
    if (bandElement != null) {
        fontName = (String) style.get(StyleFormatConstants.FONT_NAME_KEY);
        int size = ((Float) style.get(StyleFormatConstants.FONT_SIZE)).intValue();
        fnt = getFont(size);
    } else {
        fnt = getFont(10);
    }

    PdfPCell cell;
    if (image) {
        if (value == null) {
            cell = new PdfPCell(new Phrase(IMAGE_NOT_FOUND));
        } else {
            ImageBandElement ibe = (ImageBandElement) bandElement;
            try {
                byte[] imageBytes = getImage((String) value);
                cell = getImageCell(ibe, imageBytes, column, colSpan);
            } catch (Exception e) {
                cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED));
            }
        }
    } else if (bandElement instanceof HyperlinkBandElement) {
        Hyperlink hyperlink = ((HyperlinkBandElement) bandElement).getHyperlink();
        Anchor anchor = new Anchor(hyperlink.getText(), fnt);
        anchor.setReference(hyperlink.getUrl());
        Phrase ph = new Phrase();
        ph.add(anchor);
        cell = new PdfPCell(ph);
    } else if (bandElement instanceof ReportBandElement) {
        Report report = ((ReportBandElement) bandElement).getReport();
        ExporterBean eb = null;
        try {
            eb = getSubreportExporterBean(report);
            PdfExporter subExporter = new PdfExporter(eb);
            subExporter.export();
            PdfPTable innerTable = subExporter.getTable();
            cell = new PdfPCell(innerTable);
        } catch (Exception e) {
            cell = new PdfPCell();
            e.printStackTrace();
        } finally {
            if ((eb != null) && (eb.getResult() != null)) {
                eb.getResult().close();
            }
        }
    } else if ((bandElement instanceof VariableBandElement) && (VariableFactory
            .getVariable(((VariableBandElement) bandElement).getVariable()) instanceof TotalPageNoVariable)) {
        try {
            cell = new PdfPCell(Image.getInstance(total));
        } catch (BadElementException e) {
            cell = new PdfPCell(new Phrase("NA"));
        }

    } else if (bandElement instanceof ImageColumnBandElement) {
        try {
            String v = StringUtil.getValueAsString(value, null);
            if (StringUtil.BLOB.equals(v)) {
                cell = new PdfPCell(new Phrase(StringUtil.BLOB));
            } else {
                byte[] bytes = StringUtil.decodeImage(v);
                cell = getImageCell(bandElement, bytes, column, colSpan);
            }
        } catch (Exception e) {
            e.printStackTrace();
            cell = new PdfPCell(new Phrase(IMAGE_NOT_LOADED));
        }
    } else {
        String stringValue;
        if (style.containsKey(StyleFormatConstants.PATTERN)) {
            stringValue = StringUtil.getValueAsString(value, (String) style.get(StyleFormatConstants.PATTERN),
                    getReportLanguage());
        } else {
            stringValue = StringUtil.getValueAsString(value, null, getReportLanguage());
        }
        if (stringValue == null) {
            stringValue = "";
        }
        if (stringValue.startsWith("<html>")) {
            StringReader reader = new StringReader(stringValue);
            List<Element> elems = new ArrayList<Element>();
            try {
                elems = HTMLWorker.parseToList(reader, new StyleSheet());
                Phrase ph = new Phrase();
                for (int i = 0; i < elems.size(); i++) {
                    Element elem = (Element) elems.get(i);
                    ph.add(elem);
                }
                cell = new PdfPCell(ph);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Phrase ph = new Phrase(stringValue, fnt);
                cell = new PdfPCell(ph);
            }

        } else {
            Phrase ph = new Phrase(stringValue, fnt);
            cell = new PdfPCell(ph);
        }
    }

    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    cell.setUseDescender(true); // needed for a cell without padding
    cell.setMinimumHeight(MINIMUM_HEIGHT); // needed if there is a row in which all cells are empty

    if (bandElement != null) {
        cell.setRotation(bandElement.getTextRotation());
    }

    if (colSpan > 1) {
        cell.setColspan(colSpan);
    }

    if (rowSpan > 1) {
        cell.setRowspan(rowSpan);
    }

    if (style != null) {

        updateFont(style, fnt);

        if (style.containsKey(StyleFormatConstants.BACKGROUND_COLOR)) {
            Color val = (Color) style.get(StyleFormatConstants.BACKGROUND_COLOR);
            cell.setBackgroundColor(new BaseColor(val));
        }
        if (style.containsKey(StyleFormatConstants.HORIZONTAL_ALIGN_KEY)) {
            if (StyleFormatConstants.HORIZONTAL_ALIGN_LEFT
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            }
            if (StyleFormatConstants.HORIZONTAL_ALIGN_RIGHT
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            }
            if (StyleFormatConstants.HORIZONTAL_ALIGN_CENTER
                    .equals(style.get(StyleFormatConstants.HORIZONTAL_ALIGN_KEY))) {
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            }
        }

        if (style.containsKey(StyleFormatConstants.VERTICAL_ALIGN_KEY)) {
            if (StyleFormatConstants.VERTICAL_ALIGN_TOP
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_TOP);
            }
            if (StyleFormatConstants.VERTICAL_ALIGN_MIDDLE
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            }
            if (StyleFormatConstants.VERTICAL_ALIGN_BOTTOM
                    .equals(style.get(StyleFormatConstants.VERTICAL_ALIGN_KEY))) {
                cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
            }
        }

        if (style.containsKey(StyleFormatConstants.PADDING_LEFT)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_LEFT);
            cell.setPaddingLeft(val);
        }
        if (style.containsKey(StyleFormatConstants.PADDING_RIGHT)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_RIGHT);
            cell.setPaddingRight(val);
        }
        if (style.containsKey(StyleFormatConstants.PADDING_TOP)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_TOP);
            cell.setPaddingTop(val);
        }
        if (style.containsKey(StyleFormatConstants.PADDING_BOTTOM)) {
            Float val = (Float) style.get(StyleFormatConstants.PADDING_BOTTOM);
            cell.setPaddingBottom(val);
        }
        cell.setBorderWidth(0);

        if (style.containsKey(StyleFormatConstants.BORDER_LEFT)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_LEFT);
            cell.setBorderWidthLeft(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_LEFT_COLOR);
            cell.setBorderColorLeft(new BaseColor(color));
        }
        if (style.containsKey(StyleFormatConstants.BORDER_RIGHT)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_RIGHT);
            cell.setBorderWidthRight(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_RIGHT_COLOR);
            cell.setBorderColorRight(new BaseColor(color));
        }
        if (style.containsKey(StyleFormatConstants.BORDER_TOP)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_TOP);
            cell.setBorderWidthTop(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_TOP_COLOR);
            cell.setBorderColorTop(new BaseColor(color));
        }
        if (style.containsKey(StyleFormatConstants.BORDER_BOTTOM)) {
            Float val = (Float) style.get(StyleFormatConstants.BORDER_BOTTOM);
            cell.setBorderWidthBottom(val / 2);
            Color color = (Color) style.get(StyleFormatConstants.BORDER_BOTTOM_COLOR);
            cell.setBorderColorBottom(new BaseColor(color));
        }

        // for subreports we use default no wrap
        if (cell.getTable() == null) {
            cell.setNoWrap(true);
            if (bandElement != null) {
                if (bandElement.isWrapText()) {
                    cell.setNoWrap(false);
                }
            }
        }

        // to see a background image all cells must not have any background!
        if (bean.getReportLayout().getBackgroundImage() != null) {
            cell.setBackgroundColor(null);
        }
    }
    return cell;
}

From source file:server.kartu.tik.iText.java

public String createPDF(String tanggal, ArrayList kegiatan, String divisi) {
    ArrayList<Kegiatan> list = new ArrayList<>(kegiatan);

    String output = System.getProperty("user.dir") + "\\src\\data\\pdf\\" + tanggal + " " + getNamalengkap()
            + "-" + getTglnoktp() + ".pdf";

    String namaDivisi = "";
    switch (divisi) {
    case "1":
        namaDivisi = "Ekonomi";
        break;/*from  w w  w.  j a  va 2 s .co m*/
    case "2":
        namaDivisi = "Politik";
        break;
    case "3":
        namaDivisi = "Sosial Budaya";
        break;
    case "4":
        namaDivisi = "Keamanan";
        break;
    }

    Document document = new Document(PageSize.A4);
    try {
        PdfWriter.getInstance(document, new FileOutputStream(output));

        document.open();

        //------------------------------------------------------------------------------------- TITLE
        PdfPTable title = new PdfPTable(1);
        title.setWidthPercentage(100);
        Font f = new Font(FontFamily.HELVETICA, 14, Font.NORMAL, GrayColor.GRAYWHITE);
        PdfPCell celltitle = new PdfPCell(new Phrase("KARTU TIK (" + namaDivisi + ")", f));
        celltitle.setMinimumHeight(20);
        celltitle.setBackgroundColor(GrayColor.GRAYBLACK);
        celltitle.setHorizontalAlignment(Element.ALIGN_CENTER);
        celltitle.setColspan(3);
        title.addCell(celltitle);
        document.add(title);
        //-------------------------------------------------------------------------------------- END

        //------------------------------------------------------------------------------------- NAMA + ALIAS
        float[] columnWidths = { 8, 2 };
        PdfPTable tabel1 = new PdfPTable(columnWidths);
        tabel1.setWidthPercentage(100);

        PdfPTable innerTable1 = new PdfPTable(1);
        innerTable1.setWidthPercentage(100);
        PdfPTable innerTable2 = new PdfPTable(1);
        innerTable2.setWidthPercentage(100);
        PdfPCell cell;
        innerTable1.addCell(
                "1.  a. Nama Lengkap : " + getNamalengkap() + " \n\n     b. Alias : " + getAlias() + " \n\n");
        innerTable1.addCell("2.  Kebangsaan \n     a. Tgl. No. KTP : " + getTglnoktp()
                + " \n\n     b. Tgl. No. Pasport : " + getTglnopasport() + "\n\n");
        innerTable1.addCell("3.  Agama : " + getAgama());
        cell = new PdfPCell(innerTable1);
        cell.setMinimumHeight(135);
        tabel1.addCell(cell);
        if (getUrlfoto().equalsIgnoreCase("") || getUrlfoto().isEmpty() || getUrlfoto() == null) {

        } else {
            Image image = Image.getInstance(getUrlfoto());
            cell = new PdfPCell(image, false);
            if (image.getWidth() < 90) {
                cell.setPaddingLeft(8);
            } else {
                cell.setPaddingLeft(3);
            }
        }
        cell.setMinimumHeight(135);
        tabel1.addCell(cell);
        cell = new PdfPCell();
        cell.setColspan(14);
        tabel1.addCell(cell);

        document.add(tabel1);
        //------------------------------------------------------------------------------------- NAMA + ALIAS END

        //------------------------------------------------------------------------------------- TGL LAHIR + TEMPAT
        PdfPTable tabel4 = new PdfPTable(1);
        tabel4.setWidthPercentage(100);

        Paragraph pTglLahirnTempat = new Paragraph();
        pTglLahirnTempat.add("4.  a. Tgl. Lahir/ Umur : " + getTgllahir());
        pTglLahirnTempat.add("\n\n     b. Tempat Lahir     : " + getTempatlahir());
        pTglLahirnTempat.setLeading(0, 1);

        PdfPCell cTglLahirnTempat = new PdfPCell();
        cTglLahirnTempat.setMinimumHeight(45);
        cTglLahirnTempat.addElement(pTglLahirnTempat);
        tabel4.addCell(cTglLahirnTempat);

        document.add(tabel4);
        //------------------------------------------------------------------------------------- TGL LAHIR + TEMPAT END

        //------------------------------------------------------------------------------------- ALAMAT + PINDAHAN
        PdfPTable tabel5 = new PdfPTable(1);
        tabel5.setWidthPercentage(100);

        Paragraph pAlamat = new Paragraph();
        pAlamat.add("5.  Alamat : ");
        pAlamat.add(alamat);
        pAlamat.setLeading(0, 1);

        PdfPCell cAlamat = new PdfPCell();
        cAlamat.setMinimumHeight(18);
        cAlamat.addElement(pAlamat);
        tabel5.addCell(cAlamat);
        document.add(tabel5);

        PdfPTable tabel51 = new PdfPTable(1);
        tabel51.setWidthPercentage(100);

        Paragraph pAlamatUbah = new Paragraph();
        pAlamatUbah.add("6.  Perubahan Alamat :");
        pAlamatUbah.add("\n\n    1. ");
        pAlamatUbah.add("\n\n    2. ");
        pAlamatUbah.add("\n\n    3. ");
        pAlamatUbah.add("\n\n");
        pAlamatUbah.setLeading(0, 1);

        PdfPCell cAlamatUbah = new PdfPCell();
        cAlamatUbah.addElement(pAlamatUbah);
        tabel51.addCell(cAlamatUbah);
        document.add(tabel51);
        //------------------------------------------------------------------------------------- ALAMAT + PINDAHAN END

        //------------------------------------------------------------------------------------- KEDUDUKAN KELUARGA
        PdfPTable tabel6 = new PdfPTable(1);
        tabel6.setWidthPercentage(100);

        Paragraph pKedudukanKeluarga = new Paragraph();
        pKedudukanKeluarga.add("7.  Kedudukan dalam Keluarga : ");
        pKedudukanKeluarga.setLeading(0, 1);

        PdfPCell cKedudukanKeluarga = new PdfPCell();
        cKedudukanKeluarga.setMinimumHeight(20);
        cKedudukanKeluarga.addElement(pKedudukanKeluarga);
        tabel6.addCell(cKedudukanKeluarga);
        document.add(tabel6);

        PdfPTable tabel61 = new PdfPTable(1);
        tabel61.setWidthPercentage(100);

        Paragraph pNamaBapakIbu = new Paragraph();
        pNamaBapakIbu.add("8.  a.  Nama Bapak : ");
        pNamaBapakIbu.add("\n\n          Nama Ibu      : ");
        pNamaBapakIbu.add("\n\n     b.  Alamat : ");
        pNamaBapakIbu.setLeading(0, 1);

        PdfPCell cNamaBapakIbu = new PdfPCell();
        cNamaBapakIbu.setMinimumHeight(70);
        cNamaBapakIbu.addElement(pNamaBapakIbu);
        tabel61.addCell(cNamaBapakIbu);

        document.add(tabel61);
        //------------------------------------------------------------------------------------- KEDUDUKAN END

        //------------------------------------------------------------------------------------- PEKERJAAN
        PdfPTable tabel7 = new PdfPTable(2);
        tabel7.setWidthPercentage(100);

        Paragraph pPekerjaan = new Paragraph();
        pPekerjaan.add("9.  a. Pekerjaan : " + getPekerjaan());
        pPekerjaan.setLeading(0, 1);

        PdfPCell cPekerjaan = new PdfPCell();
        cPekerjaan.setMinimumHeight(20);
        cPekerjaan.addElement(pPekerjaan);
        tabel7.addCell(cPekerjaan);

        Paragraph pJabatan = new Paragraph();
        pJabatan.add("  b. Jabatan : " + getJabatan());
        pJabatan.setLeading(0, 1);

        PdfPCell cJabatan = new PdfPCell();
        cJabatan.setMinimumHeight(20);
        cJabatan.addElement(pJabatan);
        tabel7.addCell(cJabatan);

        document.add(tabel7);
        //------------------------------------------------------------------------------------- PEKERJAAN END

        //------------------------------------------------------------------------------------- INSTANSI DLL
        PdfPTable tabel8 = new PdfPTable(1);
        tabel8.setWidthPercentage(100);

        Paragraph pInstansi = new Paragraph();
        pInstansi.add("     c. Instansi/Lembaga/Kantor : " + getInstansilembagakantor());
        pInstansi.setLeading(0, 1);

        PdfPCell cInstansi = new PdfPCell();
        cInstansi.setMinimumHeight(20);
        cInstansi.addElement(pInstansi);
        tabel8.addCell(cInstansi);

        document.add(tabel8);
        //------------------------------------------------------------------------------------- INSTANSI DLL END

        //------------------------------------------------------------------------------------- NAMA ISTRI
        float[] colomn = { 7, 1, 2 };
        PdfPTable tabel9 = new PdfPTable(colomn);
        tabel9.setWidthPercentage(100);

        Paragraph pNamaIstriBapakIbu = new Paragraph();
        pNamaIstriBapakIbu.add("10.");
        pNamaIstriBapakIbu.add("\n       a. Nama Istri : ");
        pNamaIstriBapakIbu.add("\n\n       b. Nama Bapak Istri : ");
        pNamaIstriBapakIbu.add("\n\n       c. Nama Ibu Istri : ");
        pNamaIstriBapakIbu.add("\n\n       d. Alamat : ");
        pNamaIstriBapakIbu.setLeading(0, 1);

        PdfPCell cNamaIstriBapakIbu = new PdfPCell();
        cNamaIstriBapakIbu.setMinimumHeight(110);
        cNamaIstriBapakIbu.addElement(pNamaIstriBapakIbu);
        tabel9.addCell(cNamaIstriBapakIbu);

        Paragraph pUmurIstriBapakIbu = new Paragraph();
        pUmurIstriBapakIbu.add("  Umur :");
        pUmurIstriBapakIbu.setLeading(0, 1);

        PdfPCell cUmurIstriBapakIbu = new PdfPCell();
        cUmurIstriBapakIbu.setMinimumHeight(110);
        cUmurIstriBapakIbu.addElement(pUmurIstriBapakIbu);
        tabel9.addCell(cUmurIstriBapakIbu);

        Paragraph pPekerjaanIstriBapakIbu = new Paragraph();
        pPekerjaanIstriBapakIbu.add("  Pekerjaan :");
        pPekerjaanIstriBapakIbu.setLeading(0, 1);

        PdfPCell cPekerjaanIstriBapakIbu = new PdfPCell();
        cPekerjaanIstriBapakIbu.setMinimumHeight(110);
        cPekerjaanIstriBapakIbu.addElement(pPekerjaanIstriBapakIbu);
        tabel9.addCell(cPekerjaanIstriBapakIbu);

        document.add(tabel9);
        //------------------------------------------------------------------------------------- NAMA ISTRI END

        //------------------------------------------------------------------------------------- SANAK SAUDARA
        PdfPTable tabel10 = new PdfPTable(colomn);
        tabel10.setWidthPercentage(100);

        Paragraph pSanakSaudara = new Paragraph();
        pSanakSaudara.add("11.  Nama Sanak/Saudara yang menjadi Tanggungan : \n       1.\n       2.");
        pSanakSaudara.setLeading(0, 1);

        PdfPCell cSanakSaudara = new PdfPCell();
        cSanakSaudara.addElement(pSanakSaudara);
        tabel10.addCell(cSanakSaudara);

        Paragraph pSanakSaudara1 = new Paragraph();
        pSanakSaudara1.add("");
        pSanakSaudara1.setLeading(0, 1);

        PdfPCell cSanakSaudara1 = new PdfPCell();
        cSanakSaudara1.addElement(pSanakSaudara1);
        tabel10.addCell(cSanakSaudara1);

        Paragraph pSanakSaudara2 = new Paragraph();
        pSanakSaudara2.add("");
        pSanakSaudara2.setLeading(0, 1);

        PdfPCell cSanakSaudara2 = new PdfPCell();
        cSanakSaudara2.addElement(pSanakSaudara2);
        tabel10.addCell(cSanakSaudara2);

        document.add(tabel10);
        //------------------------------------------------------------------------------------- SANAK SAUDARA END

        //------------------------------------------------------------------------------------- ANAK2
        PdfPTable tabel11 = new PdfPTable(colomn);
        tabel11.setWidthPercentage(100);

        Paragraph pAnak2 = new Paragraph();
        pAnak2.add("12.  Anak-anak : ");
        pAnak2.add("\n\n       1. ");
        pAnak2.add("\n\n       2. ");
        pAnak2.add("\n\n       3. ");
        pAnak2.add("\n\n       4. ");
        pAnak2.add("\n\n       5. ");
        pAnak2.add("\n\n       6. ");
        pAnak2.add("\n");
        pAnak2.setLeading(0, 1);

        PdfPCell cAnak2 = new PdfPCell();
        cAnak2.setMinimumHeight(165);
        cAnak2.addElement(pAnak2);
        tabel11.addCell(cAnak2);

        Paragraph pUmurAnak2 = new Paragraph();
        pUmurAnak2.add("  Umur : ");
        pUmurAnak2.setLeading(0, 1);

        PdfPCell cUmurAnak2 = new PdfPCell();
        cUmurAnak2.setMinimumHeight(165);
        cUmurAnak2.addElement(pUmurAnak2);
        tabel11.addCell(cUmurAnak2);

        Paragraph pPekarjaanAnak2 = new Paragraph();
        pPekarjaanAnak2.add("  Pekerjaan : ");
        pPekarjaanAnak2.setLeading(0, 1);

        PdfPCell cPekerjaanAnak2 = new PdfPCell();
        cPekerjaanAnak2.setMinimumHeight(165);
        cPekerjaanAnak2.addElement(pPekarjaanAnak2);
        tabel11.addCell(cPekerjaanAnak2);

        document.add(tabel11);
        //------------------------------------------------------------------------------------- ANAK2 END

        //------------------------------------------------------------------------------------- CIRI-CIRI
        PdfPTable tabel12 = new PdfPTable(1);
        tabel12.setWidthPercentage(100);

        Paragraph pCiri2 = new Paragraph();
        pCiri2.add("13.  Ciri-ciri badan : ");
        pCiri2.add("\n\n       1. Rambut : " + getRambut());
        for (int i = 0; i < (35 - getRambut().length()); i++) {
            pCiri2.add(" ");
        }
        pCiri2.add("2. Muka : " + getMuka());
        for (int i = 0; i < (35 - getMuka().length()); i++) {
            pCiri2.add(" ");
        }
        pCiri2.add("3. Kulit : " + getKulit());
        pCiri2.setLeading(0, 1);

        PdfPCell cCiri2 = new PdfPCell();
        cCiri2.setMinimumHeight(45);
        cCiri2.addElement(pCiri2);
        tabel12.addCell(cCiri2);

        document.add(tabel12);
        //------------------------------------------------------------------------------------- CIRI-CIRI END

        //------------------------------------------------------------------------------------- LANJUTAN CIRI2
        PdfPTable tabel13 = new PdfPTable(1);
        tabel13.setWidthPercentage(100);

        Paragraph pCiri2Lanjutan = new Paragraph();
        for (int i = 0; i < 20; i++) {
            pCiri2Lanjutan.add(" ");
        }
        pCiri2Lanjutan.add("4.  Tinggi : " + getTinggi());
        for (int i = 0; i < (35 - getTinggi().length()); i++) {
            pCiri2Lanjutan.add(" ");
        }
        pCiri2Lanjutan.add("5.  Tanda Istimewa : " + getTandaistimewa());
        pCiri2Lanjutan.setLeading(0, 1);

        PdfPCell cCiri2Lanjutan = new PdfPCell();
        cCiri2Lanjutan.setMinimumHeight(20);
        cCiri2Lanjutan.addElement(pCiri2Lanjutan);
        tabel13.addCell(cCiri2Lanjutan);

        document.add(tabel13);
        //------------------------------------------------------------------------------------- LANJUTAN CIRI2

        //------------------------------------------------------------------------------------- RUMUS SIDIK JARI
        PdfPTable tabel14 = new PdfPTable(1);
        tabel14.setWidthPercentage(100);

        Paragraph pSidikJari = new Paragraph();
        pSidikJari.add("14.  Rumus Sidik Jari : " + getRumussidikjari());
        pSidikJari.setLeading(0, 1);

        PdfPCell cSidikJari = new PdfPCell();
        cSidikJari.setMinimumHeight(20);
        cSidikJari.addElement(pSidikJari);
        tabel14.addCell(cSidikJari);

        document.add(tabel14);
        //------------------------------------------------------------------------------------- RUMUS SIDIK JARI END

        //------------------------------------------------------------------------------------- RIWAYAT SEKOLAH
        float[] colom = { 8, 2 };
        PdfPTable tabel15 = new PdfPTable(colom);
        tabel15.setWidthPercentage(100);

        Paragraph pRiwayatSekolah = new Paragraph();
        pRiwayatSekolah.add("15.  Riwayat Sekolah : ");
        pRiwayatSekolah.add("\n\n       1. ");
        pRiwayatSekolah.add("\n\n       2. ");
        pRiwayatSekolah.add("\n\n       3. ");
        pRiwayatSekolah.add("\n\n       4. ");
        pRiwayatSekolah.add("\n\n       5. ");
        pRiwayatSekolah.add("\n\n       6. ");
        pRiwayatSekolah.setLeading(0, 1);

        PdfPCell cRiwayatSekolah = new PdfPCell();
        cRiwayatSekolah.setMinimumHeight(165);
        cRiwayatSekolah.addElement(pRiwayatSekolah);
        tabel15.addCell(cRiwayatSekolah);

        Paragraph pTahunLulus = new Paragraph();
        pTahunLulus.add("Tahun Lulus");
        pTahunLulus.setLeading(0, 1);

        PdfPCell cTahunLulus = new PdfPCell();
        cTahunLulus.setMinimumHeight(165);
        cTahunLulus.addElement(pTahunLulus);
        tabel15.addCell(cTahunLulus);

        document.add(tabel15);
        //------------------------------------------------------------------------------------- RIWAYAT SEKOLAH END

        //------------------------------------------------------------------------------------- KESENANGAN/KEGEMARAN/HOBI
        PdfPTable tabel16 = new PdfPTable(1);
        tabel16.setWidthPercentage(100);

        Paragraph pKesenenanganKegemaranHobi = new Paragraph();
        pKesenenanganKegemaranHobi.add("16.  Kesenangan/Kegemaran/Hobi : " + getHobi());
        pKesenenanganKegemaranHobi.setLeading(0, 1);

        PdfPCell cKesenenanganKegemaranHobi = new PdfPCell();
        cKesenenanganKegemaranHobi.setMinimumHeight(20);
        cKesenenanganKegemaranHobi.addElement(pKesenenanganKegemaranHobi);
        tabel16.addCell(cKesenenanganKegemaranHobi);

        document.add(tabel16);
        //------------------------------------------------------------------------------------- KESENANGAN/KEGEMARAN/HOBI END

        //------------------------------------------------------------------------------------- CATATAN KRIMINAL
        PdfPTable tabel17 = new PdfPTable(1);
        tabel17.setWidthPercentage(100);

        Paragraph pCatatanKriminal = new Paragraph();
        pCatatanKriminal.add("17.  Catatan kriminal yang ada : ");
        pCatatanKriminal.add("\n\n       1. " + getCatatankriminal1());
        pCatatanKriminal.add("\n\n       2. " + getCatatankriminal2());
        pCatatanKriminal.add("\n\n       3. " + getCatatankriminal3());
        pCatatanKriminal.setLeading(0, 1);

        PdfPCell cCatatanKriminal = new PdfPCell();
        cCatatanKriminal.setMinimumHeight(95);
        cCatatanKriminal.addElement(pCatatanKriminal);
        tabel17.addCell(cCatatanKriminal);

        document.add(tabel17);
        //------------------------------------------------------------------------------------- CATATAN KRIMINAL END

        //------------------------------------------------------------------------------------- KETERANGAN DLL
        PdfPTable tabel18 = new PdfPTable(1);
        tabel18.setWidthPercentage(100);

        Paragraph pDataKeteranganLain2 = new Paragraph();
        pDataKeteranganLain2.add("18.  Data Keterangan dan lain2 : ");
        pDataKeteranganLain2.add("\n\n\n");
        pDataKeteranganLain2.setLeading(0, 1);

        PdfPCell cDataKeteranganLain2 = new PdfPCell();
        cDataKeteranganLain2.addElement(pDataKeteranganLain2);

        if (list.size() > 0) {
            float[] kolomkegiatan = { 8, 2 };
            PdfPTable nestedTable = new PdfPTable(kolomkegiatan);

            nestedTable.addCell(new Paragraph("Kegiatan"));
            nestedTable.addCell(new Paragraph("Tanggal"));

            for (int i = 0; i < list.size(); i++) {
                nestedTable.addCell(new Paragraph(list.get(i).getNamakegiatan()));
                nestedTable.addCell(new Paragraph(list.get(i).getTanggal()));
            }

            cDataKeteranganLain2.addElement(nestedTable);
            cDataKeteranganLain2.setPaddingBottom(20f);
            tabel18.addCell(cDataKeteranganLain2);
        }

        document.add(tabel18);
        //------------------------------------------------------------------------------------- KETERANGAN DLL END

        document.close();

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return output;
}

From source file:Servlets.ReportsServlet.java

private void insertCell(PdfPTable table, String text, int align, int colspan, Font font) {

    //create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));

    //set the cell alignment
    cell.setHorizontalAlignment(align);/*from   w  ww  . j  a  va2 s  .  co m*/

    //set the cell column span in case you want to merge two or more cells
    cell.setColspan(colspan);

    //Set padding
    cell.setPadding(3f);

    //in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }
    //add the call to the table
    table.addCell(cell);

}

From source file:Servlets.ReportsServlet.java

private void insertCell(PdfPTable table, String text, int align, int colspan, Font font, float bord[]) {

    //create a new cell with the specified Text and Font
    PdfPCell cell = new PdfPCell(new Phrase(text.trim(), font));

    //set the cell alignment
    cell.setHorizontalAlignment(align);/*from w w w .j  av  a2 s . com*/

    //set the cell column span in case you want to merge two or more cells
    cell.setColspan(colspan);

    //Set padding
    cell.setPadding(3f);

    //Setting cell Borders
    // cell.setBorderWidth(3f);         // sets border width to 3 units
    cell.setBorderWidthLeft(bord[0]);
    cell.setBorderWidthRight(bord[1]);
    cell.setBorderWidthTop(bord[2]);
    cell.setBorderWidthBottom(bord[3]);

    //in case there is no text and you wan to create an empty row
    if (text.trim().equalsIgnoreCase("")) {
        cell.setMinimumHeight(10f);
    }
    //add the call to the table
    table.addCell(cell);

}