Example usage for com.lowagie.text Element ALIGN_JUSTIFIED

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

Introduction

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

Prototype

int ALIGN_JUSTIFIED

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

Click Source Link

Document

A possible value for paragraph alignment.

Usage

From source file:com.develog.utils.report.engine.export.JRPdfExporter.java

License:Open Source License

/**
 *
 */// ww w .j  a v  a  2s.c  o m
protected void exportText(JRPrintText text) throws JRException, DocumentException, IOException {
    JRStyledText styledText = getStyledText(text);

    if (styledText == null) {
        return;
    }

    int textLength = styledText.length();

    int x = text.getX();
    int y = text.getY();
    int width = text.getWidth();
    int height = text.getHeight();

    double angle = 0;

    switch (text.getRotation()) {
    case JRTextElement.ROTATION_LEFT: {
        y = text.getY() + text.getHeight();
        width = text.getHeight();
        height = text.getWidth();
        angle = Math.PI / 2;
        break;
    }
    case JRTextElement.ROTATION_RIGHT: {
        x = text.getX() + text.getWidth();
        width = text.getHeight();
        height = text.getWidth();
        angle = -Math.PI / 2;
        break;
    }
    case JRTextElement.ROTATION_NONE:
    default: {
    }
    }

    AffineTransform atrans = new AffineTransform();
    atrans.rotate(angle, x, jasperPrint.getPageHeight() - y);
    pdfContentByte.transform(atrans);

    if (text.getMode() == JRElement.MODE_OPAQUE) {
        pdfContentByte.setRGBColorStroke(text.getBackcolor().getRed(), text.getBackcolor().getGreen(),
                text.getBackcolor().getBlue());
        pdfContentByte.setRGBColorFill(text.getBackcolor().getRed(), text.getBackcolor().getGreen(),
                text.getBackcolor().getBlue());
        pdfContentByte.setLineWidth(1f);
        pdfContentByte.setLineDash(0f);
        pdfContentByte.rectangle(x, jasperPrint.getPageHeight() - y, width - 1, -height + 1);
        pdfContentByte.fillStroke();
    } else {
        /*
        pdfContentByte.setRGBColorStroke(
           text.getForecolor().getRed(),
           text.getForecolor().getGreen(),
           text.getForecolor().getBlue()
           );
        pdfContentByte.setLineWidth(0.1f);
        pdfContentByte.setLineDash(0f);
        pdfContentByte.rectangle(
           text.getX(),
           jasperPrint.getPageHeight() - text.getY(),
           text.getWidth(),
           - text.getHeight()
           );
        pdfContentByte.stroke();
        */
    }

    if (textLength == 0) {
        return;
    }

    int horizontalAlignment = Element.ALIGN_LEFT;
    switch (text.getTextAlignment()) {
    case JRAlignment.HORIZONTAL_ALIGN_LEFT: {
        horizontalAlignment = Element.ALIGN_LEFT;
        break;
    }
    case JRAlignment.HORIZONTAL_ALIGN_CENTER: {
        horizontalAlignment = Element.ALIGN_CENTER;
        break;
    }
    case JRAlignment.HORIZONTAL_ALIGN_RIGHT: {
        horizontalAlignment = Element.ALIGN_RIGHT;
        break;
    }
    case JRAlignment.HORIZONTAL_ALIGN_JUSTIFIED: {
        horizontalAlignment = Element.ALIGN_JUSTIFIED;
        break;
    }
    default: {
        horizontalAlignment = Element.ALIGN_LEFT;
    }
    }

    float verticalOffset = 0f;
    switch (text.getVerticalAlignment()) {
    case JRTextElement.VERTICAL_ALIGN_TOP: {
        verticalOffset = 0f;
        break;
    }
    case JRTextElement.VERTICAL_ALIGN_MIDDLE: {
        verticalOffset = ((float) height - text.getTextHeight()) / 2f;
        break;
    }
    case JRTextElement.VERTICAL_ALIGN_BOTTOM: {
        verticalOffset = height - text.getTextHeight();
        break;
    }
    default: {
        verticalOffset = 0f;
    }
    }

    ColumnText colText = new ColumnText(pdfContentByte);
    colText.setSimpleColumn(getPhrase(styledText, getHyperlinkInfoChunk(text)), x,
            jasperPrint.getPageHeight() - y - verticalOffset - text.getLeadingOffset(),
            //+ text.getLineSpacingFactor() * text.getFont().getSize(), 
            x + width, jasperPrint.getPageHeight() - y - height, 0, //text.getLineSpacingFactor(),// * text.getFont().getSize(),
            horizontalAlignment);

    colText.setLeading(0, text.getLineSpacingFactor());// * text.getFont().getSize());

    colText.go();

    atrans = new AffineTransform();
    atrans.rotate(-angle, x, jasperPrint.getPageHeight() - y);
    pdfContentByte.transform(atrans);
}

From source file:com.tsp.gespro.bo.DegustacionBO.java

/**
 * Representacin impresa PDF/*from  www  .jav a2s . c om*/
 */
public ByteArrayOutputStream toPdf(UsuarioBO user) throws Exception {

    SimpleDateFormat fecha = new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat hora = new SimpleDateFormat("HH:mm:ss");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    PdfITextUtil obj = new PdfITextUtil();

    //Tamao de documento (Tamao Carta)
    com.lowagie.text.Document doc = new com.lowagie.text.Document(PageSize.LETTER);

    //Definicin de Fuentes a usar
    Font letraOcho = new Font(Font.HELVETICA, 8, Font.NORMAL);
    Font letraOchoBold = new Font(Font.HELVETICA, 8, Font.BOLD);
    Font letraNueve = new Font(Font.HELVETICA, 9, Font.NORMAL);
    Font letraNueveBold = new Font(Font.HELVETICA, 9, Font.BOLD);
    Font letraNueveBoldRojo = new Font(Font.TIMES_ROMAN, 9, Font.BOLD, Color.red);
    Font letraNueveBoldAzul = new Font(Font.TIMES_ROMAN, 9, Font.BOLD, Color.blue);
    Font letraOchoVerde = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL, Color.green);
    Font letra14Bold = new Font(Font.HELVETICA, 14, Font.BOLD);

    String msgError = "";

    File fileImageLogo = null;
    try {
        if (user != null)
            fileImageLogo = new ImagenPersonalBO(this.conn)
                    .getFileImagenPersonalByEmpresa(user.getUser().getIdEmpresa());
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    try {
        //Preparamos writer de PDF
        PdfWriter writer = PdfWriter.getInstance(doc, baos);
        EventPDF eventPDF = new EventPDF(doc, user, ReportBO.DEGUSTACION_REPRESENTACION_IMPRESA, fileImageLogo);
        writer.setPageEvent(eventPDF);

        //Ajustamos margenes de pgina
        //doc.setMargins(50, 50, 120, 50);
        //doc.setMargins(20, 20, 80, 20);
        doc.setMargins(10, 10, 150, 40);

        //Iniciamos documento
        doc.open();

        //Creamos tabla principal
        PdfPTable mainTable = new PdfPTable(1);
        mainTable.setTotalWidth(550);
        mainTable.setLockedWidth(true);

        //CONTENIDO -------------

        //SALTO DE L?NEA
        obj.agregaCelda(mainTable, letraOcho, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);

        //Cabecera (Datos Generales)---------------------
        PdfPTable tAux = new PdfPTable(1);

        Cliente clienteDto = null;
        DatosUsuario datosUsuarioVendedor = null;

        try {
            if (this.degustacion.getIdCliente() > 0)
                clienteDto = new ClienteBO(this.degustacion.getIdCliente(), this.conn).getCliente();
            if (this.degustacion.getIdUsuario() > 0)
                datosUsuarioVendedor = new UsuarioBO(this.degustacion.getIdUsuario()).getDatosUsuario();
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        //Datos informativos generales
        PdfPTable tInfoGeneral = new PdfPTable(1);
        tInfoGeneral.setTotalWidth(160);
        tInfoGeneral.setLockedWidth(true);

        obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "ID Degustacin",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);
        obj.agregaCelda(tInfoGeneral, letraNueveBoldRojo, "" + this.degustacion.getIdDegustacion(),
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);

        obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "Fecha Degustacin",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);
        obj.agregaCelda(tInfoGeneral, letraNueve,
                DateManage.dateToStringEspanol(this.degustacion.getFechaApertura()),
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);
        obj.agregaCelda(tInfoGeneral, letraNueveBold, Color.lightGray, "Promotor",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);
        obj.agregaCelda(tInfoGeneral, letraNueve,
                datosUsuarioVendedor != null
                        ? (datosUsuarioVendedor.getNombre() + " " + datosUsuarioVendedor.getApellidoPat())
                        : "Sin vendedor asignado",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 1);

        //Pintamos datos informativos Generales en la esquina superior derecha
        PdfContentByte cb = writer.getDirectContent();
        tInfoGeneral.writeSelectedRows(0, -1, doc.right() - 180, doc.top() + 100, cb);

        //Datos de Cliente/Prospecto
        PdfPTable tCliente = new PdfPTable(2);
        tCliente.setTotalWidth(550);
        tCliente.setLockedWidth(true);

        obj.agregaCelda(tCliente, letraNueveBold, Color.lightGray, "Cliente",
                new boolean[] { false, false, false, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0,
                new int[0], 2);

        tAux = new PdfPTable(1);
        tAux.setTotalWidth(275);
        tAux.setLockedWidth(true);

        try {
            obj.agregaCelda(tAux, letraOcho,
                    "Nombre Comercial: " + (clienteDto != null ? clienteDto.getNombreComercial() : ""),
                    new boolean[] { false, true, false, false }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0,
                    new int[0], 1);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        obj.agregaTabla(tCliente, tAux, new boolean[] { false, false, false, false }, Element.ALIGN_LEFT,
                Element.ALIGN_TOP, 0, new int[0], 1);

        obj.agregaCelda(tCliente, letraOcho,
                "" + "DOMICILIO: \n" + (clienteDto != null ? "Calle: " + clienteDto.getCalle() : "") + " "
                        + (clienteDto != null ? clienteDto.getNumero() : "") + " "
                        + (clienteDto != null ? clienteDto.getNumeroInterior() : "")
                        + (clienteDto != null ? " Col: " + clienteDto.getColonia() : "")
                        + (clienteDto != null ? " \nDeleg./Municipio: " + clienteDto.getMunicipio() : "")
                        + (clienteDto != null ? " Estado: " + clienteDto.getEstado() : "")
                        + (clienteDto != null ? " \nC.P. " + clienteDto.getCodigoPostal() : ""),
                new boolean[] { false, true, false, true }, Element.ALIGN_LEFT, Element.ALIGN_TOP, 0,
                new int[0], 1);

        obj.agregaTabla(mainTable, tCliente, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER,
                Element.ALIGN_TOP, 0, new int[0], 1);

        //FIN Cabecera (Datos Generales)-----------------

        //DOBLE SALTO DE L?NEA
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);

        int colsDetalles = 6;
        PdfPTable tDetalles = new PdfPTable(colsDetalles);//6);
        tDetalles.setTotalWidth(550);
        tDetalles.setWidths(new int[] { 200, 70, 70, 70, 70, 70 });
        tDetalles.setLockedWidth(true);

        /*CABECERA*/
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Producto Degustado",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Hr Inicio",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Hr Termino",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Inventario Inicial",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Inventario Final",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);
        obj.agregaCelda(tDetalles, letraNueveBold, Color.lightGray, "Piezas Degustadas",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 1);

        /*FIN DE CABECERA*/
        Degustacion[] degustacionDtos = new Degustacion[0];
        try {
            degustacionDtos = this.findDegustaciones(this.degustacion.getIdDegustacion(),
                    this.degustacion.getIdEmpresa(), -1, -1, "");
        } catch (Exception e) {
        }

        //Listado de Productos
        for (Degustacion item : degustacionDtos) {

            if (item != null) {

                Concepto conceptoDto = null;

                try {
                    ConceptoBO conceptoBO = new ConceptoBO(item.getIdConcepto(), this.conn);
                    conceptoDto = conceptoBO.getConcepto();
                } catch (Exception e) {
                }

                //Producto
                obj.agregaCelda(tDetalles, letraOcho, null, conceptoDto.getNombreDesencriptado(),
                        new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP,
                        15, new int[] { 5, 5, 5, 5 }, 1);

                //Inicio
                obj.agregaCelda(tDetalles, letraOcho, null, hora.format(item.getFechaApertura()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED, Element.ALIGN_TOP,
                        15, new int[] { 5, 5, 5, 5 }, 1);

                //Termino
                obj.agregaCelda(tDetalles, letraOcho, null, hora.format(item.getFechaCierre()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15,
                        new int[] { 5, 5, 5, 5 }, 1);

                //Inv inicial 
                obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidad()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15,
                        new int[] { 5, 5, 5, 5 }, 1);

                //inv final 
                obj.agregaCelda(tDetalles, letraOcho, null, "" + (item.getCantidadCierre()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15,
                        new int[] { 5, 5, 5, 5 }, 1);

                //Piezas 
                obj.agregaCelda(tDetalles, letraOcho, null,
                        "" + (item.getCantidad() - item.getCantidadCierre()),
                        new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP, 15,
                        new int[] { 5, 5, 5, 5 }, 1);

            }
        }

        obj.agregaTabla(mainTable, tDetalles, new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_TOP, 0, new int[0], 1);

        //DOBLE SALTO DE L?NEA
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);

        /*prods Vendidos durante degustacion*/

        PdfPTable tVenta = new PdfPTable(4);
        tVenta.setTotalWidth(550);
        tVenta.setWidths(new int[] { 70, 140, 170, 120 });
        tVenta.setLockedWidth(true);

        obj.agregaCelda(tVenta, letraNueveBold, Color.lightGray, "Producto Vendido durante Degutacin",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 4);

        Productosvendidos[] pedidoProductoDto = new Productosvendidos[0];

        String filtroBusqueda = " ID_PEDIDO IN ( SELECT ID_PEDIDO FROM sgfens_pedido WHERE ID_EMPRESA = '"
                + this.degustacion.getIdEmpresa() + "' AND ID_TIPO_PEDIDO = 2 AND ID_USUARIO_VENDEDOR = "
                + this.degustacion.getIdUsuario() + " AND " + " ID_ESTATUS_PEDIDO<>2 AND FECHA_PEDIDO BETWEEN '"
                + this.degustacion.getFechaApertura() + "'  AND '" + this.degustacion.getFechaCierre() + "') ";

        try {
            pedidoProductoDto = new ProductosvendidosDaoImpl().findByDynamicWhere(filtroBusqueda, null);
        } catch (Exception e) {
        }

        if (pedidoProductoDto.length > 0) {

            obj.agregaCelda(tVenta, letraOchoBold, null, "Cdigo", new boolean[] { true, true, true, true },
                    Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1);
            obj.agregaCelda(tVenta, letraOchoBold, null, "Nombre", new boolean[] { true, true, true, true },
                    Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15, new int[] { 5, 5, 5, 5 }, 1);
            obj.agregaCelda(tVenta, letraOchoBold, null, "Descripcin",
                    new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                    new int[] { 5, 5, 5, 5 }, 1);
            obj.agregaCelda(tVenta, letraOchoBold, null, "Unidades Vendidas",
                    new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                    new int[] { 5, 5, 5, 5 }, 1);

            for (Productosvendidos pedidoProd : pedidoProductoDto) {

                if (pedidoProd != null) {

                    Concepto conceptoDto = null;
                    try {
                        ConceptoBO conceptoBO = new ConceptoBO(pedidoProd.getIdConcepto(), this.conn);
                        conceptoDto = conceptoBO.getConcepto();
                    } catch (Exception e) {
                    }

                    //Cdigo
                    obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getIdentificacion(),
                            new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED,
                            Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1);

                    //Nombre
                    obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getNombreDesencriptado(),
                            new boolean[] { true, true, true, true }, Element.ALIGN_JUSTIFIED,
                            Element.ALIGN_TOP, 15, new int[] { 5, 5, 5, 5 }, 1);

                    //Descripcin
                    obj.agregaCelda(tVenta, letraOcho, null, conceptoDto.getDescripcion(),
                            new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP,
                            15, new int[] { 5, 5, 5, 5 }, 1);

                    //Unidades Vendidas 
                    obj.agregaCelda(tVenta, letraOcho, null, "" + (pedidoProd.getCantidad()),
                            new boolean[] { true, true, true, true }, Element.ALIGN_RIGHT, Element.ALIGN_TOP,
                            15, new int[] { 5, 5, 5, 5 }, 1);

                }

            }
        } else {

            obj.agregaCelda(tVenta, letraOcho, null, "No se registrarn datos.",
                    new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                    new int[] { 5, 5, 5, 5 }, 4);

        }

        obj.agregaTabla(mainTable, tVenta, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER,
                Element.ALIGN_TOP, 0, new int[0], 1);

        //DOBLE SALTO DE L?NEA
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);
        obj.agregaCelda(mainTable, letraOcho, null, " ", new boolean[] { false, false, false, false },
                Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 0, new int[0], 1);

        /*Comentarios Adicionales*/
        PdfPTable tComenst = new PdfPTable(1);
        tComenst.setTotalWidth(550);
        tComenst.setWidths(new int[] { 550 });
        tComenst.setLockedWidth(true);

        obj.agregaCelda(tComenst, letraNueveBold, Color.lightGray, "Comentarios",
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 2);

        obj.agregaCelda(tComenst, letraOcho, null, this.degustacion.getComentariosCierre(),
                new boolean[] { true, true, true, true }, Element.ALIGN_CENTER, Element.ALIGN_MIDDLE, 15,
                new int[] { 5, 5, 5, 5 }, 2);

        obj.agregaTabla(mainTable, tComenst, new boolean[] { true, true, true, true }, Element.ALIGN_CENTER,
                Element.ALIGN_TOP, 0, new int[0], 1);

        //FIN DE CONTENIDO --------

        //Aadimos tabla principal construida al documento
        doc.add(mainTable);
        mainTable.flushContent();

    } catch (Exception ex) {
        msgError = "No se ha podido generar la representacin impresa de la Degustacion en formato PDF:<br/>"
                + ex.toString();
    } finally {
        if (doc.isOpen())
            doc.close();
    }

    if (!msgError.equals("")) {
        throw new Exception(msgError);
    }

    return baos;

}

From source file:corner.orm.tapestry.jasper.exporter.CornerPdfExporter.java

License:Apache License

/**
 * ?.????.//from   w w w .ja  va 2s  . c  o  m
 * <p>:ColumnText?,
 * ?NO_MORE_COLUMN???,TextField??.
 * TextField?.
 * @see net.sf.jasperreports.engine.export.JRPdfExporter#exportText(net.sf.jasperreports.engine.JRPrintText)
 */
@Override
protected void exportText(JRPrintText text) throws DocumentException {

    JRStyledText styledText = getStyledText(text, false);

    if (styledText == null) {
        return;
    }

    int textLength = styledText.length();

    int x = text.getX() + getOffsetX();
    int y = text.getY() + getOffsetY();
    int width = text.getWidth();
    int height = text.getHeight();
    int topPadding = text.getTopPadding();
    int leftPadding = text.getLeftPadding();
    int bottomPadding = text.getBottomPadding();
    int rightPadding = text.getRightPadding();

    int xFillCorrection = 0;
    int yFillCorrection = 0;

    double angle = 0;

    switch (text.getRotation()) {
    case JRTextElement.ROTATION_LEFT: {
        y = text.getY() + getOffsetY() + text.getHeight();
        xFillCorrection = 1;
        width = text.getHeight();
        height = text.getWidth();
        int tmpPadding = topPadding;
        topPadding = leftPadding;
        leftPadding = bottomPadding;
        bottomPadding = rightPadding;
        rightPadding = tmpPadding;
        angle = Math.PI / 2;
        break;
    }
    case JRTextElement.ROTATION_RIGHT: {
        x = text.getX() + getOffsetX() + text.getWidth();
        yFillCorrection = -1;
        width = text.getHeight();
        height = text.getWidth();
        int tmpPadding = topPadding;
        topPadding = rightPadding;
        rightPadding = bottomPadding;
        bottomPadding = leftPadding;
        leftPadding = tmpPadding;
        angle = -Math.PI / 2;
        break;
    }
    case JRTextElement.ROTATION_UPSIDE_DOWN: {
        x = text.getX() + getOffsetX() + text.getWidth();
        y = text.getY() + getOffsetY() + text.getHeight();
        int tmpPadding = topPadding;
        topPadding = bottomPadding;
        bottomPadding = tmpPadding;
        tmpPadding = leftPadding;
        leftPadding = rightPadding;
        rightPadding = tmpPadding;
        angle = Math.PI;
        break;
    }
    case JRTextElement.ROTATION_NONE:
    default: {
    }
    }

    AffineTransform atrans = new AffineTransform();
    atrans.rotate(angle, x, jasperPrint.getPageHeight() - y);
    pdfContentByte.transform(atrans);

    if (text.getMode() == JRElement.MODE_OPAQUE) {
        Color backcolor = text.getBackcolor();
        pdfContentByte.setRGBColorStroke(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue());
        pdfContentByte.setRGBColorFill(backcolor.getRed(), backcolor.getGreen(), backcolor.getBlue());
        pdfContentByte.setLineWidth(1f);
        pdfContentByte.setLineDash(0f);
        pdfContentByte.rectangle(x + xFillCorrection, jasperPrint.getPageHeight() - y + yFillCorrection,
                width - 1, -height + 1);
        pdfContentByte.fillStroke();
    } else {
        /*
         * pdfContentByte.setRGBColorStroke( text.getForecolor().getRed(),
         * text.getForecolor().getGreen(), text.getForecolor().getBlue() );
         * pdfContentByte.setLineWidth(0.1f);
         * pdfContentByte.setLineDash(0f); pdfContentByte.rectangle(
         * text.getX() + offsetX, jasperPrint.getPageHeight() - text.getY() -
         * offsetY, text.getWidth(), - text.getHeight() );
         * pdfContentByte.stroke();
         */
    }

    if (textLength > 0) {
        int horizontalAlignment = Element.ALIGN_LEFT;
        switch (text.getHorizontalAlignment()) {
        case JRAlignment.HORIZONTAL_ALIGN_LEFT: {
            if (text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR) {
                horizontalAlignment = Element.ALIGN_LEFT;
            } else {
                horizontalAlignment = Element.ALIGN_RIGHT;
            }
            break;
        }
        case JRAlignment.HORIZONTAL_ALIGN_CENTER: {
            horizontalAlignment = Element.ALIGN_CENTER;
            break;
        }
        case JRAlignment.HORIZONTAL_ALIGN_RIGHT: {
            if (text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR) {
                horizontalAlignment = Element.ALIGN_RIGHT;
            } else {
                horizontalAlignment = Element.ALIGN_LEFT;
            }
            break;
        }
        case JRAlignment.HORIZONTAL_ALIGN_JUSTIFIED: {
            horizontalAlignment = Element.ALIGN_JUSTIFIED;
            break;
        }
        default: {
            horizontalAlignment = Element.ALIGN_LEFT;
        }
        }

        float verticalOffset = 0f;
        switch (text.getVerticalAlignment()) {
        case JRAlignment.VERTICAL_ALIGN_TOP: {
            verticalOffset = 0f;
            break;
        }
        case JRAlignment.VERTICAL_ALIGN_MIDDLE: {
            verticalOffset = (height - topPadding - bottomPadding - text.getTextHeight()) / 2f;
            break;
        }
        case JRAlignment.VERTICAL_ALIGN_BOTTOM: {
            verticalOffset = height - topPadding - bottomPadding - text.getTextHeight();
            break;
        }
        default: {
            verticalOffset = 0f;
        }
        }

        float llx = x + leftPadding;
        float lly = jasperPrint.getPageHeight() - y - topPadding - verticalOffset - text.getLeadingOffset();
        float urx = x + width - rightPadding;
        float ury = jasperPrint.getPageHeight() - y - height + bottomPadding;

        //?,???
        if (this.jasperMoveXY != null) {
            llx = x + leftPadding + jasperMoveXY.getX();
            lly = jasperPrint.getPageHeight() - y - topPadding - verticalOffset - text.getLeadingOffset()
                    - jasperMoveXY.getY();
            urx = x + width - rightPadding + jasperMoveXY.getX();
            ury = jasperPrint.getPageHeight() - y - height + bottomPadding - jasperMoveXY.getY();
        }

        boolean isOver = false;
        int status = ColumnText.START_COLUMN;
        Phrase phrase = getPhrase(styledText, text);

        ColumnText colText = new ColumnText(pdfContentByte);
        colText.setSimpleColumn(phrase, llx, lly, urx, ury, 0, // text.getLineSpacingFactor(),//
                // *
                // text.getFont().getSize(),
                horizontalAlignment);

        colText.setLeading(0, text.getLineSpacingFactor());// *
        // text.getFont().getSize());
        colText.setRunDirection(
                text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR ? PdfWriter.RUN_DIRECTION_LTR
                        : PdfWriter.RUN_DIRECTION_RTL);

        float yLine = colText.getYLine();

        // ColumnText
        while (colText.hasMoreText(status)) {
            status = colText.go(true);
            colText.setYLine(yLine);

            // ??,true
            if (status == ColumnText.NO_MORE_COLUMN) {
                isOver = true;
                break;
            }
        }

        // ,ColumnText
        if (!isOver) {
            colText.setText(phrase);
            status = ColumnText.START_COLUMN;

            while (colText.hasMoreText(status)) {
                status = colText.go();
                colText.setYLine(yLine);
            }

        } else {
            // TextField,??
            String key = text.getKey();// PdfTextid
            if (alreadyExistFields.contains(key)) { // ?
                key = createUniqueName();
            }
            alreadyExistFields.add(key);
            TextField tf = new TextField(pdfContentByte.getPdfWriter(), new Rectangle(llx, lly, urx, ury), key);
            tf.setAlignment(horizontalAlignment);
            tf.setText(text.getText());
            tf.setFont(PdfUtils.createSongLightBaseFont());

            // styledText ??,?
            if (!text.isStyledText()) {
                tf.setOptions(TextField.MULTILINE);
            }

            try {
                pdfContentByte.getPdfWriter().addAnnotation(tf.getTextField());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    atrans = new AffineTransform();
    atrans.rotate(-angle, x, jasperPrint.getPageHeight() - y);
    pdfContentByte.transform(atrans);

    /*   */
    exportBox(text, text);
}

From source file:de.xirp.report.ReportGenerator.java

License:Open Source License

/**
 * Adds a//from w  w  w  . j ava2 s .  c o  m
 * {@link de.xirp.report.data.ContentPartText text}
 * item to the PDF {@link com.lowagie.text.Document}.
 * 
 * @param item
 *            The item to add.
 * @throws DocumentException
 *             if something went wrong adding the page.
 * @see de.xirp.report.data.ContentPartText
 * @see com.lowagie.text.Document
 */
private static void addText(ContentPartText item) throws DocumentException {
    for (ContentPartTextParagraph cptp : item.getParagraphs()) {
        if (!cptp.getHeader().equals("")) { //$NON-NLS-1$
            para = getParagraph(cptp.getHeader(), PARA_HEADER, Element.ALIGN_LEFT);
            document.add(para);
        }
        para = getParagraph(cptp.getText(), TEXT, Element.ALIGN_JUSTIFIED);
        document.add(para);
        addSkip();
    }
}

From source file:fr.opensagres.odfdom.converter.pdf.internal.StyleEngineForIText.java

License:Open Source License

@Override
public void visit(StyleParagraphPropertiesElement ele) {

    StyleParagraphProperties paragraphProperties = currentStyle.getParagraphProperties();
    if (paragraphProperties == null) {
        paragraphProperties = new StyleParagraphProperties();
        currentStyle.setParagraphProperties(paragraphProperties);
    }//from   w w  w  . j av  a2s . c  om

    // background-color
    String backgroundColor = ele.getFoBackgroundColorAttribute();
    if (StringUtils.isNotEmpty(backgroundColor)) {
        paragraphProperties.setBackgroundColor(ColorRegistry.getInstance().getColor(backgroundColor));
    }

    // border
    String border = ele.getFoBorderAttribute();
    if (StringUtils.isNotEmpty(border)) {
        paragraphProperties.setBorder(new StyleBorder(border, BorderType.ALL));
    }
    // border-bottom
    String borderBottom = ele.getFoBorderBottomAttribute();
    if (StringUtils.isNotEmpty(borderBottom)) {
        paragraphProperties.setBorderBottom(new StyleBorder(borderBottom, BorderType.BOTTOM));
    }

    // border-left
    String borderLeft = ele.getFoBorderLeftAttribute();
    if (StringUtils.isNotEmpty(borderLeft)) {
        paragraphProperties.setBorderLeft(new StyleBorder(borderLeft, BorderType.LEFT));
    }

    // border-bottom
    String borderRight = ele.getFoBorderRightAttribute();
    if (StringUtils.isNotEmpty(borderRight)) {
        paragraphProperties.setBorderRight(new StyleBorder(borderRight, BorderType.RIGHT));
    }

    // border-top
    String borderTop = ele.getFoBorderTopAttribute();
    if (StringUtils.isNotEmpty(borderTop)) {
        paragraphProperties.setBorderTop(new StyleBorder(borderTop, BorderType.TOP));
    }

    // join-border
    Boolean joinBorder = ele.getStyleJoinBorderAttribute();
    if (joinBorder != null) {
        paragraphProperties.setJoinBorder(joinBorder);
    }

    // line-height
    String lineHeight = ele.getFoLineHeightAttribute();
    if (StringUtils.isNotEmpty(lineHeight)) {
        paragraphProperties.setLineHeight(new StyleLineHeight(ODFUtils.getDimensionAsPoint(lineHeight),
                ODFUtils.hasPercentUnit(lineHeight)));
    }

    // margin
    String margin = ele.getFoMarginAttribute();
    if (StringUtils.isNotEmpty(margin)) {
        paragraphProperties.setMargin(ODFUtils.getDimensionAsPoint(margin));
    }

    // margin-bottom
    String marginBottom = ele.getFoMarginBottomAttribute();
    if (StringUtils.isNotEmpty(marginBottom)) {
        paragraphProperties.setMarginBottom(ODFUtils.getDimensionAsPoint(marginBottom));
    }

    // margin-left
    String marginLeft = ele.getFoMarginLeftAttribute();
    if (StringUtils.isNotEmpty(marginLeft)) {
        paragraphProperties.setMarginLeft(ODFUtils.getDimensionAsPoint(marginLeft));
    }

    // margin-right
    String marginRight = ele.getFoMarginRightAttribute();
    if (StringUtils.isNotEmpty(marginRight)) {
        paragraphProperties.setMarginRight(ODFUtils.getDimensionAsPoint(marginRight));
    }

    // margin-top
    String marginTop = ele.getFoMarginTopAttribute();
    if (StringUtils.isNotEmpty(marginTop)) {
        paragraphProperties.setMarginTop(ODFUtils.getDimensionAsPoint(marginTop));
    }

    // padding
    String padding = ele.getFoPaddingAttribute();
    if (StringUtils.isNotEmpty(padding)) {
        paragraphProperties.setPadding(ODFUtils.getDimensionAsPoint(padding));
    }

    // padding-bottom
    String paddingBottom = ele.getFoPaddingBottomAttribute();
    if (StringUtils.isNotEmpty(paddingBottom)) {
        paragraphProperties.setPaddingBottom(ODFUtils.getDimensionAsPoint(paddingBottom));
    }

    // padding-left
    String paddingLeft = ele.getFoPaddingLeftAttribute();
    if (StringUtils.isNotEmpty(paddingLeft)) {
        paragraphProperties.setPaddingLeft(ODFUtils.getDimensionAsPoint(paddingLeft));
    }

    // padding-right
    String paddingRight = ele.getFoPaddingRightAttribute();
    if (StringUtils.isNotEmpty(paddingRight)) {
        paragraphProperties.setPaddingRight(ODFUtils.getDimensionAsPoint(paddingRight));
    }

    // padding-top
    String paddingTop = ele.getFoPaddingTopAttribute();
    if (StringUtils.isNotEmpty(paddingTop)) {
        paragraphProperties.setPaddingTop(ODFUtils.getDimensionAsPoint(paddingTop));
    }

    // text-align
    String textAlign = ele.getFoTextAlignAttribute();
    if (StringUtils.isNotEmpty(textAlign)) {
        int alignment = Element.ALIGN_UNDEFINED;
        if (FoTextAlignAttribute.Value.START.toString().equals(textAlign)) {
            alignment = Element.ALIGN_LEFT;
        } else if (FoTextAlignAttribute.Value.END.toString().equals(textAlign)) {
            alignment = Element.ALIGN_RIGHT;
        } else if (FoTextAlignAttribute.Value.LEFT.toString().equals(textAlign)) {
            alignment = Element.ALIGN_LEFT;
        } else if (FoTextAlignAttribute.Value.RIGHT.toString().equals(textAlign)) {
            alignment = Element.ALIGN_RIGHT;
        } else if (FoTextAlignAttribute.Value.CENTER.toString().equals(textAlign)) {
            alignment = Element.ALIGN_CENTER;
        } else if (FoTextAlignAttribute.Value.JUSTIFY.toString().equals(textAlign)) {
            alignment = Element.ALIGN_JUSTIFIED;
        }
        paragraphProperties.setAlignment(alignment);
    }

    // auto-text-indent
    Boolean autoTextIndent = ele.getStyleAutoTextIndentAttribute();
    if (autoTextIndent != null) {
        paragraphProperties.setAutoTextIndent(autoTextIndent);
    }

    // text-indent
    String textIndent = ele.getFoTextIndentAttribute();
    if (StringUtils.isNotEmpty(textIndent)) {
        paragraphProperties.setTextIndent(ODFUtils.getDimensionAsPoint(textIndent));
    }

    // keep-together
    String keepTogether = ele.getFoKeepTogetherAttribute();
    if (StringUtils.isNotEmpty(keepTogether)) {
        if (FoKeepTogetherAttribute.Value.ALWAYS.toString().equals(keepTogether)) {
            paragraphProperties.setKeepTogether(Boolean.TRUE);
        } else {
            paragraphProperties.setKeepTogether(Boolean.FALSE);
        }
    }

    // fo:break-before
    String breakBefore = ele.getFoBreakBeforeAttribute();
    if (StringUtils.isNotEmpty(breakBefore)) {
        if (FoBreakBeforeAttribute.Value.PAGE.toString().equals(breakBefore)) {
            paragraphProperties.setBreakBefore(StyleBreak.createWithPageBreak());
        } else if (FoBreakBeforeAttribute.Value.COLUMN.toString().equals(breakBefore)) {
            paragraphProperties.setBreakBefore(StyleBreak.createWithColumnBreak());
        } else {
            paragraphProperties.setBreakBefore(StyleBreak.createWithNoBreak());
        }
    }

    super.visit(ele);
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java

License:Open Source License

@Override
protected IITextContainer startVisitParagraph(CTP paragraph, ListItemContext itemContext,
        IITextContainer pdfParentContainer) throws Exception {
    // create PDF paragraph
    StylableParagraph pdfParagraph = pdfDocument.createParagraph(pdfParentContainer);

    CTTbl parentTable = super.getParentTable();
    // indentation left
    Float indentationLeft = stylesDocument.getIndentationLeft(paragraph, parentTable);
    if (indentationLeft != null) {
        pdfParagraph.setIndentationLeft(indentationLeft);
    }//www  . j a  v  a 2 s.  c  o  m
    // indentation right
    Float indentationRight = stylesDocument.getIndentationRight(paragraph, parentTable);
    if (indentationRight != null) {
        pdfParagraph.setIndentationRight(indentationRight);
    }
    // indentation first line
    Float indentationFirstLine = stylesDocument.getIndentationFirstLine(paragraph, parentTable);
    if (indentationFirstLine != null) {
        pdfParagraph.setFirstLineIndent(indentationFirstLine);
    }
    // indentation hanging (remove first line)
    Float indentationHanging = stylesDocument.getIndentationHanging(paragraph, parentTable);
    if (indentationHanging != null) {
        pdfParagraph.setFirstLineIndent(-indentationHanging);
    }

    // // spacing before
    Float spacingBefore = stylesDocument.getSpacingBefore(paragraph, parentTable);
    if (spacingBefore != null) {
        pdfParagraph.setSpacingBefore(spacingBefore);
    }

    // spacing after
    // one more pargraph, spacing after should be applied.
    Float spacingAfter = stylesDocument.getSpacingAfter(paragraph, parentTable);
    if (spacingAfter != null) {
        pdfParagraph.setSpacingAfter(spacingAfter);
    }

    ParagraphLineSpacing lineSpacing = stylesDocument.getParagraphSpacing(paragraph, parentTable);
    if (lineSpacing != null) {
        if (lineSpacing.getLeading() != null && lineSpacing.getMultipleLeading() != null) {
            pdfParagraph.setLeading(lineSpacing.getLeading(), lineSpacing.getMultipleLeading());
        } else {
            if (lineSpacing.getLeading() != null) {
                pdfParagraph.setLeading(lineSpacing.getLeading());
            }
            if (lineSpacing.getMultipleLeading() != null) {
                pdfParagraph.setMultipliedLeading(lineSpacing.getMultipleLeading());
            }
        }

    }

    // text-align
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(paragraph, parentTable);
    if (alignment != null) {
        switch (alignment) {
        case LEFT:
            pdfParagraph.setAlignment(Element.ALIGN_LEFT);
            break;
        case RIGHT:
            pdfParagraph.setAlignment(Element.ALIGN_RIGHT);
            break;
        case CENTER:
            pdfParagraph.setAlignment(Element.ALIGN_CENTER);
            break;
        case BOTH:
            pdfParagraph.setAlignment(Element.ALIGN_JUSTIFIED);
            break;
        default:
            break;
        }
    }
    return pdfParagraph;
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java

License:Open Source License

private StylableTable createPDFTable(CTTbl table, float[] colWidths, IITextContainer pdfParentContainer)
        throws DocumentException {
    // 2) Compute tableWith
    TableWidth tableWidth = stylesDocument.getTableWidth(table);
    StylableTable pdfPTable = pdfDocument.createTable(pdfParentContainer, colWidths.length);
    pdfPTable.setTotalWidth(colWidths);//from  w  w  w .  ja  va 2 s.  c o  m
    if (tableWidth != null && tableWidth.width > 0) {
        if (tableWidth.percentUnit) {
            pdfPTable.setWidthPercentage(tableWidth.width);
        } else {
            pdfPTable.setTotalWidth(tableWidth.width);
        }
    }
    pdfPTable.setLockedWidth(true);

    // Table alignment
    ParagraphAlignment alignment = stylesDocument.getTableAlignment(table);
    if (alignment != null) {
        switch (alignment) {
        case LEFT:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_LEFT);
            break;
        case RIGHT:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_RIGHT);
            break;
        case CENTER:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_CENTER);
            break;
        case BOTH:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
            break;
        default:
            break;
        }
    }

    // Table indentation
    Float indentation = stylesDocument.getTableIndentation(table);
    if (indentation != null) {
        pdfPTable.setPaddingLeft(indentation);
    }
    return pdfPTable;
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java

License:Open Source License

@Override
protected IITextContainer startVisitParagraph(XWPFParagraph docxParagraph, ListItemContext itemContext,
        IITextContainer pdfParentContainer) throws Exception {
    this.currentRunX = null;

    // create PDF paragraph
    StylableParagraph pdfParagraph = pdfDocument.createParagraph(pdfParentContainer);

    // indentation left
    Float indentationLeft = stylesDocument.getIndentationLeft(docxParagraph);
    if (indentationLeft != null) {
        pdfParagraph.setIndentationLeft(indentationLeft);
    }/*  w w  w.ja  va  2 s  .  co m*/
    // indentation right
    Float indentationRight = stylesDocument.getIndentationRight(docxParagraph);
    if (indentationRight != null) {
        pdfParagraph.setIndentationRight(indentationRight);
    }
    // indentation first line
    Float indentationFirstLine = stylesDocument.getIndentationFirstLine(docxParagraph);
    if (indentationFirstLine != null) {
        pdfParagraph.setFirstLineIndent(indentationFirstLine);
    }
    // indentation hanging (remove first line)
    Float indentationHanging = stylesDocument.getIndentationHanging(docxParagraph);
    if (indentationHanging != null) {
        pdfParagraph.setFirstLineIndent(-indentationHanging);
    }

    // // spacing before
    Float spacingBefore = stylesDocument.getSpacingBefore(docxParagraph);
    if (spacingBefore != null) {
        pdfParagraph.setSpacingBefore(spacingBefore);
    }

    // spacing after
    Float spacingAfter = stylesDocument.getSpacingAfter(docxParagraph);
    if (spacingAfter != null) {
        pdfParagraph.setSpacingAfter(spacingAfter);
    }

    ParagraphLineSpacing lineSpacing = stylesDocument.getParagraphSpacing(docxParagraph);
    if (lineSpacing != null) {
        if (lineSpacing.getLeading() != null && lineSpacing.getMultipleLeading() != null) {
            pdfParagraph.setLeading(lineSpacing.getLeading(), lineSpacing.getMultipleLeading());
        } else {
            if (lineSpacing.getLeading() != null) {
                pdfParagraph.setLeading(lineSpacing.getLeading());
            }
            if (lineSpacing.getMultipleLeading() != null) {
                pdfParagraph.setMultipliedLeading(lineSpacing.getMultipleLeading());
            }
        }

    }

    // text-align
    ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(docxParagraph);
    if (alignment != null) {
        switch (alignment) {
        case LEFT:
            pdfParagraph.setAlignment(Element.ALIGN_LEFT);
            break;
        case RIGHT:
            pdfParagraph.setAlignment(Element.ALIGN_RIGHT);
            break;
        case CENTER:
            pdfParagraph.setAlignment(Element.ALIGN_CENTER);
            break;
        case BOTH:
            pdfParagraph.setAlignment(Element.ALIGN_JUSTIFIED);
            break;
        default:
            break;
        }
    }

    // background-color
    Color backgroundColor = stylesDocument.getBackgroundColor(docxParagraph);
    if (backgroundColor != null) {
        pdfParagraph.setBackgroundColor(Converter.toAwtColor(backgroundColor));
    }

    // border
    CTBorder borderTop = stylesDocument.getBorderTop(docxParagraph);
    pdfParagraph.setBorder(borderTop, Rectangle.TOP);

    CTBorder borderBottom = stylesDocument.getBorderBottom(docxParagraph);
    pdfParagraph.setBorder(borderBottom, Rectangle.BOTTOM);

    CTBorder borderLeft = stylesDocument.getBorderLeft(docxParagraph);
    pdfParagraph.setBorder(borderLeft, Rectangle.LEFT);

    CTBorder borderRight = stylesDocument.getBorderRight(docxParagraph);
    pdfParagraph.setBorder(borderRight, Rectangle.RIGHT);

    if (itemContext != null) {
        CTLvl lvl = itemContext.getLvl();
        CTPPr lvlPPr = lvl.getPPr();
        if (lvlPPr != null) {
            if (ParagraphIndentationLeftValueProvider.INSTANCE
                    .getValue(docxParagraph.getCTP().getPPr()) == null) {

                // search the indentation from the level properties only if
                // paragraph has not override it
                // see
                // https://code.google.com/p/xdocreport/issues/detail?id=239
                Float indLeft = ParagraphIndentationLeftValueProvider.INSTANCE.getValue(lvlPPr);
                if (indLeft != null) {
                    pdfParagraph.setIndentationLeft(indLeft);
                }
            }
            if (ParagraphIndentationHangingValueProvider.INSTANCE
                    .getValue(docxParagraph.getCTP().getPPr()) == null) {
                // search the hanging from the level properties only if
                // paragraph has not override it
                // see
                // https://code.google.com/p/xdocreport/issues/detail?id=239
                Float hanging = stylesDocument.getIndentationHanging(lvlPPr);
                if (hanging != null) {
                    pdfParagraph.setFirstLineIndent(-hanging);
                }
            }
        }
        CTRPr lvlRPr = lvl.getRPr();
        if (lvlRPr != null) {
            // Font family
            String listItemFontFamily = stylesDocument.getFontFamilyAscii(lvlRPr);

            // Get font size
            Float listItemFontSize = stylesDocument.getFontSize(lvlRPr);

            // Get font style
            int listItemFontStyle = Font.NORMAL;
            Boolean bold = stylesDocument.getFontStyleBold(lvlRPr);
            if (bold != null && bold) {
                listItemFontStyle |= Font.BOLD;
            }
            Boolean italic = stylesDocument.getFontStyleItalic(lvlRPr);
            if (italic != null && italic) {
                listItemFontStyle |= Font.ITALIC;
            }
            Boolean strike = stylesDocument.getFontStyleStrike(lvlRPr);
            if (strike != null && strike) {
                listItemFontStyle |= Font.STRIKETHRU;
            }

            // Font color
            Color listItemFontColor = stylesDocument.getFontColor(lvlRPr);

            pdfParagraph.setListItemFontFamily(listItemFontFamily);
            pdfParagraph.setListItemFontSize(listItemFontSize);
            pdfParagraph.setListItemFontStyle(listItemFontStyle);
            pdfParagraph.setListItemFontColor(Converter.toAwtColor(listItemFontColor));

        }
        pdfParagraph.setListItemText(itemContext.getText());
    }
    return pdfParagraph;
}

From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java

License:Open Source License

private StylableTable createPDFTable(XWPFTable table, float[] colWidths, IITextContainer pdfParentContainer)
        throws DocumentException {
    // 2) Compute tableWith
    TableWidth tableWidth = stylesDocument.getTableWidth(table);
    StylableTable pdfPTable = pdfDocument.createTable(pdfParentContainer, colWidths.length);
    pdfPTable.setTotalWidth(colWidths);/*from   ww w  . j  a v  a  2  s . c  o m*/
    if (tableWidth != null && tableWidth.width > 0) {
        if (tableWidth.percentUnit) {
            pdfPTable.setWidthPercentage(tableWidth.width);
        } else {
            pdfPTable.setTotalWidth(tableWidth.width);
        }
    }
    pdfPTable.setLockedWidth(true);

    // Table alignment
    ParagraphAlignment alignment = stylesDocument.getTableAlignment(table);
    if (alignment != null) {
        switch (alignment) {
        case LEFT:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_LEFT);
            break;
        case RIGHT:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_RIGHT);
            break;
        case CENTER:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_CENTER);
            break;
        case BOTH:
            pdfPTable.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
            break;
        default:
            break;
        }
    }

    // Table indentation
    Float indentation = stylesDocument.getTableIndentation(table);
    if (indentation != null) {
        pdfPTable.setPaddingLeft(indentation);
    }
    return pdfPTable;
}

From source file:ispyb.client.mx.results.ExportAutoProcAction.java

License:Open Source License

private void setAutoProcInfo(Document document) throws Exception {
    // header//from   w  w  w.  j  a va  2 s  .  co m
    Table headerTable = new Table(1);
    headerTable.getDefaultCell().setBorderWidth(0);
    headerTable.setBorderWidth(0);
    headerTable.setCellsFitPage(true);
    headerTable.setAlignment(Element.ALIGN_LEFT);
    headerTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    headerTable.getDefaultCell().setBackgroundColor(PdfRtfExporter.LIGHT_YELLOW_COLOR);
    headerTable.getDefaultCell().setLeading(3);
    headerTable.setWidth(100); // percentage
    headerTable
            .addCell(new Paragraph("Crystal data and data-collection statistics", PdfRtfExporter.FONT_DOC_11));
    headerTable.addCell(new Paragraph("Values in parentheses are for the highest resolution shell.",
            PdfRtfExporter.FONT_DOC_11));
    document.add(headerTable);
    document.add(new Paragraph(" ", PdfRtfExporter.VERY_SMALL_FONT));
    // auto proc table
    Table autoProcTable = new Table(2);
    autoProcTable.getDefaultCell().setBorderWidth(0);
    autoProcTable.setBorderWidth(0);
    autoProcTable.setCellsFitPage(true);
    autoProcTable.setAlignment(Element.ALIGN_LEFT);
    autoProcTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    // autoProcTable.getDefaultCell().setLeading(3);
    autoProcTable.setPadding(2);
    autoProcTable.setWidth(100); // percentage
    // data
    String spaceGroup = autoProc == null ? "" : autoProc.getSpaceGroup();
    String unitCell_a = autoProc == null ? "" : autoProc.getRefinedCellA().toString();
    String unitCell_b = autoProc == null ? "" : autoProc.getRefinedCellB().toString();
    String unitCell_c = autoProc == null ? "" : autoProc.getRefinedCellC().toString();
    String unitCell_alpha = autoProc == null ? "" : autoProc.getRefinedCellAlpha().toString();
    String unitCell_beta = autoProc == null ? "" : autoProc.getRefinedCellBeta().toString();
    String unitCell_gamma = autoProc == null ? "" : autoProc.getRefinedCellGamma().toString();
    String resolutionRange = "";
    String nTotalObservations = "";
    String nTotalUniqueReflections = "";
    String completeness = "";
    String multiplicity = "";
    String isigma = "";
    String rmerge = "";
    if (autoProcStatisticsOverall != null) {
        resolutionRange = autoProcStatisticsOverall.getResolutionLimitLow() + " - "
                + autoProcStatisticsOverall.getResolutionLimitHigh();
        nTotalObservations = "" + autoProcStatisticsOverall.getnTotalObservations();
        nTotalUniqueReflections = "" + (autoProcStatisticsOverall.getnTotalUniqueObservations() == null ? ""
                : autoProcStatisticsOverall.getnTotalUniqueObservations());
        completeness = "" + autoProcStatisticsOverall.getCompleteness();
        multiplicity = "" + autoProcStatisticsOverall.getMultiplicity();
        isigma = "" + autoProcStatisticsOverall.getMeanIoverSigI();
        rmerge = ""
                + (autoProcStatisticsOverall.getRmerge() == null ? "" : autoProcStatisticsOverall.getRmerge());
    }
    if (autoProcStatisticsOuter != null) {
        resolutionRange += " (" + autoProcStatisticsOuter.getResolutionLimitLow() + " - "
                + autoProcStatisticsOuter.getResolutionLimitHigh() + ")";
        nTotalObservations += " (" + autoProcStatisticsOuter.getnTotalObservations() + ")";
        nTotalUniqueReflections += autoProcStatisticsOuter.getnTotalUniqueObservations() == null ? ""
                : (" (" + autoProcStatisticsOuter.getnTotalUniqueObservations() + ")");
        completeness += " (" + autoProcStatisticsOuter.getCompleteness() + ")";
        multiplicity += " (" + autoProcStatisticsOuter.getMultiplicity() + ")";
        isigma += " (" + autoProcStatisticsOuter.getMeanIoverSigI() + ")";
        rmerge += " ("
                + (autoProcStatisticsOuter.getRmerge() == null ? "" : autoProcStatisticsOuter.getRmerge())
                + ")";
    }
    // space group
    autoProcTable.addCell(new Paragraph("Space Group", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(spaceGroup, PdfRtfExporter.FONT_DOC_11));
    // unit cell parameters
    autoProcTable.addCell(
            new Paragraph("Unit-cell parameters (" + Constants.ANGSTROM + ")", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph("", PdfRtfExporter.FONT_DOC_11));
    Paragraph pa = new Paragraph("\t a", PdfRtfExporter.FONT_DOC_11);
    pa.setAlignment(Element.ALIGN_JUSTIFIED);
    pa.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pa);
    autoProcTable.addCell(new Paragraph(unitCell_a, PdfRtfExporter.FONT_DOC_11));
    Paragraph pb = new Paragraph("\t b", PdfRtfExporter.FONT_DOC_11);
    pb.setAlignment(Element.ALIGN_JUSTIFIED);
    pb.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pb);
    autoProcTable.addCell(new Paragraph(unitCell_b, PdfRtfExporter.FONT_DOC_11));
    Paragraph pc = new Paragraph("\t c", PdfRtfExporter.FONT_DOC_11);
    pc.setAlignment(Element.ALIGN_JUSTIFIED);
    pc.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pc);
    autoProcTable.addCell(new Paragraph(unitCell_c, PdfRtfExporter.FONT_DOC_11));
    // Issue 1733: cell angles info added
    Paragraph palpha = new Paragraph("\t alpha", PdfRtfExporter.FONT_DOC_11);
    palpha.setAlignment(Element.ALIGN_JUSTIFIED);
    palpha.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(palpha);
    autoProcTable.addCell(new Paragraph(unitCell_alpha, PdfRtfExporter.FONT_DOC_11));
    Paragraph pbeta = new Paragraph("\t beta", PdfRtfExporter.FONT_DOC_11);
    pbeta.setAlignment(Element.ALIGN_JUSTIFIED);
    pbeta.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pbeta);
    autoProcTable.addCell(new Paragraph(unitCell_beta, PdfRtfExporter.FONT_DOC_11));
    Paragraph pgamma = new Paragraph("\t gamma", PdfRtfExporter.FONT_DOC_11);
    pgamma.setAlignment(Element.ALIGN_JUSTIFIED);
    pgamma.setIndentationLeft(PdfRtfExporter.INDENTATION_LEFT);
    autoProcTable.addCell(pgamma);
    autoProcTable.addCell(new Paragraph(unitCell_gamma, PdfRtfExporter.FONT_DOC_11));
    // resolution range
    autoProcTable.addCell(
            new Paragraph("Resolution range (" + Constants.ANGSTROM + ")", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(resolutionRange, PdfRtfExporter.FONT_DOC_11));
    // Observed reflections
    autoProcTable.addCell(new Paragraph("Observed reflections", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(nTotalObservations, PdfRtfExporter.FONT_DOC_11));
    // No. of unique reflections
    autoProcTable.addCell(new Paragraph("No. of unique reflections", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(nTotalUniqueReflections, PdfRtfExporter.FONT_DOC_11));
    // Completeness
    autoProcTable.addCell(new Paragraph("Completeness (%)", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(completeness, PdfRtfExporter.FONT_DOC_11));
    // multiplicity
    autoProcTable.addCell(new Paragraph("Multiplicity", PdfRtfExporter.FONT_DOC_11));
    autoProcTable.addCell(new Paragraph(multiplicity, PdfRtfExporter.FONT_DOC_11));
    new Phrase();
    // I/(I)
    Phrase p = Phrase.getInstance("<I/" + (char) 963 + "(I)>");
    p.setFont(PdfRtfExporter.FONT_DOC_11);
    autoProcTable.addCell(p);
    autoProcTable.addCell(new Paragraph(isigma, PdfRtfExporter.FONT_DOC_11));
    // Rmerge
    Chunk c1 = new Chunk("R", PdfRtfExporter.FONT_DOC_11);
    Chunk c2 = new Chunk("merge", PdfRtfExporter.FONT_DOC_EXPONENT);
    c2.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    Chunk c3 = new Chunk("(%)", PdfRtfExporter.FONT_DOC_11);
    Chunk c4 = new Chunk("#", PdfRtfExporter.FONT_DOC_EXPONENT_BLUE);
    c4.setTextRise(PdfRtfExporter.TEXT_RISE_EXP);
    Paragraph rMergeParagraph = new Paragraph();
    rMergeParagraph.add(c1);
    rMergeParagraph.add(c2);
    rMergeParagraph.add(c3);
    rMergeParagraph.add(c4);
    autoProcTable.addCell(rMergeParagraph);
    autoProcTable.addCell(new Paragraph(rmerge, PdfRtfExporter.FONT_DOC_11));
    document.add(autoProcTable);
    document.add(new Paragraph(" ", PdfRtfExporter.FONT_DOC_11));
    // nota bene info
    Paragraph nbParagraph = new Paragraph();
    nbParagraph.add(c4);
    nbParagraph.add(c1);
    nbParagraph.add(c2);
    Chunk cesp = new Chunk(" ", PdfRtfExporter.FONT_DOC_11);
    Chunk c5 = new Chunk(" = ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c5);
    Phrase pSigma = Phrase.getInstance("" + (char) 931);
    pSigma.setFont(PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(pSigma);
    Chunk chkl = new Chunk("hkl", PdfRtfExporter.FONT_DOC_EXPONENT);
    chkl.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    nbParagraph.add(chkl);
    nbParagraph.add(cesp);
    nbParagraph.add(pSigma);
    Chunk ci = new Chunk("i", PdfRtfExporter.FONT_DOC_EXPONENT);
    ci.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    nbParagraph.add(ci);
    Chunk c8 = new Chunk(" |I", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c8);
    nbParagraph.add(ci);
    Chunk c9 = new Chunk("(hkl) - (I(hkl))| / ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c9);
    nbParagraph.add(pSigma);
    nbParagraph.add(chkl);
    nbParagraph.add(cesp);
    nbParagraph.add(pSigma);
    nbParagraph.add(ci);
    nbParagraph.add(cesp);
    Chunk c10 = new Chunk("I", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c10);
    nbParagraph.add(ci);
    Chunk c11 = new Chunk("(hkl), where ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c11);
    Chunk c12 = new Chunk("I", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c12);
    Chunk cii = new Chunk("i", PdfRtfExporter.FONT_DOC_EXPONENT_ITALIC);
    cii.setTextRise(PdfRtfExporter.TEXT_RISE_SUB);
    nbParagraph.add(cii);
    Chunk c13 = new Chunk("(hkl)", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c13);
    Chunk c14 = new Chunk(" is the ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c14);
    Chunk c15 = new Chunk("i", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c15);
    Chunk c16 = new Chunk("th observation of reflection ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c16);
    Chunk chklI = new Chunk("hkl", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(chklI);
    Chunk c17 = new Chunk(" and ", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c17);
    Chunk c18 = new Chunk("<I(hkl)> ", PdfRtfExporter.FONT_DOC_11_ITALIC);
    nbParagraph.add(c18);
    Chunk c19 = new Chunk(" is the weighted average intensity for all observations of reflection ",
            PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c19);
    nbParagraph.add(chklI);
    Chunk c20 = new Chunk(".", PdfRtfExporter.FONT_DOC_11);
    nbParagraph.add(c20);
    document.add(nbParagraph);
    document.add(new Paragraph(" ", PdfRtfExporter.FONT_DOC_11));
}