Example usage for com.itextpdf.text Chunk Chunk

List of usage examples for com.itextpdf.text Chunk Chunk

Introduction

In this page you can find the example usage for com.itextpdf.text Chunk Chunk.

Prototype

private Chunk(final Float tabInterval, final boolean isWhitespace) 

Source Link

Document

Creates a tab Chunk.

Usage

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printAttributes(Section section, List<Attribute> attrs, int parentLevel) {
    Paragraph sTitle = new Paragraph("Activity Attributes", subSectionFont);
    Section subsection = section.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1));
    com.itextpdf.text.List list = new com.itextpdf.text.List(false, false, 20.0f);
    for (Attribute attr : attrs) {
        if (excludeAttribute(attr.getAttributeName(), attr.getAttributeValue()))
            continue;
        Phrase phrase = new com.itextpdf.text.Phrase();
        phrase.add(new Chunk(attr.getAttributeName(), fixedWidthFont));
        String v = attr.getAttributeValue();
        if (v == null)
            v = "";
        phrase.add(new Chunk(": " + v, normalFont));
        list.add(new ListItem(phrase));
    }//  www .  j  a  v  a 2  s .com
    subsection.add(list);
}

From source file:com.centurylink.mdw.pdf.PdfExportHelper.java

License:Apache License

private void printVariables(Chapter chapter, List<Variable> variables, int parentLevel) {
    Paragraph sTitle = new Paragraph("Process Variables", sectionFont);
    Section section = chapter.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1));
    com.itextpdf.text.List list = new com.itextpdf.text.List(false, false, 10.0f);
    for (Variable var : variables) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(var.getName(), fixedWidthFont));
        String v = var.getType();
        if (var.getDescription() != null)
            v += " (" + var.getDescription() + ")";
        phrase.add(new Chunk(": " + v + "\n", normalFont));
        list.add(new ListItem(phrase));
    }/*from   www . j a  v  a2s  .  c  o  m*/
    section.add(list);
}

From source file:com.chaschev.itext.ChunkBuilder.java

License:Apache License

public ChunkBuilder withNew(final String content, final Font font) {
    element = new Chunk(content, font);
    return this;
}

From source file:com.chaschev.itext.ColumnTextBuilder.java

License:Apache License

public ColumnTextBuilder addTruncatedLine(Chunk chunk, boolean addEllipsis) {
    final float pixelsForEllipsis = 6;

    try {//from ww  w  .j  ava2s. c o  m
        ColumnText dup = ColumnText.duplicate(columnText);

        final Rectangle oneLineRectangle = new Rectangle(simpleColumnRectangle);

        oneLineRectangle.setTop(dup.getYLine());

        final float fontHeight = calcApproximateFontHeight(chunk.getFont()) * 1.6f;

        oneLineRectangle.setBottom(dup.getYLine() - fontHeight);

        if (addEllipsis) {
            oneLineRectangle.setRight(oneLineRectangle.getRight() - pixelsForEllipsis);
        }

        dup.setSimpleColumn(oneLineRectangle);
        dup.addText(chunk);

        final int status = dup.go();

        float yLine;

        if (addEllipsis && ColumnText.hasMoreText(status)) {
            oneLineRectangle.setLeft(dup.getLastX() + 2);
            oneLineRectangle.setRight(oneLineRectangle.getRight() + pixelsForEllipsis * 2);

            dup = ColumnText.duplicate(dup);

            dup.setSimpleColumn(oneLineRectangle);

            final Chunk ellipses = new Chunk("...\n", chunk.getFont());

            dup.setText(new Phrase(ellipses));
            dup.go();
            yLine = dup.getYLine();
        } else {
            yLine = dup.getYLine();
        }

        setYLine(yLine);

        return this;

    } catch (DocumentException e) {
        throw Exceptions.runtime(e);
    }
}

From source file:com.chaschev.itext.ITextBuilder.java

License:Apache License

public Phrase newPhrase(String text, Font font) {
    final Chunk element = new Chunk(text, font);
    //        element.setHyphenation(new HyphenationAuto("en", "US", 3, 3));
    return phrase().add(element).build();
}

From source file:com.cib.statementstamper.windows.StatementStamperMainWindow.java

License:Open Source License

protected PdfPTable getFooterTable(int x, int y) {
    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(537);/* w w  w .j a va 2s .c o  m*/
    table.setLockedWidth(true);
    table.getDefaultCell().setFixedHeight(40);
    table.getDefaultCell().setBorder(Rectangle.TOP);
    table.getDefaultCell().setBorderColor(new BaseColor(221, 72, 20));
    table.getDefaultCell().setBorderWidth(1);
    table.getDefaultCell().setPaddingLeft(0);
    table.getDefaultCell().setPaddingRight(0);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    Phrase phrase = new Phrase();
    phrase.add(new Chunk(bottomChunk1, bottomFontBold));
    phrase.add(new Chunk(bottomChunk2, bottomFont));
    table.addCell(phrase);
    return table;
}

From source file:com.datamyne.charts.FinallyDemo.java

License:Apache License

/**
 * Creates PDf file./*from   w ww  . ja  v a  2s. c  o m*/
 * @param outputStream {@link OutputStream}.
 * @throws DocumentException
 * @throws IOException
 */
public void create(OutputStream outputStream) throws DocumentException, IOException {
    Document document = null;
    PdfWriter writer = null;

    try {
        //instantiate document and writer
        document = new Document();
        writer = PdfWriter.getInstance(document, outputStream);

        //open document
        document.open();

        //get dummy text
        String text = getText();
        //create text font
        com.itextpdf.text.Font font = new com.itextpdf.text.Font(FontFamily.TIMES_ROMAN, 10.0f);

        //add text before
        document.add(new Paragraph(new Chunk(text, font)));

        //add image
        int width = 300;
        int height = 300;
        JFreeChart chart = getChart();

        //create PdfContentByte
        //if you work with this object, you write to
        //the top most layer, meaning anything behind
        //will be clipped
        PdfContentByte contentByte = writer.getDirectContent();
        //create PdfTemplate from PdfContentByte
        PdfTemplate template = contentByte.createTemplate(width, height);
        //create Graphics2D from PdfTemplate
        Graphics2D g2 = template.createGraphics(width, height, new DefaultFontMapper());
        //setup the drawing area
        Rectangle2D r2D = new Rectangle2D.Double(0, 0, width, height);
        //pass the Graphics2D and drawing area to JFreeChart
        chart.draw(g2, r2D, null);
        g2.dispose(); //always dispose this

        //create Image from PdfTemplate
        Image image = Image.getInstance(template);
        document.add(image);

        //add text after
        document.add(new Paragraph(new Chunk(text, font)));

        //release resources
        document.close();
        document = null;

        writer.close();
        writer = null;
    } catch (DocumentException de) {
        throw de;
    } finally {
        //release resources
        if (null != document) {
            try {
                document.close();
            } catch (Exception ex) {
            }
        }

        if (null != writer) {
            try {
                writer.close();
            } catch (Exception ex) {
            }
        }
    }
}

From source file:com.devox.GUI.PDF.CrearReporteApto.java

private static Phrase getPhraseFromChunks(String a, String b) {
    Phrase phrase = new Phrase();
    phrase.add(new Chunk(a, FUENTE_DATOS_IZQ));
    phrase.add(new Chunk(b, FUENTE_DATOS_DER));
    return phrase;
}

From source file:com.devox.GUI.PDF.CrearReporteDestruccion.java

@Override
public PdfPTable configurarInformacion() {
    PdfPTable table = new PdfPTable(2);
    try {//  w ww  .j a  va2 s  .  c  o m
        PdfPCell cell;
        Phrase folio = new Phrase();
        folio.add(new Chunk("FOLIO DHL ", FUENTE_FOLIO_CHICA));
        folio.add(new Chunk(contenido.getFolioDHL(), FUENTE_FOLIO_CHICA_ROJA));
        cell = new PdfPCell(folio);
        cell.setRowspan(8);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("Cliente ", contenido.getNombreCliente()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("Nmero de cliente ", contenido.getClaveCliente()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("Folio del cliente ", contenido.getFolioCliente()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("Folio Abbott ", contenido.getFolioAbbott()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("Motivo de devolucin ",
                contenido.getMotivo().getCodigo() + " - " + contenido.getMotivo().getDescripcion()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("Factura ", contenido.getFactura()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("Almacn ", contenido.getAlmacen()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(
                getPhraseFromChunks("Fecha de captura ", Funciones.getOtherDate(contenido.getFechaCaptura())));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);

        table.setWidthPercentage(100);
        table.setWidths(new int[] { 1, 3 });

    } catch (DocumentException ex) {
        Log.print(ex);
    }
    return table;
}

From source file:com.devox.GUI.PDF.CrearReporteTarimas.java

@Override
public PdfPTable configurarInformacion() {
    PdfPTable table = new PdfPTable(2);
    try {/*from w  w  w  . jav  a2  s.c  o m*/
        PdfPCell cell;
        Phrase tarima = new Phrase();
        tarima.add(new Chunk("TARIMA\n", FUENTE_TARIMA_NEGRO));
        tarima.add(new Chunk(datosTarima.getNombreTarima(), FUENTE_TARIMA_ROJO));
        cell = new PdfPCell(tarima);
        cell.setRowspan(5);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        cell.setFixedHeight(200f);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("DIVISIN ", datosTarima.getDivision()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("ALMACN ", datosTarima.getAlmacen()));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("FECHA DE APERTURA ",
                Funciones.getOtherDate(datosTarima.getFecha_Apertura())));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("FECHA DE CIERRE ",
                (datosTarima.getFecha_Cierra() == null ? "TARIMA ABIERTA"
                        : Funciones.getOtherDate(datosTarima.getFecha_Cierra()))));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);
        cell = new PdfPCell(getPhraseFromChunks("DESTRUCCIN FISCAL ",
                Integer.toString(datosTarima.getDestruccionFiscal())));
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setPaddingLeft(40);
        table.addCell(cell);

        table.setWidthPercentage(100);
        table.setWidths(new int[] { 2, 1 });
    } catch (DocumentException de) {
        Log.print(de);
    }
    return table;
}