Example usage for com.lowagie.text Element ALIGN_CENTER

List of usage examples for com.lowagie.text Element ALIGN_CENTER

Introduction

In this page you can find the example usage for com.lowagie.text Element ALIGN_CENTER.

Prototype

int ALIGN_CENTER

To view the source code for com.lowagie.text Element ALIGN_CENTER.

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:com.itext.test.FirstPdf.java

private static void createTable(Section subCatPart) throws BadElementException {
    //PdfPTable//from w  ww  .ja  va  2 s  .c  om
    PdfPTable table = new PdfPTable(3);
    //PdfPTable
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    //PDFPCell
    PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1"));
    //PdfPCellHorizontalAlignment?
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    //celltable
    table.addCell(c1);
    //PDFPCell
    c1 = new PdfPCell(new Phrase("Table Header 2"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Table Header 3"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    table.setHeaderRows(1);

    table.addCell("1.0");
    table.addCell("1.1");
    table.addCell("1.2");
    table.addCell("2.1");
    table.addCell("2.2");
    table.addCell("2.3");

    subCatPart.add(table);

}

From source file:com.itn.excelDao.PdfView.java

@Override
protected void buildPdfDocument(Map<String, Object> model, Document document, PdfWriter writer,
        HttpServletRequest request, HttpServletResponse response) throws Exception {

    //Users user = (Users) model.get("user");
    List<Users> userlist = (List<Users>) model.get("allUsers");

    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.getDefaultCell().setBackgroundColor(Color.lightGray);

    table.addCell("ID");
    table.addCell("First Name");
    table.addCell("Last Name");
    table.addCell("Email");

    for (Users users : userlist) {
        table.addCell(users.getId().toString());
        table.addCell(users.getFirstName());
        table.addCell(users.getLastName());
        table.addCell(users.getEmail());
    }// w  ww  . ja v  a  2  s.c o  m

    document.add(table);

}

From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java

License:Apache License

/**
 * Creates the pdf footer./* w  w  w.jav a 2  s. c  om*/
 *
 * @param pdfPTable
 *            the pdf P table
 * @param font
 *            the font
 * @throws DocumentException
 *             the document exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void createPdfFooter(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException {
    final float width = pdfPTable.getWidthPercentage();
    final int headerWidth = (int) width;
    font = getFont();
    final PdfPCell footerCell = new PdfPCell(new Phrase(getFooter(), font));
    footerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    footerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    footerCell.setColspan(headerWidth);
    footerCell.setBorder(0);
    footerCell.setUseDescender(true);
    pdfPTable.addCell(footerCell);
    pdfPTable.setFooterRows(1);
}

From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java

License:Apache License

/**
 * Creates the pdf headers./*from  ww w  .j a v a2 s.c o m*/
 *
 * @param pdfPTable
 *            the pdf P table
 * @param font
 *            the font
 * @throws DocumentException
 *             the document exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void createPdfHeaders(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException {
    font = getFont();
    final float width = pdfPTable.getWidthPercentage();
    final int headerWidth = (int) width;
    final PdfPCell headersCells = new PdfPCell(new Phrase(getHeader(), font));
    headersCells.setHorizontalAlignment(Element.ALIGN_CENTER);
    headersCells.setColspan(headerWidth);
    headersCells.setUseDescender(true);
    headersCells.setBorder(0);
    pdfPTable.addCell(headersCells);
    for (int i = 0; i < this.model.getColumnCount(); i++) {
        if (this.model.isVisible(i)) {
            final PdfPCell cell = new PdfPCell(new Phrase(Lables.get(this.model.getActualColumnName(i)), font));
            cell.setRotation(getRotationDegree());
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            pdfPTable.addCell(cell);
        }
    }
    // Please explain
    pdfPTable.setHeaderRows(3);
    createPdfFooter(pdfPTable, font);

}

From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java

License:Apache License

/**
 * Creates the pdf table.// ww  w  .  j a  v a 2  s .c o m
 *
 * @return the pdf P table
 * @throws DocumentException
 *             the document exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public PdfPTable createPdfTable() throws DocumentException, IOException {
    final Font font = getFont();
    int columnCount = 0;
    for (int i = 0; i < this.model.getColumnCount(); i++) {
        if (this.model.isVisible(i)) {
            columnCount++;
        }
    }
    final PdfPTable pdfPTable = new PdfPTable(columnCount);
    pdfPTable.setRunDirection(getRunDirection());
    pdfPTable.getDefaultCell().setRunDirection(getRunDirection());
    pdfPTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    pdfPTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
    pdfPTable.getDefaultCell().setNoWrap(true);

    createPdfHeaders(pdfPTable, font);
    loadDataTable(pdfPTable, font);
    return pdfPTable;

}

From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java

License:Apache License

/**
 * Load data table.//w  w w.  jav a2 s  .com
 *
 * @param pdfPTable
 *            the pdf P table
 * @param font
 *            the font
 * @throws DocumentException
 *             the document exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void loadDataTable(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException {
    font = getFont();
    for (int row = 0; row < this.model.getRowCount(); row++) {
        for (int column = 0; column < this.model.getColumnCount(); column++) {
            if (this.model.isVisible(column)) {
                final PdfPCell cell = new PdfPCell(
                        new Phrase((String) this.model.getValueAt(row, column), font));
                cell.setNoWrap(true);
                cell.setRunDirection(getRunDirection());
                // TODO : make the alignment according to the colunm
                // datatype
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                pdfPTable.addCell(cell);
            }
        }
    }
}

From source file:com.kahlon.guard.controller.DocumentManager.java

/**
 *
 * @param document/*from   ww  w. j  av  a2  s  . com*/
 */
public void preProcessPDF(Object document) {
    try {

        BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false);

        Document pdf = (Document) document;
        pdf.setPageSize(PageSize.A4);
        pdf.setMargins(5f, 5f, 10f, 5f);

        // headers and footers must be added before the document is opened
        HeaderFooter footer = new HeaderFooter(new Phrase("page: ", new Font(bf_courier)), true);
        footer.setBorder(Rectangle.NO_BORDER);
        footer.setAlignment(Element.ALIGN_CENTER);
        pdf.setFooter(footer);

        //            HeaderFooter header = new HeaderFooter(
        //                        new Phrase("This is a header without a page number", new Font(bf_courier)), false);
        //            header.setAlignment(Element.ALIGN_CENTER);
        //            pdf.setHeader(header);

        pdf.open();

        String logoPath = "/resources/image/logo.png";
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
        String logo = servletContext.getRealPath(logoPath);

        pdf.add(Image.getInstance(logo));

        Person person = context.getSelectedPerson().getDisplayPerson();

        String name = FacesMessageUtil.getMessage("person.name") + " : " + person.getName();
        String age = FacesMessageUtil.getMessage("person.age") + " : " + Integer.toString(person.getAge());
        String gender = FacesMessageUtil.getMessage("person.gender") + " : "
                + person.getGender().getDescription();
        String race = FacesMessageUtil.getMessage("person.ethnicity") + " : "
                + person.getEthnicity().getDescription();

        Person rootPerson = person.getRootPerson();
        PersonImage imgp = imageService.getLastestPersonImage(rootPerson.getId());
        Image imgb = Image.getInstance(imgp.getContent());
        imgb.scaleToFit(100, 120);

        PdfPTable headerTable = new PdfPTable(2);

        PdfPTable personTable = new PdfPTable(1);
        personTable.setWidthPercentage(100);
        PdfPCell cell;

        cell = new PdfPCell(new Phrase(name));
        cell.setBorder(Rectangle.NO_BORDER);
        personTable.addCell(cell);

        cell = new PdfPCell(new Phrase(age));
        cell.setBorder(Rectangle.NO_BORDER);
        personTable.addCell(cell);

        cell = new PdfPCell(new Phrase(gender));
        cell.setBorder(Rectangle.NO_BORDER);
        personTable.addCell(cell);

        cell = new PdfPCell(new Phrase(race));
        cell.setBorder(Rectangle.NO_BORDER);
        personTable.addCell(cell);

        BarcodePDF417 pdf417 = new BarcodePDF417();
        pdf417.setText(Integer.toString(person.getId()));
        Image img = pdf417.getImage();
        img.scalePercent(150, 60 * pdf417.getYHeight());
        cell = new PdfPCell(img);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setPaddingTop(15);
        personTable.addCell(cell);

        cell.addElement(personTable);
        headerTable.addCell(cell);

        cell = new PdfPCell(imgb);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setBorder(Rectangle.NO_BORDER);
        headerTable.addCell(cell);

        headerTable.setSpacingAfter(15);
        pdf.add(headerTable);

        LineSeparator lineSeparator = new LineSeparator();
        lineSeparator.setPercentage(82);
        pdf.add(lineSeparator);
        Paragraph space = new Paragraph();
        space.add("");
        space.setSpacingAfter(15);
        pdf.add(space);

    } catch (IOException e) {
        logger.log(Level.INFO, e.getMessage());
    } catch (BadElementException e) {
        logger.log(Level.INFO, e.getMessage());
    } catch (DocumentException e) {
        logger.log(Level.INFO, e.getMessage());
    } catch (Exception e) {
        logger.log(Level.INFO, e.getMessage());
    }

}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void addSubtotal(String[] data) throws DocumentException {

    // add dashed line...
    for (String value : data) {

        String v = null;//w  w  w  .  j ava 2  s  .co  m
        String rawValue = value(value);
        if (StringUtils.isNotEmpty(rawValue)) {
            v = line(rawValue, SINGLE_LINE);
        }

        PdfPCell c1 = new PdfPCell(new Phrase(v, font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(value));
        setCellPadding(c1);
        detailTable.addCell(c1);
    }

    // add totals....
    for (String value : data) {
        PdfPCell c1 = new PdfPCell(new Phrase(value(value), font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(alignment(value));
        setCellPadding(c1);
        detailTable.addCell(c1);
    }

    // add blank line....
    for (String value : data) {
        PdfPCell c1 = new PdfPCell(new Phrase(" ", font));
        c1.setBorder(Rectangle.NO_BORDER);
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        setCellPadding(c1);
        detailTable.addCell(c1);
    }

}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private int alignment(String value) {

    String[] e = parse(value);/* ww  w  . j av  a 2  s  .c  o m*/
    if (e[0] != null) {

        if (e[0].equals(LEFT)) {
            return Element.ALIGN_LEFT;
        }
        if (e[0].equals(RIGHT)) {
            return Element.ALIGN_RIGHT;
        }

    }

    return Element.ALIGN_CENTER;

}

From source file:com.khs.report.writer.ReportPDFWriter.java

License:Apache License

private void createFootings(String footing) throws DocumentException {
    String[] cols = footing.split(ReportProcessor.ALIGN_DELIMITER, 3);
    float[] colSizes = new float[] { 25, 50, 25 };

    footerTable = new PdfPTable(colSizes);
    footerTable.setWidthPercentage(getHeadingWidth());

    int count = 0;
    for (String c : cols) {
        PdfPCell c1 = new PdfPCell(new Phrase(value(c), font));

        c1.setBorder(Rectangle.NO_BORDER);
        int alignment = Element.ALIGN_CENTER;
        if (count == 0) {
            alignment = Element.ALIGN_LEFT;
        } else if (count == 2) {
            alignment = Element.ALIGN_RIGHT;
        }//from w w w  . j a va  2s . c o  m
        c1.setHorizontalAlignment(alignment);
        setCellPadding(c1);
        footerTable.addCell(c1);
        count++;
    }
}