Example usage for com.lowagie.text Font STRIKETHRU

List of usage examples for com.lowagie.text Font STRIKETHRU

Introduction

In this page you can find the example usage for com.lowagie.text Font STRIKETHRU.

Prototype

int STRIKETHRU

To view the source code for com.lowagie.text Font STRIKETHRU.

Click Source Link

Document

this is a possible style.

Usage

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);
    }//from  w ww . j  a  va  2s. c om
    // 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

@Override
protected void visitRun(XWPFRun docxRun, boolean pageNumber, String url, IITextContainer pdfParagraphContainer)
        throws Exception {
    // Font family
    String fontFamilyAscii = stylesDocument.getFontFamilyAscii(docxRun);
    String fontFamilyEastAsia = stylesDocument.getFontFamilyEastAsia(docxRun);
    String fontFamilyHAnsi = stylesDocument.getFontFamilyHAnsi(docxRun);

    // Get font size
    Float fontSize = stylesDocument.getFontSize(docxRun);
    if (fontSize == null) {
        fontSize = -1f;//from  w w  w .  j a  v a  2s.c o  m
    }

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

    // Font color
    Color fontColor = stylesDocument.getFontColor(docxRun);

    // Font
    this.currentRunFontAscii = getFont(fontFamilyAscii, fontSize, fontStyle, fontColor);
    this.currentRunFontEastAsia = getFont(fontFamilyEastAsia, fontSize, fontStyle, fontColor);
    this.currentRunFontHAnsi = getFont(fontFamilyHAnsi, fontSize, fontStyle, fontColor);

    // Underline patterns
    this.currentRunUnderlinePatterns = stylesDocument.getUnderline(docxRun);

    // background color
    this.currentRunBackgroundColor = stylesDocument.getBackgroundColor(docxRun);

    // highlight
    if (currentRunBackgroundColor == null) {
        this.currentRunBackgroundColor = stylesDocument.getTextHighlighting(docxRun);
    }

    StylableParagraph pdfParagraph = (StylableParagraph) pdfParagraphContainer;
    pdfParagraph.adjustMultipliedLeading(currentRunFontAscii);

    // addd symbol list item chunk if needed.
    String listItemText = pdfParagraph.getListItemText();
    if (StringUtils.isNotEmpty(listItemText)) {
        // FIXME: add some space after the list item
        listItemText += "    ";

        String listItemFontFamily = pdfParagraph.getListItemFontFamily();
        Float listItemFontSize = pdfParagraph.getListItemFontSize();
        int listItemFontStyle = pdfParagraph.getListItemFontStyle();
        java.awt.Color listItemFontColor = pdfParagraph.getListItemFontColor();
        Font listItemFont = options.getFontProvider().getFont(
                listItemFontFamily != null ? listItemFontFamily : fontFamilyAscii, options.getFontEncoding(),
                listItemFontSize != null ? listItemFontSize : fontSize,
                listItemFontStyle != Font.NORMAL ? listItemFontStyle : fontStyle,
                listItemFontColor != null ? listItemFontColor : Converter.toAwtColor(fontColor));
        Chunk symbol = createTextChunk(listItemText, false, listItemFont, currentRunUnderlinePatterns,
                currentRunBackgroundColor);
        pdfParagraph.add(symbol);
        pdfParagraph.setListItemText(null);
    }

    IITextContainer container = pdfParagraphContainer;
    if (url != null) {
        // URL is not null, generate a PDF hyperlink.
        StylableAnchor pdfAnchor = new StylableAnchor();
        pdfAnchor.setReference(url);
        pdfAnchor.setITextContainer(container);
        container = pdfAnchor;
    }
    super.visitRun(docxRun, pageNumber, url, container);

    if (url != null) {
        // URL is not null, add the PDF hyperlink in the PDF paragraph
        pdfParagraphContainer.addElement((StylableAnchor) container);
    }

    this.currentRunFontAscii = null;
    this.currentRunFontEastAsia = null;
    this.currentRunFontHAnsi = null;
    this.currentRunUnderlinePatterns = null;
    this.currentRunBackgroundColor = null;
}

From source file:fr.opensagres.xdocreport.itext.extension.font.AbstractFontRegistry.java

License:Open Source License

/**
 * checks if the style of this font is STRIKETHRU.
 * /*from   www.  j a va 2s  .  co m*/
 * @return a <CODE>boolean</CODE>
 */
public boolean isStrikethru(int style) {
    if (style == Font.UNDEFINED) {
        return false;
    }
    return (style & Font.STRIKETHRU) == Font.STRIKETHRU;
}

From source file:jm.seg.frmGeneraPdf.java

License:GNU General Public License

public void GenerarFactura(String ruta_xml, String dir, String _archivoNombre) throws FileNotFoundException {
    File _archivo = null;/*from   w  ww .  j a va  2  s  .  c o  m*/
    Xml xml = new Xml(ruta_xml + ".xml");

    String numeroAutorizacion = xml.getValor("numeroAutorizacion");
    String fechaAutorizacion = xml.getValor("fechaAutorizacion");

    String doc = xml.getValor("comprobante");
    try {

        _archivo = new File(dir, _archivoNombre + "xml.xml");
        if (!_archivo.exists()) {
            //byte[] bytes = (res.getString(campoBytea)!=null) ? res.getBytes(campoBytea) : null;
            RandomAccessFile archivo = new RandomAccessFile(dir + _archivoNombre + "xml.xml", "rw");
            archivo.writeBytes(doc);
            archivo.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    //infoTributaria
    Xml xml2 = new Xml(ruta_xml + "xml.xml");
    String ambiente = xml2.getValor("ambiente");
    String tipoEmision = xml2.getValor("tipoEmision");
    String razonSocial = xml2.getValor("razonSocial");
    String nombreComercial = xml2.getValor("nombreComercial");
    String ruc = xml2.getValor("ruc");
    String claveAcceso = xml2.getValor("claveAcceso");
    String codDoc = xml2.getValor("codDoc");
    String numFac = xml2.getValor("estab") + "-" + xml2.getValor("ptoEmi") + "-" + xml2.getValor("secuencial");
    String dirMatriz = xml2.getValor("dirMatriz");

    String EMAIL = "";
    String DIRECCION = "";
    String ARCOTEL = "";

    int limiteAdi = xml2.getNumNodos("campoAdicional");
    try {
        //Campos Adicionales
        for (int i = 0; i < limiteAdi; i++) {
            if (xml2.getAtributo("campoAdicional", i, "nombre").toUpperCase().compareTo("EMAIL") == 0) {
                EMAIL = xml2.getValor("campoAdicional", i);
            }
            if (xml2.getAtributo("campoAdicional", i, "nombre").toUpperCase().compareTo("DIRECCION") == 0) {
                DIRECCION = xml2.getValor("campoAdicional", i);
            }
            if (xml2.getAtributo("campoAdicional", i, "nombre").toUpperCase().compareTo("ARCOTEL") == 0) {
                ARCOTEL = xml2.getValor("campoAdicional", i);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (ambiente.compareTo("1") == 0) {
        ambiente = "Pruebas";
    }
    if (ambiente.compareTo("2") == 0) {
        ambiente = "Produccin";
    }
    if (tipoEmision.compareTo("1") == 0) {
        tipoEmision = "Normal";
    }
    if (tipoEmision.compareTo("2") == 0) {
        tipoEmision = "Contingencia";
    }

    if (codDoc.compareTo("01") == 0) {
        //infoFactura
        String fechaEmision = xml2.getValor("fechaEmision");
        String dirEstablecimiento = xml2.getValor("dirEstablecimiento");
        String contribuyenteEspecial = xml2.getValor("contribuyenteEspecial");
        String obligadoContabilidad = xml2.getValor("obligadoContabilidad");
        String razonSocialComprador = xml2.getValor("razonSocialComprador");
        String identificacionComprador = xml2.getValor("identificacionComprador");
        String totalSinImpuestos = xml2.getValor("totalSinImpuestos");
        String totalDescuento = xml2.getValor("totalDescuento");
        String codigoPorcentaje = xml2.getValor("codigoPorcentaje");//0% 0 >>12% 2>>mo objeto de impuesto 6>>Excento al iva 7
        String baseImponible = xml2.getValor("baseImponible"); //Depende del codigo porcentaje
        String valor = xml2.getValor("valor");// va en el Iva 12%
        String importeTotal = xml2.getValor("importeTotal");//Sumatoria de todo

        //detalles
        int limite = xml2.getNumNodos("detalle");
        String[][] array = new String[limite][6];
        for (int i = 0; i < limite; i++) {
            array[i][0] = xml2.getValor("codigoPrincipal");
            array[i][1] = xml2.getValor("descripcion");
            array[i][2] = xml2.getValor("cantidad");
            array[i][3] = xml2.getValor("precioUnitario");
            array[i][4] = xml2.getValor("descuento");
            array[i][5] = xml2.getValor("precioTotalSinImpuesto");
        }

        /* inicio PDF */
        Document pdf = new Document(PageSize.A4);// paso 1
        pdf.setMargins(-35, -45, 40, 10); /*Izquierda, derecha, tope, pie */

        try {
            PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(dir + claveAcceso + ".pdf"));
            pdf.open();

            //pdf.open(); // paso 3
            // Para enviar a la impresora automticamente.
            //writer.addJavaScript("this.print(false);", false);

            /* todo el cuerpo del doc es el paso 4 */
            //PdfPTable tbl_titulo = new PdfPTable(1);
            PdfPTable tbl_titulo = new PdfPTable(new float[] { 49f, 2f, 49f });
            PdfPTable tbl_1 = new PdfPTable(new float[] { 37f, 63f });
            PdfPTable tbl_2 = new PdfPTable(1);
            //titulos izquierda
            tbl_1.addCell(Addons.setLogo(dir + "logo.jpg", 250, 83, Element.ALIGN_CENTER));//ancho,alto
            tbl_1.addCell(
                    Addons.setCeldaPDF(" ", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF(razonSocial + " '" + nombreComercial + "' ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 2));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Matriz: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirMatriz, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0,
                    5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Sucursal: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirEstablecimiento, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Contribuyente Especial Nro. " + contribuyenteEspecial,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF("OBLIGADO A LLEVAR CONTABILIDAD: " + obligadoContabilidad,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));

            //Titulos derecha
            tbl_2.addCell(Addons.setCeldaPDF("R.U.C: " + ruc, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("F A C T U R A ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("No. " + numFac, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("NMERO DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(numeroAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("FECHA Y HORA DE AUTORIZACION", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(fechaAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("AMBIENTE: " + ambiente, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("EMISIN:  " + tipoEmision, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("CLAVE DE ACCESO", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setBarCode(this.getBarcode(writer, claveAcceso)));//ancho,alto

            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_1, 0, 1));
            tbl_titulo.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_2, 0, 1));
            tbl_titulo.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_titulo);

            //Informacion Cliente
            PdfPTable tbl_info = new PdfPTable(1);
            PdfPTable tbl_info1 = new PdfPTable(new float[] { 32f, 43f, 25f });
            tbl_info1.addCell(Addons.setCeldaPDF("Razn Social / Nombres y Apellidos: ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF(razonSocialComprador, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF("RUC/CI: " + identificacionComprador, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF("Fecha de emisin:    " + fechaEmision, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 1));
            tbl_info1.addCell(Addons.setCeldaPDF("DIRECCION: " + DIRECCION, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 2));
            tbl_info.addCell(Addons.setCeldaPDF(tbl_info1, 0, 1));
            tbl_info.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_info);

            //Detalles
            PdfPTable tbl_det = new PdfPTable(1);
            PdfPTable tbl_det1 = new PdfPTable(new float[] { 10f, 10f, 50f, 10f, 10f, 10f });

            tbl_det1.addCell(Addons.setCeldaPDF("Cod. Principal", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Cant.", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Descripcin", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Precio Unitario", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Desc.", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Total", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            for (int i = 0; i < limite; i++) {
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][0], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][2], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][1], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][3], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][4], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][5], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
            }
            tbl_det.addCell(Addons.setCeldaPDF(tbl_det1, 0, 1));
            tbl_det.addCell(Addons.setFilaBlanco(6, 20));
            pdf.add(tbl_det);

            //Informacion Adicional
            PdfPTable tbl_info_ad = new PdfPTable(new float[] { 40f, 10f, 50f });
            PdfPTable tbl_info_ad1 = new PdfPTable(new float[] { 30f, 70f });
            PdfPTable tbl_info_ad2 = new PdfPTable(new float[] { 70f, 30f });
            //titulos izquierda
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Informacin Adicional", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 0, 5, 2));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Contacto: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("062609177 / 062610330", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Email: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(EMAIL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Sitio Web:", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("www.saitel.ec", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(ARCOTEL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 2));

            //Titulos derecha
            if (codigoPorcentaje.compareTo("0") == 0) {
                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 12% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 0, 5, 2));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 0% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(baseImponible, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL No objeto de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL SIN IMPUESTOS", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalSinImpuestos, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL Exento de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(valor, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("DESCUENTO", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalDescuento, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("IVA 12%", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));
            }

            if (codigoPorcentaje.compareTo("2") == 0) {
                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 12% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(baseImponible, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 0% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL No objeto de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL SIN IMPUESTOS", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalSinImpuestos, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL Exento de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("DESCUENTO", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalDescuento, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("IVA 12%", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(
                        Addons.setCeldaPDF(valor, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_RIGHT, 1, 5));
            }

            tbl_info_ad2.addCell(Addons.setCeldaPDF("VALOR TOTAL", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_info_ad2.addCell(Addons.setCeldaPDF(Addons.redondear(importeTotal), Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_RIGHT, 1, 5));

            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad1, 0, 1));
            tbl_info_ad.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad2, 0, 1));
            pdf.add(tbl_info_ad);

        } catch (IllegalStateException ie) {
            ie.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } finally {
        }
        pdf.close(); // paso 5
        /* fin PDF */
    }

    //Nota de credito
    if (codDoc.compareTo("04") == 0) {
        //infoFactura
        String fechaEmision = xml2.getValor("fechaEmision");
        String dirEstablecimiento = xml2.getValor("dirEstablecimiento");
        String razonSocialComprador = xml2.getValor("razonSocialComprador");
        String identificacionComprador = xml2.getValor("identificacionComprador");
        String contribuyenteEspecial = xml2.getValor("contribuyenteEspecial");
        String obligadoContabilidad = xml2.getValor("obligadoContabilidad");
        String codDocModificado = xml2.getValor("codDocModificado");
        String numDocModificado = xml2.getValor("numDocModificado");
        String fechaEmisionDocSustento = xml2.getValor("fechaEmisionDocSustento");
        String motivo = xml2.getValor("motivo");
        String totalSinImpuestos = xml2.getValor("totalSinImpuestos");

        if (codDocModificado.compareTo("01") == 0) {
            codDocModificado = "FACTURA";
        }
        if (codDocModificado.compareTo("04") == 0) {
            codDocModificado = "NOTA DE CRDITO";
        }
        if (codDocModificado.compareTo("05") == 0) {
            codDocModificado = "NOTA DE DBITO";
        }
        if (codDocModificado.compareTo("06") == 0) {
            codDocModificado = "GU?A DE REMISION";
        }
        if (codDocModificado.compareTo("07") == 0) {
            codDocModificado = "COMPROBANTE DE RETENCIN";
        }

        String codigoPorcentaje = xml2.getValor("codigoPorcentaje");//0% 0 >>12% 2>>mo objeto de impuesto 6>>Excento al iva 7
        String baseImponible = xml2.getValor("baseImponible"); //Depende del codigo porcentaje
        String valor = xml2.getValor("valor");// va en el Iva 12%

        //detalles
        int limite = xml2.getNumNodos("detalle");
        String[][] array = new String[limite][6];
        for (int i = 0; i < limite; i++) {
            array[i][0] = xml2.getValor("codigoPrincipal");
            array[i][1] = xml2.getValor("descripcion");
            array[i][2] = xml2.getValor("cantidad");
            array[i][3] = xml2.getValor("precioUnitario");
            array[i][4] = xml2.getValor("descuento");
            array[i][5] = xml2.getValor("precioTotalSinImpuesto");
        }

        /* inicio PDF */
        Document pdf = new Document(PageSize.A4);// paso 1
        pdf.setMargins(-35, -45, 40, 10); /*Izquierda, derecha, tope, pie */

        try {
            PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(dir + claveAcceso + ".pdf"));
            pdf.open();

            //pdf.open(); // paso 3
            // Para enviar a la impresora automticamente.
            //writer.addJavaScript("this.print(false);", false);

            /* todo el cuerpo del doc es el paso 4 */
            //PdfPTable tbl_titulo = new PdfPTable(1);
            PdfPTable tbl_titulo = new PdfPTable(new float[] { 49f, 2f, 49f });
            PdfPTable tbl_1 = new PdfPTable(new float[] { 37f, 63f });
            PdfPTable tbl_2 = new PdfPTable(1);
            //titulos izquierda
            tbl_1.addCell(Addons.setLogo(dir + "logo.jpg", 250, 83, Element.ALIGN_CENTER));//ancho,alto
            tbl_1.addCell(
                    Addons.setCeldaPDF(" ", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF(razonSocial + " '" + nombreComercial + "' ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 2));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Matriz: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirMatriz, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0,
                    5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Sucursal: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirEstablecimiento, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Contribuyente Especial Nro. " + contribuyenteEspecial,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF("OBLIGADO A LLEVAR CONTABILIDAD: " + obligadoContabilidad,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));

            //Titulos derecha
            tbl_2.addCell(Addons.setCeldaPDF("R.U.C: " + ruc, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("F A C T U R A ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("No. " + numFac, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("NMERO DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(numeroAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("FECHA Y HORA DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(fechaAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("AMBIENTE: " + ambiente, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("EMISIN:  " + tipoEmision, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("CLAVE DE ACCESO", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setBarCode(this.getBarcode(writer, claveAcceso)));//ancho,alto

            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_1, 0, 1));
            tbl_titulo.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_2, 0, 1));
            tbl_titulo.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_titulo);

            //Informacion Cliente
            PdfPTable tbl_info = new PdfPTable(1);
            PdfPTable tbl_info1 = new PdfPTable(new float[] { 32f, 43f, 25f });
            tbl_info1.addCell(Addons.setCeldaPDF("Razn Social / Nombres y Apellidos: ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF(razonSocialComprador, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF("RUC/CI: " + identificacionComprador, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF("Fecha de emisin:" + fechaEmision, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 3));

            tbl_info1.addCell(Addons.setCeldaPDF(
                    "-------------------------------------------------------------------------------------------------------------",
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 0, 5, 3));
            tbl_info1.addCell(Addons.setCeldaPDF("Comprobante que se Modifica:", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF(codDocModificado + ": " + numDocModificado, Font.STRIKETHRU,
                    10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_info1.addCell(Addons.setCeldaPDF("Fecha emisin (Comprobante a Modificar)", Font.STRIKETHRU,
                    10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(Addons.setCeldaPDF(fechaEmisionDocSustento, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 2));
            tbl_info1.addCell(Addons.setCeldaPDF("Razn de Modificacin: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_info1.addCell(
                    Addons.setCeldaPDF(motivo, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_info.addCell(Addons.setCeldaPDF(tbl_info1, 0, 1));
            tbl_info.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_info);

            //Detalles
            PdfPTable tbl_det = new PdfPTable(1);
            PdfPTable tbl_det1 = new PdfPTable(new float[] { 10f, 10f, 50f, 10f, 10f, 10f });

            tbl_det1.addCell(Addons.setCeldaPDF("Cod. Principal", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Cant.", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Descripcin", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Precio Unitario", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Desc.", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Total", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_CENTER, 1, 5));
            for (int i = 0; i < limite; i++) {
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][0], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][2], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][1], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][3], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][4], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][5], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));
            }
            tbl_det.addCell(Addons.setCeldaPDF(tbl_det1, 0, 1));
            tbl_det.addCell(Addons.setFilaBlanco(6, 20));
            pdf.add(tbl_det);

            //Informacion Adicional
            PdfPTable tbl_info_ad = new PdfPTable(new float[] { 40f, 10f, 50f });
            PdfPTable tbl_info_ad1 = new PdfPTable(new float[] { 30f, 70f });
            PdfPTable tbl_info_ad2 = new PdfPTable(new float[] { 70f, 30f });
            //titulos izquierda
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Informacin Adicional", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 0, 5, 2));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Contacto: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("062609177 / 062610330", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Email: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(EMAIL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Sitio Web:", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("www.saitel.ec", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(ARCOTEL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 2));

            //Titulos derecha
            if (codigoPorcentaje.compareTo("0") == 0) {
                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 12% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 0, 5, 2));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 0% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(baseImponible, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL No objeto de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL SIN IMPUESTOS", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalSinImpuestos, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL Exento de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(valor, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("IVA 12%", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_CENTER, 0, 8, 0));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0, 5, 2));
            }

            else {
                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 12% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(baseImponible, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL 0% ", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL No objeto de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL SIN IMPUESTOS", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF(totalSinImpuestos, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("SUBTOTAL Exento de IVA", Font.STRIKETHRU, 10,
                        Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(Addons.setCeldaPDF("0.00", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1, 5));

                tbl_info_ad2.addCell(Addons.setCeldaPDF("IVA 12%", Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));
                tbl_info_ad2.addCell(
                        Addons.setCeldaPDF(valor, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_RIGHT, 1, 5));
            }

            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad1, 0, 1));
            tbl_info_ad.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad2, 0, 1));
            pdf.add(tbl_info_ad);

        } catch (IllegalStateException ie) {
            ie.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } finally {
        }
        pdf.close(); // paso 5
        /* fin PDF */
    }

    //Comprobante de retencion
    if (codDoc.compareTo("07") == 0) {
        //infoCompRetencion
        String fechaEmision = xml2.getValor("fechaEmision");
        String dirEstablecimiento = xml2.getValor("dirEstablecimiento");
        String contribuyenteEspecial = xml2.getValor("contribuyenteEspecial");
        String obligadoContabilidad = xml2.getValor("obligadoContabilidad");
        String tipoIdentificacionSujetoRetenido = xml2.getValor("tipoIdentificacionSujetoRetenido");
        String razonSocialSujetoRetenido = xml2.getValor("razonSocialSujetoRetenido");
        String identificacionSujetoRetenido = xml2.getValor("identificacionSujetoRetenido");
        String periodoFiscal = xml2.getValor("periodoFiscal");

        //detalles
        int limite = xml2.getNumNodos("impuesto");
        String[][] array = new String[limite][7];
        for (int i = 0; i < limite; i++) {
            array[i][0] = xml2.getValor("codigo", i);
            array[i][1] = xml2.getValor("codigoRetencion", i);
            array[i][2] = xml2.getValor("baseImponible", i);
            array[i][3] = xml2.getValor("porcentajeRetener", i);
            array[i][4] = xml2.getValor("valorRetenido", i);
            array[i][5] = xml2.getValor("codDocSustento", i);
            array[i][6] = xml2.getValor("numDocSustento", i);
        }

        /* inicio PDF */
        Document pdf = new Document(PageSize.A4);// paso 1
        pdf.setMargins(-35, -45, 40, 10); /*Izquierda, derecha, tope, pie */

        try {
            PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(dir + claveAcceso + ".pdf"));
            pdf.open();

            //pdf.open(); // paso 3
            // Para enviar a la impresora automticamente.
            //writer.addJavaScript("this.print(false);", false);

            /* todo el cuerpo del doc es el paso 4 */
            //PdfPTable tbl_titulo = new PdfPTable(1);
            PdfPTable tbl_titulo = new PdfPTable(new float[] { 49f, 2f, 49f });
            PdfPTable tbl_1 = new PdfPTable(new float[] { 37f, 63f });
            PdfPTable tbl_2 = new PdfPTable(1);
            //titulos izquierda
            tbl_1.addCell(Addons.setLogo(dir + "logo.jpg", 250, 83, Element.ALIGN_CENTER));//ancho,alto
            tbl_1.addCell(
                    Addons.setCeldaPDF(" ", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF(razonSocial + " '" + nombreComercial + "' ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_CENTER, 0, 8, 2));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Matriz: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirMatriz, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0,
                    5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Direccin Sucursal: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF(dirEstablecimiento, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5, 0));
            tbl_1.addCell(Addons.setCeldaPDF("Contribuyente Especial Nro. " + contribuyenteEspecial,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));
            tbl_1.addCell(Addons.setCeldaPDF("OBLIGADO A LLEVAR CONTABILIDAD: " + obligadoContabilidad,
                    Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 5, 2));

            //Titulos derecha
            tbl_2.addCell(Addons.setCeldaPDF("R.U.C: " + ruc, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("COMPROBANTE DE RETENCIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("No. " + numFac, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("NMERO DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(numeroAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("FECHA Y HORA DE AUTORIZACIN", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF(fechaAutorizacion, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("AMBIENTE: " + ambiente, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("EMISIN:  " + tipoEmision, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setCeldaPDF("CLAVE DE ACCESO", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 5));
            tbl_2.addCell(Addons.setBarCode(this.getBarcode(writer, claveAcceso)));//ancho,alto

            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_1, 0, 1));
            tbl_titulo.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_titulo.addCell(Addons.setCeldaPDF(tbl_2, 0, 1));
            tbl_titulo.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_titulo);

            //Informacion Cliente
            PdfPTable tbl_info = new PdfPTable(1);
            PdfPTable tbl_info1 = new PdfPTable(new float[] { 32f, 43f, 25f });
            tbl_info1.addCell(Addons.setCeldaPDF("Razn Social / Nombres y Apellidos: ", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF(razonSocialSujetoRetenido, Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF("RUC/CI: " + identificacionSujetoRetenido, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8));
            tbl_info1.addCell(Addons.setCeldaPDF("Fecha de emisin: " + fechaEmision, Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 3));
            tbl_info.addCell(Addons.setCeldaPDF(tbl_info1, 0, 1));
            tbl_info.addCell(Addons.setFilaBlanco(3, 20));
            pdf.add(tbl_info);

            //Detalles
            PdfPTable tbl_det = new PdfPTable(1);
            PdfPTable tbl_det1 = new PdfPTable(new float[] { 14f, 18f, 12f, 10f, 13f, 10f, 13f, 10f });

            tbl_det1.addCell(Addons.setCeldaPDF("Comprobante", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Nmero", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Fecha Emisin", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Ejercicio Fiscal", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Base Imponible para la retencion", Font.STRIKETHRU, 8,
                    Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(
                    Addons.setCeldaPDF("Impuesto", Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Porcentaje de Retencin", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            tbl_det1.addCell(Addons.setCeldaPDF("Valor Retenido", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 1, 5));
            Double val_ret = 0.0;

            //detalles
            for (int i = 0; i < limite; i++) {
                //Comprobante
                if (array[i][5].compareTo("01") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("FACTURA", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][5].compareTo("04") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("NOTA DE CRDITO", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][5].compareTo("05") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("NOTA DE DBITO", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][5].compareTo("06") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("GU?A DE REMISION", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][5].compareTo("07") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("COMPROBANTE DE RETENCIN", Font.STRIKETHRU, 10,
                            Font.NORMAL, Element.ALIGN_LEFT, 1, 5));
                }

                //Nmero
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][6], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Fecha Emisin
                tbl_det1.addCell(Addons.setCeldaPDF(fechaEmision, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Ejercicio Fiscal
                tbl_det1.addCell(Addons.setCeldaPDF(periodoFiscal, Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Base Imponible para la retencion
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][2], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Impuesto
                if (array[i][0].compareTo("1") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("RENTA", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][0].compareTo("2") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("IVA", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }
                if (array[i][0].compareTo("6") == 0) {
                    tbl_det1.addCell(Addons.setCeldaPDF("ISD", Font.STRIKETHRU, 10, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 5));
                }

                //Porcentaje de Retencin
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][3], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                //Valor Retenido
                tbl_det1.addCell(Addons.setCeldaPDF(array[i][4], Font.STRIKETHRU, 10, Font.NORMAL,
                        Element.ALIGN_LEFT, 1, 5));

                val_ret += Double.parseDouble(array[i][4]);
            }
            tbl_det1.addCell(Addons.setCeldaPDF("Valor Retenido", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_RIGHT, 1, 5, 7));
            tbl_det1.addCell(Addons.setCeldaPDF(Addons.redondear(val_ret) + "", Font.STRIKETHRU, 10,
                    Font.NORMAL, Element.ALIGN_LEFT, 1, 5, 1));
            tbl_det.addCell(Addons.setCeldaPDF(tbl_det1, 0, 1));
            tbl_det.addCell(Addons.setFilaBlanco(6, 20));
            pdf.add(tbl_det);

            //Informacion Adicional
            PdfPTable tbl_info_ad = new PdfPTable(new float[] { 40f, 10f, 50f });
            PdfPTable tbl_info_ad1 = new PdfPTable(new float[] { 30f, 70f });
            //titulos izquierda
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Informacin Adicional", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_CENTER, 0, 5, 2));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Contacto: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("062609177 / 062610330", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Email: ", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(EMAIL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("Sitio Web:", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(Addons.setCeldaPDF("www.saitel.ec", Font.STRIKETHRU, 10, Font.NORMAL,
                    Element.ALIGN_LEFT, 0, 8, 0));
            tbl_info_ad1.addCell(
                    Addons.setCeldaPDF(ARCOTEL, Font.STRIKETHRU, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 8, 2));
            tbl_info_ad.addCell(Addons.setCeldaPDF(tbl_info_ad1, 0, 1));
            tbl_info_ad.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            tbl_info_ad.addCell(Addons.setCeldaPDF(" ", Font.TIMES_ROMAN, 1, Font.NORMAL, 0, 0));
            pdf.add(tbl_info_ad);

        } catch (IllegalStateException ie) {
            ie.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        } finally {
        }
        pdf.close(); // paso 5
        /* fin PDF */
    }

}

From source file:net.sf.jasperreports.engine.export.JRPdfExporter.java

License:LGPL

/**
 *
 *///from   w ww.  ja  v  a  2s.co  m
protected Font getFont(Map attributes) {
    JRFont jrFont = new JRBaseFont(attributes);

    Exception initialException = null;

    Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND);

    Font font = null;
    PdfFont pdfFont = null;
    FontKey key = new FontKey(jrFont.getFontName(), jrFont.isBold(), jrFont.isItalic());

    if (fontMap != null && fontMap.containsKey(key)) {
        pdfFont = (PdfFont) fontMap.get(key);
    } else {
        pdfFont = new PdfFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded());
    }

    try {
        font = FontFactory.getFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(), pdfFont.isPdfEmbedded(),
                jrFont.getFontSize(),
                (pdfFont.isPdfSimulatedBold() ? Font.BOLD : 0)
                        | (pdfFont.isPdfSimulatedItalic() ? Font.ITALIC : 0)
                        | (jrFont.isUnderline() ? Font.UNDERLINE : 0)
                        | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0),
                forecolor);

        // check if FontFactory didn't find the font
        if (font.getBaseFont() == null && font.family() == Font.UNDEFINED) {
            font = null;
        }
    } catch (Exception e) {
        initialException = e;
    }

    if (font == null) {
        byte[] bytes = null;

        try {
            bytes = JRLoader.loadBytesFromLocation(pdfFont.getPdfFontName(), classLoader, urlHandlerFactory,
                    fileResolver);
        } catch (JRException e) {
            throw new JRRuntimeException("Could not load the following font : " + "\npdfFontName   : "
                    + pdfFont.getPdfFontName() + "\npdfEncoding   : " + pdfFont.getPdfEncoding()
                    + "\nisPdfEmbedded : " + pdfFont.isPdfEmbedded(), initialException);
        }

        BaseFont baseFont = null;

        try {
            baseFont = BaseFont.createFont(pdfFont.getPdfFontName(), pdfFont.getPdfEncoding(),
                    pdfFont.isPdfEmbedded(), true, bytes, null);
        } catch (DocumentException e) {
            throw new JRRuntimeException(e);
        } catch (IOException e) {
            throw new JRRuntimeException(e);
        }

        font = new Font(baseFont, jrFont.getFontSize(),
                ((pdfFont.isPdfSimulatedBold()) ? Font.BOLD : 0)
                        | ((pdfFont.isPdfSimulatedItalic()) ? Font.ITALIC : 0)
                        | (jrFont.isUnderline() ? Font.UNDERLINE : 0)
                        | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0),
                forecolor);
    }

    return font;
}

From source file:org.areasy.common.doclet.document.Fonts.java

License:Open Source License

public static Font getFont(int faceType, int style, int size) {
    Font font = null;//  ww  w  .  j  a  v  a  2 s  .c  o m
    String lookup = String.valueOf(faceType);
    String fontFile = fontTable.getProperty(lookup);

    int fontStyle = Font.NORMAL;
    Color color = COLOR_BLACK;

    if ((style & LINK) != 0) {
        fontStyle += Font.UNDERLINE;
        color = COLOR_LINK;
    } else if ((style & UNDERLINE) != 0)
        fontStyle += Font.UNDERLINE;

    if ((style & STRIKETHROUGH) != 0)
        fontStyle += Font.STRIKETHRU;

    if (fontFile != null) {

        File file = new File(DefaultConfiguration.getWorkDir(), fontFile);
        if (file.exists() && file.isFile()) {

            try {
                String encoding = encTable.getProperty(lookup, BaseFont.CP1252);
                BaseFont bfComic = BaseFont.createFont(file.getAbsolutePath(), encoding, BaseFont.EMBEDDED);

                if ((style & AbstractConfiguration.ITALIC) > 0) {
                    if ((style & AbstractConfiguration.BOLD) > 0)
                        fontStyle += Font.BOLDITALIC;
                    else
                        fontStyle += Font.ITALIC;
                } else if ((style & AbstractConfiguration.BOLD) > 0)
                    fontStyle += Font.BOLD;

                if (fontStyle != Font.NORMAL)
                    font = new Font(bfComic, size, fontStyle, color);
                else
                    font = new Font(bfComic, size);

                if (font == null)
                    throw new IllegalArgumentException("Font null: " + fontFile);
            } catch (Exception e) {
                e.printStackTrace();
                throw new IllegalArgumentException("Font unusable");
            }
        } else
            DocletUtility.error("Font file not found: " + fontFile);
    } else {
        // Use predefined font
        String face = "";

        if (faceType == TEXT_FONT) {
            face = FontFactory.HELVETICA;

            if ((style & AbstractConfiguration.ITALIC) > 0) {
                if ((style & AbstractConfiguration.BOLD) > 0)
                    face = FontFactory.HELVETICA_BOLDOBLIQUE;
                else
                    face = FontFactory.HELVETICA_OBLIQUE;
            } else if ((style & AbstractConfiguration.BOLD) > 0)
                face = FontFactory.HELVETICA_BOLD;
        } else {
            face = FontFactory.COURIER;
            if ((style & ITALIC) > 0) {
                if ((style & BOLD) > 0)
                    face = FontFactory.COURIER_BOLDOBLIQUE;
                else
                    face = FontFactory.COURIER_OBLIQUE;
            } else if ((style & BOLD) > 0)
                face = FontFactory.COURIER_BOLD;
        }

        if (fontStyle != Font.NORMAL)
            font = FontFactory.getFont(face, size, fontStyle, color);
        else
            font = FontFactory.getFont(face, size);
    }

    return font;
}

From source file:org.lucee.extension.pdf.tag.PDF.java

License:Open Source License

private Font toFont(Struct sct) throws PageException {
    Cast caster = engine.getCastUtil();/*ww w  . j a  va 2s.  c o m*/
    Font f = getDefaultFont();
    // size
    float size = caster.toFloatValue(sct.get("size", null), 0);
    if (size > 0)
        f.setSize(size);

    // family
    Set fonts = FontFactory.getRegisteredFonts();
    String family = caster.toString(sct.get("family", null), null);
    if (!Util.isEmpty(family)) {
        String lc = family.toLowerCase();
        if (!fonts.contains(lc)) {
            StringBuilder sb = new StringBuilder();
            Iterator it = fonts.iterator();
            while (it.hasNext()) {
                if (sb.length() > 0)
                    sb.append(", ");
                sb.append(it.next());
            }
            throw engine.getExceptionUtil().createApplicationException(
                    "font family [" + family + "] is not available, available font families are [" + sb + "]");
        }
        f.setFamily(lc);
    }

    int style = 0;
    // bold
    boolean bold = caster.toBooleanValue(sct.get("bold", null), false);
    if (bold)
        style |= Font.BOLD;
    // italic
    boolean italic = caster.toBooleanValue(sct.get("italic", null), false);
    if (italic)
        style |= Font.ITALIC;
    // underline
    boolean underline = caster.toBooleanValue(sct.get("underline", null), false);
    if (underline)
        style |= Font.UNDERLINE;
    // strike
    boolean strike = caster.toBooleanValue(sct.get("strike", null), false);
    if (strike)
        style |= Font.STRIKETHRU;
    if (style != 0)
        f.setStyle(style);

    return f;
}

From source file:org.odftoolkit.odfdom.converter.internal.itext.stylable.StylableParagraph.java

License:Open Source License

@SuppressWarnings("unchecked")
public Element getElement() {
    if (!elementPostProcessed) {
        elementPostProcessed = true;/*from w  ww  .  j a v  a2s . co  m*/

        // add space if this paragraph is empty
        // otherwise it's height will be zero
        boolean empty = true;
        ArrayList<Chunk> chunks = getChunks();
        for (Chunk chunk : chunks) {
            if (chunk.getImage() == null && chunk.getContent() != null && chunk.getContent().length() > 0) {
                empty = false;
                break;
            }
        }
        if (empty) {
            super.add(new Chunk("\u00A0")); // non breaking space
        }

        // adjust line height and baseline
        if (font != null && font.getBaseFont() != null) {
            // iText and open office computes proportional line height differently
            // [iText] line height = coefficient * font size
            // [open office] line height = coefficient * (font ascender + font descender + font extra margin)
            // we have to increase paragraph line height to generate pdf similar to open office document
            // this algorithm may be inaccurate if fonts with different multipliers are used in this paragraph
            float size = font.getSize();
            float ascender = font.getBaseFont().getFontDescriptor(BaseFont.AWT_ASCENT, size);
            float descender = -font.getBaseFont().getFontDescriptor(BaseFont.AWT_DESCENT, size); // negative value
            float margin = font.getBaseFont().getFontDescriptor(BaseFont.AWT_LEADING, size);
            float multiplier = (ascender + descender + margin) / size;
            if (multipliedLeading > 0.0f) {
                setMultipliedLeading(getMultipliedLeading() * multiplier);
            }

            // iText seems to output text with baseline lower than open office
            // we raise all paragraph text by some amount
            // again this may be inaccurate if fonts with different size are used in this paragraph
            float itextdescender = -font.getBaseFont().getFontDescriptor(BaseFont.DESCENT, size); // negative
            float textRise = itextdescender + getTotalLeading() - font.getSize() * multiplier;
            chunks = getChunks();
            for (Chunk chunk : chunks) {
                Font f = chunk.getFont();
                if (f != null) {
                    // have to raise underline and strikethru as well
                    float s = f.getSize();
                    if (f.isUnderlined()) {
                        f.setStyle(f.getStyle() & ~Font.UNDERLINE);
                        chunk.setUnderline(s * 1 / 17, s * -1 / 7 + textRise);
                    }
                    if (f.isStrikethru()) {
                        f.setStyle(f.getStyle() & ~Font.STRIKETHRU);
                        chunk.setUnderline(s * 1 / 17, s * 1 / 4 + textRise);
                    }
                }
                chunk.setTextRise(chunk.getTextRise() + textRise);
            }
        }

        // wrap this paragraph into a table if necessary
        if (wrapperCell != null) {
            // background color or borders were set
            wrapperCell.addElement(this);
            wrapperTable = createTable(wrapperCell);
            if (getIndentationLeft() > 0.0f || getIndentationRight() > 0.0f || getSpacingBefore() > 0.0f
                    || getSpacingAfter() > 0.0f) {
                // margins were set, have to wrap the cell again
                PdfPCell outerCell = createCell();
                outerCell.setPaddingLeft(getIndentationLeft());
                setIndentationLeft(0.0f);
                outerCell.setPaddingRight(getIndentationRight());
                setIndentationRight(0.0f);
                outerCell.setPaddingTop(getSpacingBefore());
                setSpacingBefore(0.0f);
                outerCell.setPaddingBottom(getSpacingAfter());
                setSpacingAfter(0.0f);
                outerCell.addElement(wrapperTable);
                wrapperTable = createTable(outerCell);
            }
        }
    }
    return wrapperTable != null ? wrapperTable : this;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java

License:Open Source License

private int computeStyle(final TypedMapWrapper<Attribute, Object> attributes, final PdfTextSpec pdfTextSpec) {
    final Float weight = attributes.get(TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR, Float.class);
    final Float italics = attributes.get(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE, Float.class);
    final boolean underlined = attributes.exists(TextAttribute.UNDERLINE);
    final boolean strikethrough = attributes.exists(TextAttribute.STRIKETHROUGH);

    FontNativeContext nativeContext = pdfTextSpec.getFontMetrics().getNativeContext();

    int style = 0;
    if (nativeContext.isNativeBold() == false && weight >= TextAttribute.WEIGHT_DEMIBOLD) {
        style |= Font.BOLD;//from w w w.java 2s.  c o  m
    }
    if (nativeContext.isNativeItalics() == false && italics >= TextAttribute.POSTURE_OBLIQUE) {
        style |= Font.ITALIC;
    }
    if (underlined) {
        style |= Font.UNDERLINE;
    }
    if (strikethrough) {
        style |= Font.STRIKETHRU;
    }
    return style;
}