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:org.me.modelos.PDFHelper.java

public void tablaToPdf(JTable jTable, File pdfNewFile, String title) {
    try {//  w w  w .j a  va  2 s  . c o  m
        Font subCategoryFont = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD);
        Document document = new Document(PageSize.LETTER.rotate());
        PdfWriter writer = null;
        try {
            writer = PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile));
        } catch (FileNotFoundException fileNotFoundException) {
            Message.showErrorMessage(fileNotFoundException.getMessage());
        }

        writer.setBoxSize("art", new Rectangle(150, 10, 700, 580));
        writer.setPageEvent(new HeaderFooterPageEvent());
        document.open();
        document.addTitle(title);

        document.addSubject("Reporte");
        document.addKeywords("reportes, gestion, pdf");
        document.addAuthor("Gestion de Proyectos de software");
        document.addCreator("gestion de proyectos");

        Paragraph parrafo = new Paragraph(title, subCategoryFont);

        PdfPTable table = new PdfPTable(jTable.getColumnCount());
        table.setWidthPercentage(100);
        PdfPCell columnHeader;

        for (int column = 0; column < jTable.getColumnCount(); column++) {
            Font font = new Font(Font.FontFamily.HELVETICA);
            font.setColor(255, 255, 255);
            columnHeader = new PdfPCell(new Phrase(jTable.getColumnName(column), font));
            columnHeader.setHorizontalAlignment(Element.ALIGN_LEFT);
            columnHeader.setBackgroundColor(new BaseColor(96, 125, 139));
            table.addCell(columnHeader);
        }
        table.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255));
        table.setHeaderRows(1);
        BaseColor verdad = new BaseColor(255, 255, 255);
        BaseColor falso = new BaseColor(214, 230, 244);
        boolean bandera = false;
        for (int row = 0; row < jTable.getRowCount(); row++) {

            for (int column = 0; column < jTable.getColumnCount(); column++) {

                if (bandera) {
                    table.getDefaultCell().setBackgroundColor(verdad);
                } else {
                    table.getDefaultCell().setBackgroundColor(falso);
                }
                table.addCell(jTable.getValueAt(row, column).toString());
                bandera = !bandera;
            }

        }

        parrafo.add(table);
        document.add(parrafo);
        document.close();
        //JOptionPane.showMessageDialog(null, "Se ha creado el pdf en " + pdfNewFile.getPath(),
        //        "RESULTADO", JOptionPane.INFORMATION_MESSAGE);
    } catch (DocumentException documentException) {
        System.out.println("Se ha producido un error " + documentException);
        JOptionPane.showMessageDialog(null, "Se ha producido un error" + documentException, "ERROR",
                JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.openlmis.web.view.pdf.requisition.RequisitionCellFactory.java

License:Open Source License

public static PdfPCell numberCell(String value) {
    PdfPCell cell = getPdfPCell(value);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    return cell;/*from w  w w  . j a v  a 2  s.  c o m*/
}

From source file:org.openlmis.web.view.pdf.requisition.RequisitionCellFactory.java

License:Open Source License

public static PdfPCell textCell(String value) {
    PdfPCell cell = getPdfPCell(value);
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    return cell;//from w w w .  j  a v a  2s .  co m
}

From source file:org.openlmis.web.view.pdf.requisition.RequisitionCellFactory.java

License:Open Source License

public static PdfPCell headingCell(String value) {
    Chunk chunk = new Chunk(value, H2_FONT);
    PdfPCell cell = new PdfPCell(new Phrase(chunk));
    cell.setPadding(CELL_PADDING);/* w  w w .j a v  a 2 s  .  co m*/
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    return cell;
}

From source file:org.openlmis.web.view.pdf.requisition.RequisitionCellFactory.java

License:Open Source License

public static PdfPCell imageCell() throws BadElementException, IOException {
    Resource resource = new ClassPathResource(OK_IMAGE);
    Image image = Image.getInstance(resource.getFile().getAbsolutePath());
    PdfPCell cell = new PdfPCell(image);
    cell.setPadding(CELL_PADDING);/* w  w  w . ja  v a 2  s. c  om*/
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    return cell;
}

From source file:org.patientview.radar.service.impl.PdfDocumentDataBuilder.java

License:Open Source License

private PdfPCell createBaseCell(String text, Font font) {
    PdfPCell cell = new PdfPCell(new Phrase(text, font));
    cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    cell.setPadding(4f);//ww w  . j a  va  2s .  c o  m
    return cell;
}

From source file:org.qnot.passtab.PDFOutput.java

License:Open Source License

private void addCell(PdfPTable table, String str, boolean bold, boolean fill, boolean rightBorder,
        boolean bottomBorder) {
    Phrase phrase = withColor ? new Phrase(str, bold ? fontBold : font) : new Phrase(str, font);

    PdfPCell cell = new PdfPCell(phrase);

    cell.setBorder(Rectangle.NO_BORDER);
    cell.setPadding(0f);/*from   ww  w  . j a  va 2s  . c o m*/
    cell.setPaddingTop(2f);

    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);

    if (rightBorder) {
        cell.setBorderWidthRight(1f);
        cell.setPaddingRight(3f);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
    }
    if (bottomBorder) {
        cell.setBorderWidthBottom(1f);
        cell.setPaddingBottom(3f);
    }

    if (fill && this.withColor) {
        cell.setGrayFill(0.80f);
    }

    table.addCell(cell);
}

From source file:org.sharegov.cirm.utils.PDFExportUtil.java

License:Apache License

private static void createTable(Section subCatPart, Json allData) throws DocumentException {

    Json metaData = allData.at("metaData");
    PdfPTable table = null;/*from  w  w w  . j ava2  s  .  co m*/
    PdfPCell c1 = null;

    int columns = metaData.at("columns").asInteger();
    table = new PdfPTable(columns);
    table.setWidthPercentage(100);
    if (columns == 9) {
        int[] widths = { 10, 20, 12, 12, 4, 6, 6, 8, 8 };
        table.setWidths(widths);
    } else {
        int[] widths = { 10, 25, 12, 12, 4, 6, 6, 8 };
        table.setWidths(widths);
    }
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);

    c1 = new PdfPCell(new Phrase(metaData.at("boid").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("type").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("fullAddress").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("city").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("zip").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("hasStatus").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("createdDate").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    c1 = new PdfPCell(new Phrase(metaData.at("lastActivityUpdatedDate").asString(), smallBold));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
    table.addCell(c1);
    if (columns == 9) {
        c1 = new PdfPCell(new Phrase(metaData.at("gisColumn").asString(), smallBold));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(c1);
    }
    table.setHeaderRows(1);

    List<Json> data = allData.at("data").asJsonList();
    for (Json dataValue : data) {
        if (!dataValue.at("hasCaseNumber").asString().isEmpty())
            c1 = new PdfPCell(new Phrase(dataValue.at("hasCaseNumber").asString(), smallFont));
        else
            c1 = new PdfPCell(new Phrase(GenUtils.makeCaseNumber(dataValue.at("boid").asLong()), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("label").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("fullAddress").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("Street_Address_City").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("Zip_Code").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("hasStatus").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("hasDateCreated").asString(), smallFont));
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(dataValue.at("lastActivityUpdatedDate").asString(), smallFont));
        table.addCell(c1);
        if (columns == 9) {
            c1 = new PdfPCell(new Phrase(dataValue.at("gisColumn").asString(), smallFont));
            table.addCell(c1);
        }
    }

    subCatPart.add(table);
}

From source file:org.sharegov.cirm.utils.PDFViewReport.java

License:Apache License

private void addCell(PdfPTable table, String name, int align, Font font, BaseColor color) {
    PdfPCell cell = new PdfPCell(new Phrase(name, font));
    cell.setHorizontalAlignment(align);
    cell.setBorder(Rectangle.NO_BORDER);
    if (color != null)
        cell.setBackgroundColor(color);/*  w  ww .j a v  a  2s.  c o m*/
    table.addCell(cell);
}

From source file:org.sharegov.cirm.utils.PDFViewReport.java

License:Apache License

private void addCell(PdfPCell cell, PdfPTable table, String name, int align, Font font, BaseColor color) {
    cell = new PdfPCell(new Phrase(name, font));
    cell.setHorizontalAlignment(align);
    cell.setBorder(Rectangle.NO_BORDER);
    if (color != null)
        cell.setBackgroundColor(color);/*from  w  w  w.ja v  a2  s.  co m*/
    table.addCell(cell);
}