Example usage for com.itextpdf.text Phrase Phrase

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

Introduction

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

Prototype

private Phrase(final boolean dummy) 

Source Link

Document

Constructs a Phrase that can be used in the static getInstance() method.

Usage

From source file:com.udec.utilidades.PdfTable.java

public PdfPTable tabla2(List<Nomina> no) throws DocumentException {
    //Instanciamos una tabla de 3 columnas
    PdfPTable tabla = new PdfPTable(4);
    tabla.setWidthPercentage(100);//from ww  w .j a va  2 s.c o m
    tabla.setWidths(new float[] { 1, 1, 1, 3 });
    //Declaramos un objeto para manejar las celdas
    PdfPCell celda;
    celda = new PdfPCell(new Phrase("Codigo:"));
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    //celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);
    if (!no.isEmpty()) {
        celda = new PdfPCell(new Phrase("" + no.get(0).getEmpleadoCodigo().getCodigo()));
        //celda.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celda);
    }

    celda = new PdfPCell(new Phrase("Nombre:"));
    //celda.setBorder(Rectangle.NO_BORDER);
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    tabla.addCell(celda);

    if (!no.isEmpty()) {
        celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getNombre()));
        //celda.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celda);
    }
    celda = new PdfPCell(new Phrase("Cedula:"));
    //celda.setBorder(Rectangle.NO_BORDER);
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    tabla.addCell(celda);
    if (!no.isEmpty()) {
        celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getCedula()));
        //celda.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celda);
    }
    celda = new PdfPCell(new Phrase("Cargo:"));
    //celda.setBorder(Rectangle.NO_BORDER);
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    tabla.addCell(celda);
    if (!no.isEmpty()) {
        celda = new PdfPCell(new Phrase(no.get(0).getEmpleadoCodigo().getCargoCargoid().getCargo()));
        //celda.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celda);
    }
    celda = new PdfPCell(new Phrase("Dias Lab:"));
    //celda.setBorder(Rectangle.NO_BORDER);
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    tabla.addCell(celda);
    if (!no.isEmpty()) {
        dt = dtC.findBySingle2("periodoIdperiodo", no.get(0).getPeriodoIdperiodo(), "empleadoCodigo",
                no.get(0).getEmpleadoCodigo());

        celda = new PdfPCell(new Phrase("" + dt.getDias()));
        //celda.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celda);
    }
    celda = new PdfPCell(new Phrase("Sueldo:"));

    //celda.setBorder(Rectangle.NO_BORDER);
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);

    tabla.addCell(celda);

    if (!no.isEmpty()) {
        celda = new PdfPCell(new Phrase("" + no.get(0).getEmpleadoCodigo().getSalario()));
        //celda.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celda);
    }

    return tabla;
}

From source file:com.udec.utilidades.PdfTable.java

public PdfPTable firma() throws DocumentException {
    PdfPTable tabla = new PdfPTable(3);
    tabla.setWidthPercentage(100);/*from w  w  w.j  a  v  a2  s .  c o m*/
    tabla.setWidths(new float[] { 2, 1, 2 });
    //Declaramos un objeto para manejar las celdas
    PdfPCell celda;

    celda = new PdfPCell(new Phrase(""));
    celda.setBorder(Rectangle.BOTTOM);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase(""));
    celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase(""));
    celda.setBorder(Rectangle.BOTTOM);
    tabla.addCell(celda);

    celda = new PdfPCell(new Phrase("JEFE ADMINISTRATIVO"));
    celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase(""));
    celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase("EMPLEADO"));
    celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);
    return tabla;
}

From source file:com.udec.utilidades.PdfTable.java

public PdfPTable tabla3(List<Nomina> no) throws DocumentException {
    //Instanciamos una tabla de 3 columnas
    PdfPTable tabla = new PdfPTable(4);
    tabla.setWidthPercentage(100);//from  w  ww.j  a  v  a 2 s. c  om
    tabla.setWidths(new float[] { 1, 3, 1, 1 });
    //Declaramos un objeto para manejar las celdas
    PdfPCell celda;
    celda = new PdfPCell(new Phrase("CODIGO"));
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    celda.setBorder(Rectangle.BOTTOM);
    celda.setVerticalAlignment(Element.ALIGN_TOP);
    celda.setBorderWidth(1);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase("DESCRIPCION"));
    celda.setBorder(Rectangle.BOTTOM);
    celda.setVerticalAlignment(Element.ALIGN_TOP);
    celda.setBorderWidth(1);
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase("VLR.DEVEN"));
    celda.setBorder(Rectangle.BOTTOM);
    celda.setVerticalAlignment(Element.ALIGN_TOP);
    celda.setBorderWidth(1);
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    celda.setBorderWidth(1);
    celda.setVerticalAlignment(Element.ALIGN_TOP);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase("VLR.DEDUC"));
    celda.setBorder(Rectangle.BOTTOM);
    celda.setVerticalAlignment(Element.ALIGN_TOP);
    celda.setBorderWidth(1);
    celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
    tabla.addCell(celda);
    double totalDev = 0, totalDed = 0;
    for (Nomina nomina : no) {
        celda = new PdfPCell(new Phrase("" + nomina.getConceptoIdconcepto().getCodigo()));
        celda.setBorder(Rectangle.NO_BORDER);
        celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        tabla.addCell(celda);
        celda = new PdfPCell(new Phrase("" + nomina.getConceptoIdconcepto().getConcepto()));
        celda.setBorder(Rectangle.NO_BORDER);
        celda.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
        tabla.addCell(celda);
        if (nomina.getConceptoIdconcepto().getTipo().equals("DEVENGADO")) {
            totalDev += nomina.getValor();
            celda = new PdfPCell(new Phrase("" + nomina.getValor()));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
            tabla.addCell(celda);
        } else {
            celda = new PdfPCell(new Phrase(""));
            celda.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(celda);
        }
        if (nomina.getConceptoIdconcepto().getTipo().equals("DEDUCIDO")) {
            totalDed += nomina.getValor();
            celda = new PdfPCell(new Phrase("" + nomina.getValor()));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
            tabla.addCell(celda);
        } else {
            celda = new PdfPCell(new Phrase(""));
            celda.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(celda);
        }

    }

    celda = new PdfPCell(new Phrase(""));
    celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase("TOTALES"));
    celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase("" + totalDev));
    celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
    celda.setBorder(Rectangle.TOP);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase(" " + totalDed));
    celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
    celda.setBorder(Rectangle.TOP);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase(""));
    celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase("NETO A PAGAR"));
    celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase(" " + (totalDev - totalDed)));
    celda.setBorder(Rectangle.NO_BORDER);
    celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
    tabla.addCell(celda);
    celda = new PdfPCell(new Phrase(" "));
    celda.setBorder(Rectangle.NO_BORDER);
    tabla.addCell(celda);

    return tabla;
}

From source file:com.vectorprint.report.itext.debug.DebugHelper.java

License:Open Source License

public static void styleLink(PdfContentByte canvas, String styleClass, String extraInfo, float x, float y,
        EnhancedMap settings, LayerManager layerAware) {
    if (styleClass == null) {
        log.warning("not showing link to styleClass because there is no styleClass");
        return;/*from   w w  w.  j a v a 2 s  .  c om*/
    }
    Font dbf = DebugHelper.debugFontLink(canvas, settings);
    layerAware.startLayerInGroup(DEBUG, canvas);

    PdfAction act = PdfAction.gotoLocalPage(styleClass, true);
    Chunk c = new Chunk(styleClass + extraInfo, dbf);
    float w = ItextHelper.getTextWidth(c);
    float h = ItextHelper.getTextHeight(c);
    float tan = (float) Math.tan(Math.toRadians(8));
    canvas.setAction(act, x, y, x + w, y + h + tan * w);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(c), x, y, 8);
    canvas.endLayer();
}

From source file:com.vectorprint.report.itext.debug.DebugHelper.java

License:Open Source License

/**
 * This method will append to the pdf a legend explaining the visual feedback in the pdf, an overview of the styles
 * used and an overview of the properties used.
 *
 * @throws DocumentException/*  www .jav a  2 s  .  c om*/
 */
public static void appendDebugInfo(PdfWriter writer, Document document, EnhancedMap settings,
        StylerFactory stylerFactory) throws DocumentException, VectorPrintException {

    PdfContentByte canvas = writer.getDirectContent();
    canvas.setFontAndSize(FontFactory.getFont(FontFactory.COURIER).getBaseFont(), 8);
    canvas.setColorFill(
            itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR)));
    canvas.setColorStroke(
            itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR)));

    Font f = FontFactory.getFont(FontFactory.COURIER, 8);

    f.setColor(itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR)));

    float top = document.getPageSize().getTop();

    document.add(new Phrase(new Chunk("table: ", f).setLocalDestination(DEBUGPAGE)));
    document.add(Chunk.NEWLINE);
    document.add(new Phrase("cell: ", f));
    document.add(Chunk.NEWLINE);
    document.add(new Phrase("image: ", f));
    document.add(Chunk.NEWLINE);
    document.add(new Phrase("text: ", f));
    document.add(Chunk.NEWLINE);
    document.add(new Phrase("background color is shown in a small rectangle", f));
    document.add(Chunk.NEWLINE);
    canvas.setLineWidth(2);
    canvas.setLineDash(new float[] { 0.3f, 5 }, 0);
    float left = document.leftMargin();
    canvas.rectangle(left + 80, top - 25, left + 80, 8);
    canvas.closePathStroke();
    canvas.setLineWidth(0.3f);
    canvas.setLineDash(new float[] { 2, 2 }, 0);
    canvas.rectangle(left + 80, top - 37, left + 80, 8);
    canvas.closePathStroke();
    canvas.setLineDash(new float[] { 1, 0 }, 0);
    canvas.rectangle(left + 80, top - 50, left + 80, 8);
    canvas.closePathStroke();
    canvas.setLineDash(new float[] { 0.3f, 5 }, 0);
    canvas.rectangle(left + 80, top - 63, left + 80, 8);
    canvas.closePathStroke();
    document.add(Chunk.NEWLINE);

    document.add(new Phrase("fonts available: " + FontFactory.getRegisteredFonts(), f));

    document.add(Chunk.NEWLINE);

    if (settings.getBooleanProperty(false, DEBUG)) {
        document.add(new Phrase("OVERVIEW OF STYLES FOR THIS REPORT", f));
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
    }

    Font b = new Font(f);
    b.setStyle("bold");
    Set<Map.Entry<String, String>> entrySet = stylerFactory.getStylerSetup().entrySet();
    for (Map.Entry<String, String> styleInfo : entrySet) {
        String key = styleInfo.getKey();
        document.add(new Chunk(key, b).setLocalDestination(key));
        document.add(new Chunk(": " + styleInfo.getValue(), f));
        document.add(Chunk.NEWLINE);
        document.add(new Phrase("   styling configured by " + key + ": ", f));
        for (BaseStyler st : (Collection<BaseStyler>) stylerFactory.getBaseStylersFromCache((key))) {
            document.add(Chunk.NEWLINE);
            document.add(new Chunk("      ", f));
            document.add(new Chunk(st.getClass().getSimpleName(), DebugHelper.debugFontLink(canvas, settings))
                    .setLocalGoto(st.getClass().getSimpleName()));
            document.add(new Chunk(":", f));
            document.add(Chunk.NEWLINE);
            document.add(new Phrase("         non default parameters for " + st.getClass().getSimpleName()
                    + ": " + getParamInfo(st), f));
            document.add(Chunk.NEWLINE);
            if (!st.getConditions().isEmpty()) {
                document.add(new Phrase("      conditions for this styler: ", f));
            }
            for (StylingCondition sc : (Collection<StylingCondition>) st.getConditions()) {
                document.add(Chunk.NEWLINE);
                document.add(new Chunk("         ", f));
                document.add(
                        new Chunk(sc.getClass().getSimpleName(), DebugHelper.debugFontLink(canvas, settings))
                                .setLocalGoto(sc.getClass().getSimpleName()));
                document.add(Chunk.NEWLINE);
                document.add(new Phrase("            non default parameters for "
                        + sc.getClass().getSimpleName() + ": " + getParamInfo(sc), f));
            }
        }
        document.add(Chunk.NEWLINE);
        document.add(Chunk.NEWLINE);
    }

    document.newPage();

    document.add(new Phrase("Properties used for the report", f));
    document.add(Chunk.NEWLINE);

    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(bo);

    settings.listProperties(ps);
    ps.close();
    document.add(new Paragraph(bo.toString(), f));

    document.newPage();

    try {
        bo = new ByteArrayOutputStream();
        ps = new PrintStream(bo);
        Help.printHelpHeader(ps);
        ps.close();
        document.add(new Paragraph(bo.toString(), f));

        Help.printStylerHelp(document, f);

        Help.printConditionrHelp(document, f);

    } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException
            | NoSuchMethodException | InvocationTargetException ex) {
        log.log(Level.SEVERE, null, ex);
    }
}

From source file:com.vectorprint.report.itext.DefaultElementProducer.java

License:Open Source License

/**
 * Creates and styles a cell with data in it. If the data is an instance of Element it is added as is to the cell,
 * otherwise a {@link #createPhrase(java.lang.Object, java.util.Collection) phrase} is created from the data.
 *
 * @param data/*from   w w  w .  ja  v  a2 s  .  com*/
 * @param stylers
 * @return
 * @throws VectorPrintException
 */
public PdfPCell createCell(Object data, Collection<? extends BaseStyler> stylers) throws VectorPrintException {
    DebuggablePdfPCell cell;

    /*
     * only when creating an instance of PdfPCell with its content (Phrase/Image/Chunk) in the constructor
     * alignment will work!
     */
    if (null != data) {
        if (data instanceof Phrase) {
            cell = new DebuggablePdfPCell((Phrase) data);
        } else if (data instanceof Chunk) {
            cell = new DebuggablePdfPCell(new Phrase((Chunk) data));
        } else if (data instanceof Image) {
            cell = new DebuggablePdfPCell((Image) data);
        } else if (data instanceof Element) {
            if (data instanceof PdfPTable) {
                cell = new DebuggablePdfPCell((PdfPTable) data);
            } else {
                throw new VectorPrintException(
                        String.format("%s not supported for a cell", data.getClass().getName()));
            }
        } else {

            cell = new DebuggablePdfPCell(createPhrase(data, stylers));
        }
    } else {

        cell = new DebuggablePdfPCell();
    }

    StylerFactoryHelper.SETTINGS_ANNOTATION_PROCESSOR.initSettings(cell, settings);

    return styleHelper.style(cell, data, stylers);
}

From source file:com.vectorprint.report.itext.DefaultElementProducer.java

License:Open Source License

/**
 * Create a Phrase, style it and add the data
 *
 * @param data//from   w  ww. ja  v a2  s . c  o m
 * @param stylers
 * @return
 * @throws VectorPrintException
 */
public Phrase createPhrase(Object data, Collection<? extends BaseStyler> stylers) throws VectorPrintException {
    return initTextElementArray(styleHelper.style(new Phrase(Float.NaN), data, stylers), data, stylers);
}

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * when failure information is appended to the report, a header on each page will be printed refering to this
 * information./*from  w  ww. ja  v a 2  s .c o m*/
 *
 * @param template
 * @param x
 * @param y
 */
protected void printFailureHeader(PdfTemplate template, float x, float y) {
    Font f = DebugHelper.debugFontLink(template, getSettings());
    Chunk c = new Chunk(getSettings().getProperty("failures in report, see end of report", "failureheader"), f);
    ColumnText.showTextAligned(template, Element.ALIGN_LEFT, new Phrase(c), x, y, 0);
}

From source file:com.vectorprint.report.itext.EventHelper.java

License:Open Source License

/**
 * prints a failure and / or a debug header when applicable.
 *
 * @see #getTemplateImage(com.itextpdf.text.pdf.PdfTemplate)
 * @param writer/* ww  w.j a  v  a 2s . co  m*/
 * @param document
 * @throws DocumentException
 * @throws VectorPrintException
 */
private final void renderHeader(PdfWriter writer, Document document)
        throws DocumentException, VectorPrintException {
    if ((!debugHereAfter && getSettings().getBooleanProperty(false, DEBUG))
            || (!failuresHereAfter && !getSettings().getBooleanProperty(false, DEBUG))) {

        writer.getDirectContent().addImage(getTemplateImage(template));

        if (getSettings().getBooleanProperty(false, DEBUG)) {
            ArrayList a = new ArrayList(2);
            a.add(PdfName.TOGGLE);
            a.add(elementProducer.initLayerGroup(DEBUG, writer.getDirectContent()));
            PdfAction act = PdfAction.setOCGstate(a, true);
            Chunk h = new Chunk("toggle debug info",
                    DebugHelper.debugFontLink(writer.getDirectContent(), getSettings())).setAction(act);

            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(h), 10,
                    document.top() - 15, 0);
            Font f = DebugHelper.debugFontLink(writer.getDirectContent(), getSettings());
            //            act = PdfAction.gotoLocalPage("debugpage", true);

            elementProducer.startLayerInGroup(DEBUG, writer.getDirectContent());

            h = new Chunk(getSettings().getProperty("go to debug legend", "debugheader"), f)
                    .setLocalGoto(BaseReportGenerator.DEBUGPAGE);
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_LEFT, new Phrase(h), 10,
                    document.top() - 3, 0);

            writer.getDirectContent().endLayer();

        }
    }
}

From source file:comisionesafis.informes.FacturasComisionesAgentesCabecera.java

@Override
public void onStartPage(PdfWriter writer, Document document) {
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase("FFF"), 200, 830, 0);
}