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

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

Introduction

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

Prototype

public void setHorizontalAlignment(int horizontalAlignment) 

Source Link

Document

Sets the horizontal alignment for the cell.

Usage

From source file:de.aw.awlib.pdf.PDFDocument.java

License:Open Source License

/**
 * Erstellt eine Tabelle im pdf//from w w w .j  a va2  s .co m
 *
 * @param columnHeaders
 *         Header der Tabellenspalten
 * @param cellcontent
 *         Inhalte der Tabellenzeilen
 * @throws DocumentException
 *         wenn das Document nicht erstellt werden kann.
 */
public void createTable(@NonNull String[] columnHeaders, @Nullable String summary,
        @NonNull String[][] cellcontent) throws DocumentException {
    if (summary != null) {
        addTableTitle(summary);
    }
    PdfPTable table = new PdfPTable(columnHeaders.length);
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    for (String columnHeader : columnHeaders) {
        PdfPCell c1 = new PdfPCell(new Phrase(columnHeader));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(c1);
    }
    table.setHeaderRows(1);
    for (String[] cells : cellcontent) {
        for (String cell : cells) {
            table.addCell(cell);
        }
    }
    mDocument.add(table);
}

From source file:de.beimax.talenttree.PageGeneratorSimple.java

License:Open Source License

/**
 * get celled talent text//w  ww .  j  a va  2 s  . c o m
 * @param key
 * @param talentBoxWidth
 * @param fontSize
 * @return
 * @throws Exception
 */
protected PdfPTable getTalentCell(String key, float talentBoxWidth, float fontSize) throws Exception {
    // get phrase
    Phrase phrase = parseTextProperty(key, fontSize, true);

    // table text
    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(talentBoxWidth - PDFGenerator.talentBoxStroke * 3);
    table.setLockedWidth(true);
    PdfPCell cell = new PdfPCell(phrase);
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    table.addCell(cell);
    table.completeRow();

    return table;
}

From source file:de.domjos.schooltools.core.utils.fileUtils.PDFBuilder.java

License:Open Source License

public void addTable(List<String> headers, float[] headerWidth, List<List<Map.Entry<String, BaseColor>>> cells)
        throws Exception {
    PdfPTable table = new PdfPTable(headers.size());
    if (headerWidth != null) {
        table.setWidths(headerWidth);/* ww  w .  j av  a  2s .co  m*/
    }

    for (String header : headers) {
        PdfPCell cell = new PdfPCell(
                new Phrase(header, new Font(Font.FontFamily.HELVETICA, 18, Font.BOLDITALIC)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(cell);
    }

    for (List<Map.Entry<String, BaseColor>> row : cells) {
        for (Map.Entry<String, BaseColor> cellItem : row) {
            PdfPCell cell = new PdfPCell(
                    new Phrase(cellItem.getKey(), new Font(Font.FontFamily.HELVETICA, 14, Font.NORMAL)));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setBackgroundColor(cellItem.getValue());
            table.addCell(cell);
        }
    }

    this.document.add(table);
}

From source file:de.extra.xtt.util.pdf.PdfCreatorImpl.java

License:Apache License

/**
 * Erzeugt das Inhaltsverzeichnis aus den bereits vorhandenen Elementen in
 * der Liste <code>listEntries</code>.
 * //from  w  ww  .  jav a 2s  .c o  m
 * @param docPdf
 *            Zieldokument, falls Inhaltsverzeichnis nicht temporr erzeugt
 *            wird
 * @param temp
 *            Gibt an, ob das Inhaltsverzeichnis temporr in einer neuen
 *            Datei/Dokument erzeugt werden soll
 * @return Anzahl der Seiten
 * @throws DocumentException
 * @throws IOException
 */
private int erzeugeInhaltsverzeichnis(Document docPdf, boolean temp) throws DocumentException, IOException {

    int anzPages = 0;
    Document docInhalt = docPdf;
    String filePathTempInhaltString = "";

    if (temp) {
        // temp. Dateinamen bestimmen
        File fileDokuFile = new File(dateiname);
        filePathTempInhaltString = fileDokuFile.getParent() + "/tmp_inhalt.pdf";
        // Neues Dokument erzeugen
        docInhalt = initPdfWriterAndDocument(filePathTempInhaltString, false);
    }

    // berschrift
    Chapter currChapter = new Chapter(getParagraphChapter("Inhaltsverzeichnis"), 0);
    // 0, damit keine Nummerierung
    currChapter.setNumberDepth(0);
    docInhalt.add(currChapter);
    // eine Zeile Abstand
    docInhalt.add(getEmptyLineTextHalf());

    for (ContPdfEntry currEntry : listEntries) {

        // Eintrag erzeugen inkl. Abstand
        String strEintrag = currEntry.getBezeichnung() + "  ";
        Chunk chunkBezeichnung;
        Chunk chunkSeitenzahlChunk;
        if (currEntry.getParentEntry() == null) {
            // 1. Ebene => fett, Abstand davor einfgen
            docInhalt.add(getEmptyLineTextHalf());
            chunkBezeichnung = getChunkTextBold(strEintrag);
            chunkSeitenzahlChunk = getChunkTextBold("" + currEntry.getPageNumber());
        } else {
            // 2. Ebene
            chunkBezeichnung = getChunkText(strEintrag);
            chunkSeitenzahlChunk = getChunkText("" + currEntry.getPageNumber());
        }
        // Referenz setzen
        chunkBezeichnung.setLocalGoto(currEntry.getDestination());
        chunkSeitenzahlChunk.setLocalGoto(currEntry.getDestination());
        // Abstandzeichen generieren, Breite auffllen
        float widthAbstand = docInhalt.getPageSize().getWidth() * 0.81f;
        ;
        while (chunkBezeichnung.getWidthPoint() <= widthAbstand) {
            chunkBezeichnung.append(".");
        }

        // Tabelle erzeugen und formatieren
        PdfPTable currTable = new PdfPTable(2);
        currTable.setWidthPercentage(100f);
        currTable.setWidths(new int[] { 96, 4 });

        // Inhalte einfgen
        // Zelle Bezeichnung
        PdfPCell currCellBezeichnung = new PdfPCell(new Phrase(chunkBezeichnung));
        currCellBezeichnung.setBorder(0);
        currCellBezeichnung.setHorizontalAlignment(Element.ALIGN_JUSTIFIED_ALL);

        // Zelle Seitennummer
        PdfPCell currCellPageNumberCell = new PdfPCell(new Phrase(chunkSeitenzahlChunk));
        currCellPageNumberCell.setBorder(0);
        currCellPageNumberCell.setHorizontalAlignment(Element.ALIGN_RIGHT);

        // Zellen zur Tabelle hinzufgen
        currTable.addCell(currCellBezeichnung);
        currTable.addCell(currCellPageNumberCell);

        docInhalt.add(currTable);
    }

    if (temp) {
        // Dokument schlieen
        docInhalt.close();

        // Anzahl der Seitenzahlen bestimmen
        PdfReader reader = new PdfReader(filePathTempInhaltString);
        anzPages = reader.getNumberOfPages();
        reader.close();

        // temp. Datei lschen
        File currFileInhaltFile = new File(filePathTempInhaltString);
        currFileInhaltFile.delete();
    }
    return anzPages;
}

From source file:de.fau.osr.util.matrix.MatrixTools.java

License:Open Source License

/**
 * adds new cell to table//from  w  ww.  j  ava 2 s .c  om
 * @param table table to work with
 * @param text content of cell
 * @param fontSize font fontSize
 * @param alignment enum alignment
 * @param rowFixedHeight cell fixed height
 * @return added cell
 */
private static PdfPCell addCell(PdfPTable table, String text, int fontSize, int alignment,
        float rowFixedHeight) {
    Phrase ph = new Phrase(text, getFont(fontSize));
    PdfPCell cell = new PdfPCell(ph);
    cell.setHorizontalAlignment(alignment);
    if (rowFixedHeight > 0)
        cell.setFixedHeight(rowFixedHeight);
    table.addCell(cell);
    return cell;
}

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

public void addColumn(byte[] image, int width, int height, int horizontalalignment)
        throws BadElementException, MalformedURLException, IOException {
    Image i = Image.getInstance(image);
    float w = i.getWidth() / width;
    float h = i.getHeight() / height;
    if (w > h) {
        h = i.getHeight() / w;/*from   w w  w  .j a va  2 s.  c om*/
        w = width;
    } else {
        w = i.getHeight() / h;
        h = height;
    }
    i.scaleToFit(w, h);
    PdfPCell cell = new PdfPCell(i, false);
    cell.setPadding(3);
    cell.setHorizontalAlignment(horizontalalignment);
    table.addCell(cell);
}

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

/**
 * Erzeugt eine Zelle der Tabelle.//from  w  ww . j a  v a2 s. c  om
 * 
 * @param text
 *          der anzuzeigende Text.
 * @param align
 *          die Ausrichtung.
 * @param backgroundcolor
 *          die Hintergundfarbe.
 * @return die erzeugte Zelle.
 */
private PdfPCell getDetailCell(String text, int align, BaseColor backgroundcolor, boolean silbentrennung) {
    PdfPCell cell = null;
    if (silbentrennung) {
        cell = new PdfPCell(new Phrase(new Chunk(notNull(text), getFreeSans(8)).setHyphenation(hyph)));
    } else {
        cell = new PdfPCell(new Phrase(new Chunk(notNull(text), getFreeSans(8))));
    }
    cell.setHorizontalAlignment(align);
    cell.setBackgroundColor(backgroundcolor);
    return cell;
}

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

private PdfPCell getDetailCell(String text, int align, BaseColor backgroundcolor, int colspan) {
    PdfPCell cell = new PdfPCell(new Phrase(new Chunk(notNull(text), getFreeSans(8)).setHyphenation(hyph)));
    cell.setHorizontalAlignment(align);
    cell.setBackgroundColor(backgroundcolor);
    cell.setColspan(colspan);/* w w  w  . j a va  2s  . com*/
    return cell;
}

From source file:de.jost_net.JVerein.io.Reporter.java

License:Open Source License

/**
 * Erzeugt eine Zelle fuer die uebergebene Zahl.
 * // w ww .  ja va 2  s . co  m
 * @param value
 *          die Zahl.
 * @return die erzeugte Zelle.
 */
private PdfPCell getDetailCell(double value) {
    Font f = null;
    if (value >= 0) {
        f = getFreeSans(8, BaseColor.BLACK);
    } else {
        f = getFreeSans(8, BaseColor.RED);
    }
    PdfPCell cell = new PdfPCell(new Phrase(Einstellungen.DECIMALFORMAT.format(value), f));
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return cell;
}

From source file:Documentos.ReportesPDF.java

public void agregarTabla(Paragraph parrafo) {
    //Anchos de las columnas
    PdfPTable tabla = new PdfPTable(anchosFilas);
    // Porcentaje que ocupa a lo ancho de la pagina del PDF
    tabla.setWidthPercentage(90);/*w w  w . jav  a 2  s.co  m*/
    //Alineacion horizontal centrada
    tabla.setHorizontalAlignment(Element.ALIGN_CENTER);
    //agregar celda que ocupa las  columnas de los rotulos
    PdfPCell cell0 = new PdfPCell(new Paragraph("Repostera AnaIs"));
    cell0.setColspan(anchosFilas.length);
    cell0.setBackgroundColor(new BaseColor(66, 139, 202));
    //Centrar contenido de celda
    cell0.setHorizontalAlignment(Element.ALIGN_CENTER);
    PdfPCell cell = new PdfPCell(new Paragraph(tituloReporte()));
    cell.setColspan(anchosFilas.length);
    cell.setBackgroundColor(new BaseColor(49, 176, 213));
    //Centrar contenido de celda
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    //Color de fondo de la celda     
    tabla.addCell(cell0);
    tabla.addCell(cell);
    // Mostrar los rotulos de las columnas
    for (int i = 0; i < rotulosColumnas.length; i++) {
        cell = new PdfPCell(new Paragraph(rotulosColumnas[i]));
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(new BaseColor(248, 248, 248));
        tabla.addCell(cell);
    }
    switch (numReport) {
    case 1:
        DataBase.DataBasePDF.pdfVendedores(cell, tabla);
        break;
    case 2:
        DataBase.DataBasePDF.pdfProveedores(cell, tabla);
        break;
    case 3:
        DataBase.DataBasePDF.pdfClientes(cell, tabla);
        break;
    case 4:
        DataBase.DataBasePDF.pdfVentas(cell, tabla);
        break;
    case 5:
        DataBase.DataBasePDF.pdfProductos(cell, tabla);
        break;
    case 6:
        DataBase.DataBasePDF.pdfPedidos(cell, tabla);
        break;
    }

    //Agregar la tabla con los datos al parrafo que nos llego como entrada
    parrafo.add(tabla);
}