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

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

Introduction

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

Prototype

public void setHorizontalAlignment(int horizontalAlignment) 

Source Link

Document

Sets the horizontal alignment for the cell.

Usage

From source file:com.songbook.pc.exporter.PdfExporter.java

License:Open Source License

private Element buildQrCodeSection() throws IOException, DocumentException {
    // Load images
    Image qrApkImage = PngImage/*from  w  w  w.jav  a2  s .  com*/
            .getImage(PdfExporter.class.getResourceAsStream("/export/qr/songbook_apk_qr.png"));
    Image qrPdfImage = PngImage
            .getImage(PdfExporter.class.getResourceAsStream("/export/qr/songbook_pdf_qr.png"));

    PdfPCell cell = new PdfPCell((Phrase) null);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setVerticalAlignment(PdfPCell.ALIGN_CENTER);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100);
    table.setWidths(new float[] { 1, 2, 1 });

    cell.setImage(qrApkImage);
    table.addCell(cell);
    cell.setImage(null);

    table.addCell(cell);

    cell.setImage(qrPdfImage);
    table.addCell(cell);
    cell.setImage(null);

    cell.setPhrase(new Phrase("APP"));
    table.addCell(cell);
    cell.setPhrase(null);

    table.addCell(cell);

    cell.setPhrase(new Phrase("PDF"));
    table.addCell(cell);
    cell.setPhrase(null);

    return table;
}

From source file:corner.orm.tapestry.pdf.components.AbstractPdfTableDisplay.java

License:Apache License

/**
 * PdfPTableHeader/*from   w  w w .  j ava2 s.  c  om*/
 * 
 * @param table
 */
protected void beginTableHeader(PdfPTable table) {
    // 
    if (this.getDisplayTableModel().getHeaders() != null) {
        Font headerFont = this.getDisplayTableModel().getHeadersFont();
        if (headerFont == null) {//footer
            headerFont = PdfUtils.createHeaderSongLightFont(10);
        }
        for (int i = 0; i < getDisplayTableModel().getColumnCount(); i++) {

            // TODO ??
            PdfPCell cell = new PdfPCell(new Phrase(getDisplayTableModel().getHeaders()[i], headerFont));

            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);// 
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);// 

            table.addCell(cell);
        }
    }

}

From source file:corner.orm.tapestry.pdf.components.AbstractPdfTableDisplay.java

License:Apache License

/**
 * PdfPTableFooter//from   w w w.jav  a  2s  .  c om
 * 
 * @param table
 */
protected void beginTableFooter(PdfPTable table, PdfWriter writer) {
    if (this.getDisplayTableModel().getFooters() != null) {
        List<String> cells = this.getDisplayTableModel().getFooters();
        Font footerFont = this.getDisplayTableModel().getFootersFont();
        if (footerFont == null) {//footer
            footerFont = PdfUtils.createHeaderSongLightFont(10);
        }
        Iterator<String> it = cells.iterator();
        while (it.hasNext()) {
            String key = it.next();
            // TODO ??
            PdfPCell cell = new PdfPCell(new Phrase(key, footerFont));
            cell.setColspan(getDisplayTableModel().getColumnCount());
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);// ??
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);// 

            table.addCell(cell);
        }
    }
}

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);//  w w  w .ja v  a2  s . c o  m

    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  w w.j a  va 2  s  .  co  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

/**
 * Use the configuration information to fill the table cells
 * @param tableBuilder Table configuration
 *///from w  w  w  .  j av  a2  s.c om
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

private void formatZelle(final int zeile, final int spalte, final PdfPCell cell) {
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorderColor(new Color(//
            Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.red")), //
            Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.green")), //
            Integer.parseInt(getPdfStyle().getProperty("sudoku.board.border.color.blue"))));

    if (isEvenBlockIndex(zeile, spalte)) {
        cell.setBackgroundColor(new Color(//
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.red")), //
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.green")), //
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.odd.color.blue"))));
    } else {/* w w w .  j a va  2 s  .  co  m*/
        cell.setBackgroundColor(new Color(//
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.red")), //
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.green")), //
                Integer.parseInt(getPdfStyle().getProperty("sudoku.board.background.even.color.blue"))));
    }
    cell.setBorderWidth(PdfConstants.RAHMEN_DUENN);
    if (BoxUtils.isFirstRowInBlock(zeile, getSudokuSize())) {
        cell.setBorderWidthTop(PdfConstants.RAHMEN_DICK);
    } else {
        cell.setBorderWidthTop(PdfConstants.RAHMEN_DUENN);
    }
    if (BoxUtils.isLastColumnInRow(spalte, getSudokuSize())) {
        cell.setBorderWidthRight(PdfConstants.RAHMEN_DICK);
    } else {
        cell.setBorderWidthRight(PdfConstants.RAHMEN_DUENN);
    }
    if (BoxUtils.isLastRowInColumn(zeile, getSudokuSize())) {
        cell.setBorderWidthBottom(PdfConstants.RAHMEN_DICK);
    } else {
        cell.setBorderWidthBottom(PdfConstants.RAHMEN_DUENN);
    }
    if (BoxUtils.isFirstColumnInBlock(spalte, getSudokuSize())) {
        cell.setBorderWidthLeft(PdfConstants.RAHMEN_DICK);
    } else {
        cell.setBorderWidthLeft(PdfConstants.RAHMEN_DUENN);
    }
    cell.setFixedHeight(27f);
}

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);/*ww w .ja  v  a  2  s.co  m*/
    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 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 2  s .  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 . j ava  2 s .  co  m
        cell.setGrayFill(0.8f);
    }
    setBorder(cell, first, last);
    // cell.setRotation(rotation);
    return cell;
}