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:geoportal.presentacion.beans.ReportesControlador.java

public void imprimirReporte() {
    //DateFormat dfDateFull = DateFormat.getDateInstance(DateFormat.FULL);
    try {//from  w  w  w .  j  a  v a 2  s.  co  m

        //Generamos el archivo PDF
        String directorioArchivos;
        ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        directorioArchivos = ctx.getRealPath("/") + "reportes";
        String name = directorioArchivos + "/document-reporte.pdf";
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(name));
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(name));
        //PdfWriter writer = PdfWriter.getInstance(document,
        //new FileOutputStream("C:"));

        Paragraph paragraph = new Paragraph();
        Paragraph paragraph1 = new Paragraph();
        Paragraph paragraph2 = new Paragraph();

        //PdfPTable table = new PdfPTable(4);
        PdfPTable table1 = new PdfPTable(1);
        PdfPTable table2 = new PdfPTable(4);
        PdfPTable table3 = new PdfPTable(4);
        PdfPTable table5 = new PdfPTable(1);

        paragraph.add("\n\n\n\n\n\n\n");
        paragraph.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph1.add("\n");
        paragraph1.setAlignment(Paragraph.ALIGN_CENTER);
        paragraph2.add("Total Denuncias:" + totalDenuncias);
        paragraph2.setAlignment(Paragraph.ALIGN_LEFT);

        //  Obtenemos una instancia de nuestro manejador de eventos
        MembreteHeaderiText header = new MembreteHeaderiText();
        //Asignamos el manejador de eventos al escritor.
        writer.setPageEvent(header);

        document.open();
        //            Chunk titulo = new Chunk(CHUNK, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK));
        //
        //            titulo = new Chunk(IMAGE, FontFactory.getFont(FontFactory.COURIER, 20, Font.UNDERLINE, BaseColor.BLACK));
        //            document.add(titulo);
        //            Image foto = Image.getInstance(resources / ferrari.jpg?);
        //foto.scaleToFit(100, 100);        foto.setAlignment(Chunk.ALIGN_MIDDLE);

        //primera linea   
        PdfPCell cell5 = new PdfPCell(new Paragraph("VIOLENCIA INTRAFAMILIAR "));
        //segunda linea
        PdfPCell cell12 = new PdfPCell(new Paragraph("AO"));
        PdfPCell cell6 = new PdfPCell(new Paragraph("2010"));
        PdfPCell cell7 = new PdfPCell(new Paragraph("2011"));
        PdfPCell cell8 = new PdfPCell(new Paragraph("2012"));

        //tercera fila
        PdfPCell cell13 = new PdfPCell(new Paragraph("# DENUNCIAS"));
        PdfPCell cell9 = new PdfPCell(new Paragraph("" + lstVif2010.size()));
        PdfPCell cell10 = new PdfPCell(new Paragraph("" + lstVif2011.size()));
        PdfPCell cell11 = new PdfPCell(new Paragraph("" + lstVif_2012.size()));

        PdfPCell cell15 = new PdfPCell(new Paragraph("TOTAL DENUNCIAS:" + totalDenuncias));

        cell5.setHorizontalAlignment(Element.ALIGN_CENTER);

        cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell7.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell8.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell9.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell10.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell11.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell12.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell13.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell15.setHorizontalAlignment(Element.ALIGN_LEFT);

        cell12.setBackgroundColor(Color.cyan);
        cell13.setBackgroundColor(Color.cyan);

        cell5.setBorder(Rectangle.NO_BORDER);
        cell15.setBorder(Rectangle.NO_BORDER);

        table1.addCell(cell5);
        //aadir segunda fila
        table2.addCell(cell12);
        table2.addCell(cell6);
        table2.addCell(cell7);
        table2.addCell(cell8);
        //aadir tercera fila
        table3.addCell(cell13);
        table3.addCell(cell9);
        table3.addCell(cell10);
        table3.addCell(cell11);
        //aadir cuarta fila
        table5.addCell(cell15);

        document.add(paragraph);
        document.add(table1);
        document.add(paragraph1);
        document.add(table2);
        document.add(table3);
        document.add(table5);
        //document.add(paragraph2);

        //document.add(table);
        //document.setFooter(event);
        document.close();
        //----------------------------
        //Abrimos el archivo PDF
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "inline=filename=" + name);
        try {
            response.getOutputStream().write(Util.getBytesFromFile(new File(name)));
            response.getOutputStream().flush();
            response.getOutputStream().close();
            context.responseComplete();

        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:gov.utah.dts.det.ccl.documents.reporting.reports.InspectionsConductedReport.java

@Override
public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor fileDescriptor)
        throws TemplateException {
    FindingCategoryType fCat = getFindingCategory(context);
    PickListValue insType = getInspectionType(context);

    List<Object[]> results = getResults(context);

    ReportTable<Integer> reportTable = new ReportTable<Integer>();

    for (Object[] res : results) {
        String row = (String) res[1];
        String column = (String) res[0];
        Integer val = ((BigDecimal) res[2]).intValue();

        reportTable.addRow(row);/*from  w w w.j a  va2s .  c  o m*/
        reportTable.addColumn(column);
        reportTable.addTableDataItem(row, column, val);
    }

    setFileName(context, fileDescriptor);

    Document document = new Document(PAGE_SIZE, 36, 36, 36, 36);
    try {
        PdfWriter.getInstance(document, outputStream);
        document.open();

        StringBuilder sb = new StringBuilder();
        if (insType != null) {
            sb.append(insType.getValue());
            sb.append(" ");
        }
        sb.append("Inspections Conducted");
        if (fCat != null) {
            sb.append(" With ");
            sb.append(fCat.getDisplayName());
            sb.append(" Findings");
        }

        Paragraph heading = new Paragraph(sb.toString());
        heading.setAlignment(Element.ALIGN_CENTER);
        document.add(heading);

        Date startDate = (Date) context.get(DATE_RANGE_START_KEY);
        Date endDate = (Date) context.get(DATE_RANGE_END_KEY);

        clearStringBuilder(sb);
        if (startDate.compareTo(endDate) == 0) {
            sb.append("On ");
            sb.append(DATE_FORMATTER.format(startDate));
        } else {
            sb.append(DATE_FORMATTER.format(startDate));
            sb.append(" - ");
            sb.append(DATE_FORMATTER.format(endDate));
        }
        Paragraph date = new Paragraph(sb.toString(), FONT);
        date.setAlignment(Element.ALIGN_RIGHT);
        document.add(date);

        PdfPTable table = new PdfPTable(reportTable.getColumns().size() + 2);
        table.setHeaderRows(1);
        table.setSpacingBefore(FONT_SIZE);
        table.setWidthPercentage(100f);
        setDefaultCellAttributes(table.getDefaultCell());

        table.addCell("");
        for (Iterator<String> itr = reportTable.getColumns().iterator(); itr.hasNext();) {
            table.addCell(getHeaderCell(itr.next()));
        }
        table.addCell(getHeaderCell("Total"));
        int[] colTotals = new int[reportTable.getColumns().size() + 1];
        for (Iterator<String> rowItr = reportTable.getRows().iterator(); rowItr.hasNext();) {
            String row = rowItr.next();
            table.addCell(getHeaderCell(row));
            int total = 0;
            int idx = 0;
            for (Iterator<String> colItr = reportTable.getColumns().iterator(); colItr.hasNext();) {
                String column = colItr.next();
                Integer value = reportTable.getTableDataItem(row, column);
                if (value == null) {
                    table.addCell(getNumberCell("0"));
                } else {
                    total += value;
                    colTotals[idx] = colTotals[idx] + value;
                    table.addCell(getNumberCell(value.toString()));
                }
                idx++;
            }
            table.addCell(getHeaderCell(Integer.toString(total)));
            colTotals[colTotals.length - 1] = colTotals[colTotals.length - 1] + total;
            idx++;
        }
        table.addCell(getHeaderCell("Total"));
        for (int i = 0; i < colTotals.length; i++) {
            table.addCell(getHeaderCell(Integer.toString(colTotals[i])));
        }

        document.add(table);
    } catch (DocumentException de) {
        throw new TemplateException(de);
    }
    document.close();
}

From source file:gov.utah.dts.det.ccl.documents.reporting.reports.TopFindingsReport.java

@Override
public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor fileDescriptor)
        throws TemplateException {
    List<Object[]> results = getResults(context);

    setFileName(context, fileDescriptor);

    Document document = new Document(PAGE_SIZE, 36, 36, 36, 36);
    try {//w  w  w  . ja v  a  2 s  .co m
        PdfWriter.getInstance(document, outputStream);
        document.open();

        StringBuilder sb = new StringBuilder((String) context.get(LICENSE_TYPE_KEY));
        sb.append(" Top Findings Report");
        Paragraph heading = new Paragraph(sb.toString(), HEADING_FONT);
        heading.setAlignment(Element.ALIGN_CENTER);
        document.add(heading);

        Date startDate = (Date) context.get(DATE_RANGE_START_KEY);
        Date endDate = (Date) context.get(DATE_RANGE_END_KEY);
        ReportType reportType = ReportType.valueOf((String) context.get(REPORT_TYPE_KEY));

        clearStringBuilder(sb);
        sb.append(DATE_FORMATTER.format(startDate));
        sb.append(" - ");
        sb.append(DATE_FORMATTER.format(endDate));

        Paragraph date = new Paragraph(sb.toString(), FONT);
        date.setAlignment(Element.ALIGN_RIGHT);
        document.add(date);

        PdfPTable table = new PdfPTable(2);
        table.setHeaderRows(1);
        table.setSpacingBefore(FONT_SIZE);
        table.setWidthPercentage(100f);
        table.setWidths(new float[] { 80f, 20f });
        setDefaultCellAttributes(table.getDefaultCell());

        table.addCell(getHeaderCell("Rule Number"));
        table.addCell(getHeaderCell(reportType.getLabel()));

        double total = 0;
        for (Iterator<Object[]> itr = results.iterator(); itr.hasNext();) {
            Object[] row = itr.next();
            Paragraph p = new Paragraph();
            p.add(new Paragraph((String) row[0], TABLE_HEADER_FONT));
            p.add(new Paragraph((String) row[1], FONT));
            table.addCell(p);
            double rowTotal = ((BigDecimal) row[2]).doubleValue();
            total += rowTotal;
            if (reportType == ReportType.CMP_AMOUNT) {
                PdfPCell cell = getCurrencyCell(CURRENCY_FORMATTER.format(rowTotal));
                table.addCell(cell);
            } else {
                table.addCell(getNumberCell(Integer.toString((int) rowTotal)));
            }
        }

        PdfPCell totCell = getHeaderCell("Total");
        totCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(totCell);

        if (reportType == ReportType.CMP_AMOUNT) {
            PdfPCell cell = getHeaderCell(CURRENCY_FORMATTER.format(total));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
        } else {
            PdfPCell cell = getHeaderCell(Integer.toString((int) total));
            table.addCell(cell);
        }

        document.add(table);
    } catch (DocumentException de) {
        throw new TemplateException(de);
    }
    document.close();
}

From source file:gov.utah.health.uper.reports.Registration.java

/**
 * Builds Header Information//from w  w  w.  j a v  a2  s . c om
 * @param document
 * @throws DocumentException
 */
private void buildHeader(Document document, ApplicationBean app) throws DocumentException {

    Paragraph preface = new Paragraph("Utah Plant Extract Registry", subFont12);
    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);

    preface = new Paragraph("Issue Date:  ", subFont12);
    preface.add(app.getIssuedDate());
    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);

    preface = new Paragraph("Expiration Date:  ", subFont12);
    preface.add(app.getExpirationDate());

    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);

    preface = new Paragraph("Registration Number: ", subFont12);
    preface.add(app.getStateFileNumber());
    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);
    addSpacing(document);

}

From source file:gov.utah.health.uper.reports.Registration.java

/**
 * Builds Footer Information//from   w ww  .j av a2s . c  om
 * @param document
 * @throws DocumentException
 */
private void buildFooter(Document document) throws DocumentException {

    Paragraph preface = new Paragraph(FOOTER, footerFont);
    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);
    document.add(Chunk.NEWLINE);
    preface = new Paragraph(FOOTER_WARN, footerFontBold);
    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);

    preface = new Paragraph(FOOTER_WARNING, footerFontBold);
    preface.setAlignment(Element.ALIGN_CENTER);
    document.add(preface);

}

From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

private void renderObject(final ExportSheet exportSheet, final Table datatable) throws BadElementException {
    final Font labelFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    final Font valueFont = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);

    for (final ExportField exportColumn : exportSheet.getExportFields()) {
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), labelFont));

        datatable.getDefaultCell().setBorderWidth(1);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        final DtField dtField = exportColumn.getDtField();
        final Object value = dtField.getDataAccessor().getValue(exportSheet.getDtObject());
        final int horizontalAlignement;
        if (value instanceof Number || value instanceof Date) {
            horizontalAlignement = Element.ALIGN_RIGHT;
        } else if (value instanceof Boolean) {
            horizontalAlignement = Element.ALIGN_CENTER;
        } else {// w  w  w.j av a 2  s .c o m
            horizontalAlignement = Element.ALIGN_LEFT;
        }
        datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignement);

        String text = ExportUtil.getText(persistenceManager, referenceCache, denormCache,
                exportSheet.getDtObject(), exportColumn);
        if (text == null) {
            text = "";
        }
        datatable.addCell(new Phrase(8, text, valueFont));
    }
}

From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Effectue le rendu des headers.//from w  w w .  j  a v a2 s . c om
 *
 * @param parameters Paramtres
 * @param datatable Table
 */
private static void renderHeaders(final ExportSheet parameters, final Table datatable)
        throws BadElementException {
    // size of columns
    // datatable.setWidths(headerwidths);
    // datatable.setWidth(100f);

    // table header
    final Font font = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    datatable.getDefaultCell().setBorderWidth(2);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    // datatable.getDefaultCell().setGrayFill(0.75f);

    for (final ExportField exportColumn : parameters.getExportFields()) {
        datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), font));
    }
    // end of the table header
    datatable.endHeaders();
}

From source file:io.vertigo.dynamo.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

/**
 * Effectue le rendu de la liste./* w ww .  j a v a2 s . c o m*/
 *
 * @param parameters Paramtres
 * @param datatable Table
 */
private void renderList(final ExportSheet parameters, final Table datatable) throws BadElementException {
    // data rows
    final Font font = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
    final Font whiteFont = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);
    whiteFont.setColor(Color.WHITE);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    // datatable.getDefaultCell().setGrayFill(0);

    // Parcours des DTO de la DTC
    for (final DtObject dto : parameters.getDtList()) {
        for (final ExportField exportColumn : parameters.getExportFields()) {
            final DtField dtField = exportColumn.getDtField();
            final Object value = dtField.getDataAccessor().getValue(dto);
            final int horizontalAlignement;
            if (value instanceof Number || value instanceof Date) {
                horizontalAlignement = Element.ALIGN_RIGHT;
            } else if (value instanceof Boolean) {
                horizontalAlignement = Element.ALIGN_CENTER;
            } else {
                horizontalAlignement = Element.ALIGN_LEFT;
            }
            datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignement);

            String text = ExportUtil.getText(persistenceManager, referenceCache, denormCache, dto,
                    exportColumn);
            if (text == null) {
                text = "";
            }
            datatable.addCell(new Phrase(8, text, font));
        }
    }
}

From source file:io.vertigo.dynamo.plugins.export.rtf.RTFExporter.java

License:Apache License

/** {@inheritDoc} */
@Override/* w  ww .  ja  v a 2 s . c  om*/
protected void createWriter(final Document document, final OutputStream out) {
    // final RtfWriter2 writer =
    RtfWriter2.getInstance(document, out);
    // writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);

    // advanced page numbers : x/y
    final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL);
    //-----
    final Paragraph footerParagraph = new Paragraph();
    footerParagraph.add(new RtfPageNumber(font));
    footerParagraph.add(new Phrase(" / ", font));
    footerParagraph.add(new RtfTotalPageNumber(font));
    footerParagraph.setAlignment(Element.ALIGN_CENTER);
    //-----
    final HeaderFooter footer = new RtfHeaderFooter(footerParagraph);
    footer.setBorder(Rectangle.TOP);
    document.setFooter(footer);
}

From source file:io.vertigo.quarto.plugins.export.pdfrtf.AbstractExporterIText.java

License:Apache License

private void renderObject(final ExportSheet exportSheet, final Table datatable) throws BadElementException {
    final Font labelFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    final Font valueFont = FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL);

    for (final ExportField exportColumn : exportSheet.getExportFields()) {
        datatable.getDefaultCell().setBorderWidth(2);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(new Phrase(exportColumn.getLabel().getDisplay(), labelFont));

        datatable.getDefaultCell().setBorderWidth(1);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        final DtField dtField = exportColumn.getDtField();
        final Object value = dtField.getDataAccessor().getValue(exportSheet.getDtObject());
        final int horizontalAlignement;
        if (value instanceof Number || value instanceof LocalDate || value instanceof Instant) {
            horizontalAlignement = Element.ALIGN_RIGHT;
        } else if (value instanceof Boolean) {
            horizontalAlignement = Element.ALIGN_CENTER;
        } else {//from  w w  w  . j a v a 2  s. co  m
            horizontalAlignement = Element.ALIGN_LEFT;
        }
        datatable.getDefaultCell().setHorizontalAlignment(horizontalAlignement);

        String text = ExportUtil.getText(storeManager, referenceCache, denormCache, exportSheet.getDtObject(),
                exportColumn);
        if (text == null) {
            text = "";
        }
        datatable.addCell(new Phrase(8, text, valueFont));
    }
}