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

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

Introduction

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

Prototype

public PdfPCell(PdfPCell cell) 

Source Link

Document

Constructs a deep copy of a PdfPCell.

Usage

From source file:Cotizacion.ExportarPDF.java

private static void acomodarDatosTablaProductos(Paragraph subCatPart) throws BadElementException {
    numeroFilas = LogicaCotizacion.numero;
    cantidadTabla = new String[numeroFilas];
    productoTabla = new String[numeroFilas];
    precioTabla = new String[numeroFilas];
    totalTabla = new String[numeroFilas];
    descripcionTabla = new String[numeroFilas];

    PdfPTable tabla = new PdfPTable(5);
    tabla.setWidthPercentage(100);/*from   ww  w  .  j a  va  2  s  . c  om*/

    PdfPCell celda = new PdfPCell(new Paragraph("Producto"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    celda = new PdfPCell(new Paragraph("Descripcin"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    celda = new PdfPCell(new Paragraph("P/U"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    celda = new PdfPCell(new Paragraph("Cantidad"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    celda = new PdfPCell(new Paragraph("Total"));
    celda.setHorizontalAlignment(Element.ALIGN_CENTER);
    celda.setBackgroundColor(new Color(0, 175, 239));
    tabla.addCell(celda);
    for (int i = 0; i < numeroFilas; i++) {
        productoTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 0);
        tabla.addCell("   " + productoTabla[i]);
        descripcionTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 1);
        tabla.addCell("" + descripcionTabla[i]);
        precioTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 2);
        tabla.addCell("$  " + precioTabla[i]);
        cantidadTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 3);
        tabla.addCell("   " + cantidadTabla[i]);
        totalTabla[i] = "" + Cotizacion.PanelCotizacion.tablaProductos.getValueAt(i, 4);
        tabla.addCell("$  " + totalTabla[i]);
    }
    agregarLineasEnBlanco(subCatPart, 1);
    subCatPart.add(tabla);
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Set the logo of Humboldt on the left corner and the current date on the
 * right corner/*from   w  ww  .  j  a v a 2  s . c o m*/
 * 
 * @param document
 *            reference of the pdfDocument object
 */
protected void addHeading(Document document) {
    Paragraph paragraph = new Paragraph();
    PdfPTable table = createMyStandardTable(2);

    table.setTotalWidth(TABLEWIDTH);
    PdfPCell cell;

    Image img = new ResourceLoader("pdf/humboldt_logo.png").getImage();
    img.setAlignment(Element.ALIGN_BOTTOM);
    img.scaleToFit(205f, 65f);
    cell = new PdfPCell(img);

    cell.setBorder(0);
    table.addCell(cell);

    String date = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMAN).format(Calendar.getInstance().getTime());

    cell = new PdfPCell(new Phrase(date));
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);

    paragraph.add(table);
    addEmptyLine(paragraph, 1);

    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Adds a signature field with a date field to the document. Should be the
 * last part that is added to the document.
 * //from  ww w .  ja  va  2 s.c o  m
 * @param document
 *            represents the PDF before it is saved
 * @param role
 *            word for the kind of person that shall sign the paper
 */
protected void addSignatureField(Document document, String role) {
    Paragraph paragraph = new Paragraph();

    //this table contains the signatureTable and the dataTable.
    // this purpose makes it easier to format
    PdfPTable table = createMyStandardTable(2);

    //the first column is double times greater than the second column
    try {
        table.setWidths(new float[] { 10f, 20f });
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    //create and fill date table
    PdfPTable dateTable = new PdfPTable(1);

    PdfPCell cell = new PdfPCell(new Phrase(""));
    //just the bottom border will be displayed (line for date)
    cell.setBorderWidthTop(0);
    cell.setBorderWidthLeft(0);
    cell.setBorderWidthRight(0);

    dateTable.addCell(cell);

    cell = new PdfPCell(new Phrase("Datum"));
    cell.setBorder(0);

    dateTable.addCell(cell);

    //put date table into the 'parent' table
    cell = new PdfPCell(dateTable);
    cell.setBorder(0);
    table.addCell(cell);

    //create and fill signature table
    PdfPTable signatureTable = new PdfPTable(1);
    cell = new PdfPCell(new Phrase(""));
    //just the bottom border will be displayed (line for signature)
    cell.setBorderWidthTop(0);
    cell.setBorderWidthLeft(0);
    cell.setBorderWidthRight(0);

    signatureTable.addCell(cell);

    cell = new PdfPCell(new Phrase("Unterschrift " + role));
    cell.setBorder(0);

    signatureTable.addCell(cell);

    //put signature table into the 'parent' table
    cell = new PdfPCell(signatureTable);
    cell.setBorder(0);
    table.addCell(cell);

    paragraph.add(table);
    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Use the configuration information to fill the table cells
 * @param tableBuilder Table configuration
 *///from   w  ww.  j a  v  a2 s .  c  o  m
private static void fillTableWithContent(TableBuilder tableBuilder) {
    PdfPCell cell = null;
    for (int i = 0; i < tableBuilder.contentArray.length; i++) {
        if (tableBuilder.contentArray[i] == null || tableBuilder.contentArray[i].equals("null")) {
            tableBuilder.contentArray[i] = "";
        }
        if (tableBuilder.font != null) {
            cell = new PdfPCell(new Phrase(tableBuilder.contentArray[i], tableBuilder.font));
        } else {
            cell = new PdfPCell(new Phrase(tableBuilder.contentArray[i]));
        }
        if (tableBuilder.isAlignedCentrally) {
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        }
        if (!tableBuilder.withBorder) {
            cell.setBorder(0);
        }
        if (tableBuilder.padding != 0f) {
            cell.setPadding(tableBuilder.padding);
        }
        if (tableBuilder.leading != 0f) {
            cell.setLeading(tableBuilder.leading, tableBuilder.leading);
        }
        tableBuilder.table.addCell(cell);
    }
}

From source file:de.jdufner.sudoku.generator.pdf.PdfCellHandler.java

License:Open Source License

@Override
public void handleCell(Cell cell) {
    PdfPCell pdfCell = null;//from   w w w .  j  a  va  2s .  co m
    if (cell.isFixed()) {
        pdfCell = new PdfPCell(new Paragraph(cell.getValue().toString()));
    } else {
        if (Boolean.getBoolean(getPdfStyle().getProperty("sudoku.board.candidates.print"))) {
            pdfCell = new PdfPCell(buildCandidates());
        } else {
            pdfCell = new PdfPCell();
        }
    }
    formatZelle(cell.getRowIndex(), cell.getColumnIndex(), pdfCell);
    table.addCell(pdfCell);
}

From source file:de.jdufner.sudoku.generator.pdf.PdfCellHandler.java

License:Open Source License

/**
 * /* w  w  w  .  j a  v a  2s.c o  m*/
 * @return 3x3 Tabelle gefllt mit Kandidaten 1-9
 */
private PdfPTable buildCandidates() {
    final float CANDIDATE_FONT_SIZE = 6f;
    final float CANDIDATE_PADDING = 1f;
    PdfPTable candidates = new PdfPTable(3);
    PdfPCell[][] candidate = new PdfPCell[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            Paragraph p = new Paragraph(String.valueOf(i * 3 + j + 1));
            p.getFont().setSize(CANDIDATE_FONT_SIZE);
            candidate[i][j] = new PdfPCell(p);
            candidate[i][j].setPadding(CANDIDATE_PADDING);
            candidate[i][j].setHorizontalAlignment(Element.ALIGN_CENTER);
            candidate[i][j].setVerticalAlignment(Element.ALIGN_MIDDLE);
            candidate[i][j].setBorderColor(new Color(PdfConstants.RAHMEN_FARBE[0], PdfConstants.RAHMEN_FARBE[1],
                    PdfConstants.RAHMEN_FARBE[2]));
            candidate[i][j].setBorderWidth(PdfConstants.RAHMEN_KEIN);
            if (i > 0) {
                candidate[i][j].setBorderWidthTop(PdfConstants.RAHMEN_DUENN);
            }
            if (j > 0) {
                candidate[i][j].setBorderWidthLeft(PdfConstants.RAHMEN_DUENN);
            }
            candidates.addCell(candidate[i][j]);
        }
    }
    return candidates;
}

From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private PdfPTable writePdfTable(SudokuData sudokuData) {
    PdfPTable einzelnesSudoku = new PdfPTable(1);
    PdfPTable ueberschrift = new PdfPTable(2);
    PdfPCell linkeZelle = new PdfPCell(new Phrase("ID: " + sudokuData.getId()));
    linkeZelle.getPhrase().getFont().setSize(9f);
    linkeZelle.setBorder(Integer.parseInt(getPdfStyle().getProperty("border.none")));
    linkeZelle.setHorizontalAlignment(Element.ALIGN_LEFT);
    ueberschrift.addCell(linkeZelle);//w  ww  .  j  a  v a  2s .  c  om
    PdfPCell rechteZelle = new PdfPCell(
            new Phrase(Level.valueOf(sudokuData.getLevel()).getName() + " (" + sudokuData.getFixed() + ")"));
    rechteZelle.getPhrase().getFont().setSize(9f);
    rechteZelle.setBorder(0);
    rechteZelle.setHorizontalAlignment(Element.ALIGN_RIGHT);
    ueberschrift.addCell(rechteZelle);
    PdfPCell obereZelle = new PdfPCell(ueberschrift);
    obereZelle.setBorder(0);
    einzelnesSudoku.addCell(obereZelle);
    PdfCellHandler pdfCellHandler = new PdfCellHandler(SudokuSize.getByUnitSize(sudokuData.getSize()),
            getPdfStyle());
    pdfCellHandler.initialize();
    HandlerUtil.forEachCell(SudokuFactory.INSTANCE.buildSudoku(sudokuData.getSudokuAsString()), pdfCellHandler);
    PdfPCell untereZelle = new PdfPCell(pdfCellHandler.getTable());
    untereZelle.setBorder(0);
    einzelnesSudoku.addCell(untereZelle);
    return einzelnesSudoku;
}

From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private PdfPCell buildHeaderCell(String text, int rotation, boolean first, boolean last) {
    PdfPCell cell = new PdfPCell(new Phrase(text));
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    setBorder(cell, first, last);/* w  ww . ja  v  a 2 s .co m*/
    cell.setRotation(rotation);
    return cell;
}

From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private PdfPCell buildBodyNumberCell(int value, boolean even, boolean first, boolean last) {
    PdfPCell cell = new PdfPCell(new Phrase(String.valueOf(value)));
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    if (even) {/*from w  w w  . j  av  a  2s.c  o m*/
        cell.setGrayFill(0.8f);
    }
    setBorder(cell, first, last);
    // cell.setRotation(rotation);
    return cell;
}

From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java

License:Open Source License

private PdfPCell buildBodyTextCell(String value, boolean even, boolean first, boolean last) {
    PdfPCell cell = new PdfPCell(new Phrase(value));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    if (even) {//from ww w  . ja v a 2s .  c o  m
        cell.setGrayFill(0.8f);
    }
    setBorder(cell, first, last);
    // cell.setRotation(rotation);
    return cell;
}