Example usage for com.itextpdf.text FontFactory getFont

List of usage examples for com.itextpdf.text FontFactory getFont

Introduction

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

Prototype


public static Font getFont(final String fontname, final float size, final int style) 

Source Link

Document

Constructs a Font-object.

Usage

From source file:org.h819.commons.file.MyPDFUtils.java

/**
 *  STCAIYUN.TTF?? jar? classpath//from w  w  w.j a va 2  s .  c  om
 * ? pdf ??? pdf ?
 * ??????
 *
 * @return
 * @throws IOException
 */
private static Font getPdfFont() {

    //
    String fontName = "/STCAIYUN.TTF";
    String fontPath = SystemUtils.getJavaIoTmpDir() + File.separator + MyConstants.JarTempDir + File.separator
            + fontName;

    //?????
    if (!Files.exists(Paths.get(fontPath))) {
        MyFileUtils.copyResourceFileFromJarLibToTmpDir(fontName);
    }
    return FontFactory.getFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
}

From source file:org.jaqpot.core.service.data.ReportService.java

public void report2PDF(Report report, OutputStream os) {

    Document document = new Document();
    document.setPageSize(PageSize.A4);/*  w ww  .j a  v a 2s  . com*/
    document.setMargins(50, 45, 80, 40);
    document.setMarginMirroring(false);

    try {
        PdfWriter writer = PdfWriter.getInstance(document, os);
        TableHeader event = new TableHeader();
        writer.setPageEvent(event);

    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    document.open();

    /** setup fonts for pdf */
    Font ffont = new Font(Font.FontFamily.UNDEFINED, 9, Font.ITALIC);
    Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLDITALIC);
    Font paragraphFontBold = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);
    Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL);
    Font tableFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD);

    /** print link to jaqpot*/
    Chunk chunk = new Chunk(
            "This report has been automatically created by the JaqpotQuatro report service. Click here to navigate to our official webpage",
            ffont);
    chunk.setAnchor("http://www.jaqpot.org");

    Paragraph paragraph = new Paragraph(chunk);
    paragraph.add(Chunk.NEWLINE);

    Chapter chapter = new Chapter(paragraph, 1);
    chapter.setNumberDepth(0);

    /** get title */
    String title = null;
    if (report.getMeta() != null && report.getMeta().getTitles() != null
            && !report.getMeta().getTitles().isEmpty())
        title = report.getMeta().getTitles().iterator().next();

    /** print title aligned centered in page */
    if (title == null)
        title = "Report";
    chunk = new Chunk(title, chapterFont);
    paragraph = new Paragraph(chunk);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    paragraph.add(Chunk.NEWLINE);
    paragraph.add(Chunk.NEWLINE);

    chapter.add(paragraph);

    /** report Description */
    if (report.getMeta() != null && report.getMeta().getDescriptions() != null
            && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        paragraph = new Paragraph();
        paragraph.add(new Chunk("Description: ", paragraphFontBold));
        paragraph.add(new Chunk(report.getMeta().getDescriptions().toString().replaceAll(":http", ": http"),
                paragraphFont));
        chapter.add(paragraph);
        chapter.add(Chunk.NEWLINE);
    }

    /** report model, algorithm and/or dataset id */
    if (report.getMeta() != null && report.getMeta().getHasSources() != null
            && !report.getMeta().getHasSources().isEmpty() && !report.getMeta().getDescriptions().isEmpty()
            && !report.getMeta().getDescriptions().toString().equalsIgnoreCase("null")) {
        Iterator<String> sources = report.getMeta().getHasSources().iterator();
        sources.forEachRemaining(o -> {
            if (o != null) {
                String[] source = o.split("/");
                if (source[source.length - 2].trim().equals("model")
                        || source[source.length - 2].trim().equals("algorithm")
                        || source[source.length - 2].trim().equals("dataset")) {
                    Paragraph paragraph1 = new Paragraph();
                    paragraph1.add(new Chunk(source[source.length - 2].substring(0, 1).toUpperCase()
                            + source[source.length - 2].substring(1) + ": ", paragraphFontBold));
                    paragraph1.add(new Chunk(source[source.length - 1], paragraphFont));
                    chapter.add(paragraph1);
                    chapter.add(Chunk.NEWLINE);
                }
            }
        });
    }

    /** report single calculations */
    report.getSingleCalculations().forEach((key, value) -> {
        Paragraph paragraph1 = new Paragraph();
        paragraph1 = new Paragraph();
        paragraph1.add(new Chunk(key + ": ", paragraphFontBold));
        paragraph1.add(new Chunk(value.toString().trim().replaceAll(" +", " "), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    });

    /** report date of completion */
    if (report.getMeta() != null && report.getMeta().getDate() != null) {
        Paragraph paragraph1 = new Paragraph();
        paragraph1.add(new Chunk("Procedure completed on: ", paragraphFontBold));
        paragraph1.add(new Chunk(report.getMeta().getDate().toString(), paragraphFont));
        chapter.add(paragraph1);
        chapter.add(Chunk.NEWLINE);
    }

    try {
        document.add(chapter);
    } catch (DocumentException ex) {
        throw new InternalServerErrorException(ex);
    }

    Integer chapterNumber = 0;

    /** report all_data */
    for (Entry<String, ArrayCalculation> entry : report.getArrayCalculations().entrySet()) {
        String label = entry.getKey();
        ArrayCalculation ac = entry.getValue();
        PdfPTable table = new PdfPTable(ac.getColNames().size() + 1);
        for (Entry<String, List<Object>> row : ac.getValues().entrySet()) {

            try {
                XMLWorkerHelper.getInstance().parseXHtml(w -> {
                    if (w instanceof WritableElement) {
                        List<Element> elements = ((WritableElement) w).elements();
                        for (Element element : elements) {
                            PdfPCell pdfCell = new PdfPCell();
                            pdfCell.addElement(element);
                            table.addCell(pdfCell);
                        }
                    }
                }, new StringReader(row.getKey()));
            } catch (IOException e) {
                e.printStackTrace();
            }

            for (Object o : row.getValue()) {
                table.addCell(o.toString());
            }
            table.completeRow();
        }
        try {
            Chunk tableChunk = new Chunk(label, tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(Chunk.NEWLINE);
            tableChapter.add(table);
            document.newPage();
            document.add(tableChapter);
        } catch (DocumentException ex) {
            throw new InternalServerErrorException(ex);
        }
    }

    /** report plots */
    for (Entry<String, String> entry : report.getFigures().entrySet()) {
        try {
            byte[] valueDecoded = Base64.decodeBase64(entry.getValue());
            Image l = Image.getInstance(valueDecoded);
            document.newPage();
            //image starts at the half's half of pdf page
            l.setAbsolutePosition(0, (document.getPageSize().getHeight() / 2 / 2));
            l.scaleToFit(document.getPageSize());

            Chunk tableChunk = new Chunk(entry.getKey(), tableFont);
            Chapter tableChapter = new Chapter(new Paragraph(tableChunk), ++chapterNumber);
            tableChapter.add(l);
            document.add(tableChapter);
        } catch (IOException | DocumentException e) {
            e.printStackTrace();
        }
    }
    document.close();
}

From source file:org.javad.pdf.fonts.FontRegistry.java

License:Apache License

public Font getFont(PdfFontDefinition name) {
    Font f = null;//from w  ww  .  j a v  a2s .c o m
    initializeFontTable();
    PdfFontBean bean = fontMap.get(name);
    if (bean == null) {
        throw new IllegalArgumentException(
                "The name \"" + name.toString() + "\" was not found in the mapping.");
    }
    if (calculatedFonts.containsKey(bean)) {
        return calculatedFonts.get(bean);
    }
    if (bean.isSystem()) {
        initializeFonts();
        f = findFont(bean.getFontFamily(), bean);
    } else if (bean.getFontMapping() != null) {
        logger.log(Level.FINE, "Using a mapped font for \"{0}\"", name);
        PdfFontMapping mapping = bean.getFontMapping();
        FontFactory.register(mapping.getFilePath(), mapping.getFontAlias());
        f = findFont(mapping.getFontAlias(), bean);
    }
    if (isFontInvalid(f)) {
        logger.log(Level.INFO, "Unable to find a registered font for \"{0}\" using default of Helvetica", name);
        f = FontFactory.getFont(FontFactory.HELVETICA, name.getDefaultSize(), name.getDefaultStyle());
    }
    calculatedFonts.put(bean, f);
    return f;
}

From source file:org.primaresearch.pdf.PageToPdfConverter.java

License:Apache License

/**
 * Creates the font that is to be used for the hidden text layer in the PDF.
 *///from ww w  .  j av a 2 s  . c om
private void createFont() throws DocumentException, IOException {

    //TODO Even with the 'NOT_EMBEDDED' settings it seems to embed the font!

    if (ttfFontFilePath == null)
        font = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    else {
        font = FontFactory.getFont(ttfFontFilePath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED).getBaseFont();
        //PDTrueTypeFont.loadTTF(document, ttfFontFilePath);
        //Encoding enc = font.getFontEncoding();
        //Map<Integer, String> map = enc.getCodeToNameMap();
        //System.out.println("Font encoding map size: " + map.size());
    }
}

From source file:org.sistemafinanciero.rest.impl.CuentaBancariaRESTService.java

License:Apache License

@Override
public Response getCertificado(BigInteger id) {
    OutputStream file;/*from  ww w .ja  v  a 2 s  .  c  om*/

    CuentaBancariaView cuentaBancaria = cuentaBancariaServiceNT.findById(id);
    String codigoAgencia = ProduceObject.getCodigoAgenciaFromNumeroCuenta(cuentaBancaria.getNumeroCuenta());

    Agencia agencia = agenciaServiceNT.findByCodigo(codigoAgencia);

    if (agencia == null) {
        JsonObject model = Json.createObjectBuilder().add("message", "Agencia no encontrado").build();
        return Response.status(Response.Status.NOT_FOUND).entity(model).build();
    }

    try {
        file = new FileOutputStream(new File(certificadoURL + "\\" + id + ".pdf"));
        //Document document = new Document(PageSize.A5.rotate());
        Document document = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();

        //recuperando moneda, redondeando y dando formato
        Moneda moneda = monedaServiceNT.findById(cuentaBancaria.getIdMoneda());
        BigDecimal saldo = cuentaBancaria.getSaldo();
        BigDecimal decimalValue = saldo.subtract(saldo.setScale(0, RoundingMode.FLOOR))
                .movePointRight(saldo.scale());
        Long integerValue = saldo.longValue();

        String decimalString = decimalValue.toString();
        if (decimalString.length() < 2)
            decimalString = "0" + decimalString;

        NumberFormat df1 = NumberFormat.getCurrencyInstance();
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        dfs.setCurrencySymbol("");
        dfs.setGroupingSeparator(',');
        dfs.setMonetaryDecimalSeparator('.');
        ((DecimalFormat) df1).setDecimalFormatSymbols(dfs);

        //recuperando el plazo en dias
        Date fechaApertura = cuentaBancaria.getFechaApertura();
        Date fechaCierre = cuentaBancaria.getFechaCierre();
        LocalDate localDateApertura = new LocalDate(fechaApertura);
        LocalDate localDateCierre = new LocalDate(fechaCierre);
        Days days = Days.daysBetween(localDateApertura, localDateCierre);

        //fuentes
        Font fontTitulo = FontFactory.getFont("Times New Roman", 14, Font.BOLD);
        Font fontSubTitulo = FontFactory.getFont("Times New Roman", 8);
        Font fontContenidoNegrita = FontFactory.getFont("Times New Roman", 10, Font.BOLD);
        Font fontContenidoNormal = FontFactory.getFont("Times New Roman", 10);

        //dando formato a las fechas
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        String fechaAperturaString = df.format(cuentaBancaria.getFechaApertura());
        String fechaVencimientoString = df.format(cuentaBancaria.getFechaCierre());

        //ingresando datos al documento
        document.add(new Paragraph("\n"));
        document.add(new Paragraph("\n"));

        //parrafo titulo
        Paragraph parrafoTitulo = new Paragraph();
        parrafoTitulo.setFont(fontTitulo);
        parrafoTitulo.setSpacingBefore(30);
        parrafoTitulo.setAlignment(Element.ALIGN_CENTER);

        //parrafo subtitulo
        Paragraph parrafoSubTitulo = new Paragraph();
        parrafoSubTitulo.setFont(fontSubTitulo);
        parrafoSubTitulo.setSpacingAfter(30);
        parrafoSubTitulo.setAlignment(Element.ALIGN_CENTER);

        //parrafo contenido
        Paragraph parrafoContenido = new Paragraph();
        parrafoContenido.setIndentationLeft(50);
        parrafoContenido.setAlignment(Element.ALIGN_LEFT);

        //parrafo firmas
        Paragraph parrafoFirmas = new Paragraph();
        parrafoFirmas.setAlignment(Element.ALIGN_CENTER);

        //agregar titulo al documento
        Chunk titulo = new Chunk("CERTIFICADO DE PLAZO FIJO");
        parrafoTitulo.add(titulo);

        //agregar titulo al documento
        Chunk subTitulo;
        if (cuentaBancaria.getIdMoneda().compareTo(BigInteger.ZERO) == 0) {
            subTitulo = new Chunk("DEPSITO A PLAZO FIJO - DOLARES AMERICANOS");
        } else if (cuentaBancaria.getIdMoneda().compareTo(BigInteger.ONE) == 0) {
            subTitulo = new Chunk("DEPSITO A PLAZO FIJO - NUEVOS SOLES");
        } else {
            subTitulo = new Chunk("DEPSITO A PLAZO FIJO - EUROS");
        }
        parrafoSubTitulo.add(subTitulo);

        //agregando contenido al documento
        //Agencia
        Chunk agencia1 = new Chunk("AGENCIA", fontContenidoNegrita);
        Chunk agencia2 = new Chunk(": " + agencia.getCodigo() + " - " + agencia.getDenominacion().toUpperCase(),
                fontContenidoNormal);
        parrafoContenido.add(agencia1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(agencia2);
        parrafoContenido.add("\n");

        //cuenta
        Chunk numeroCuenta1 = new Chunk("N CUENTA", fontContenidoNegrita);
        Chunk numeroCuenta2 = new Chunk(": " + cuentaBancaria.getNumeroCuenta(), fontContenidoNormal);
        parrafoContenido.add(numeroCuenta1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(numeroCuenta2);
        parrafoContenido.add("\n");

        //codigo cliente
        Chunk codigoSocio1 = new Chunk("CODIGO CLIENTE", fontContenidoNegrita);
        Chunk codigoSocio2 = new Chunk(": " + cuentaBancaria.getIdSocio().toString(), fontContenidoNormal);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(codigoSocio1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(codigoSocio2);
        parrafoContenido.add("\n");

        //cliente
        Chunk socio1 = new Chunk("CLIENTE", fontContenidoNegrita);
        Chunk socio2 = new Chunk(": " + cuentaBancaria.getSocio(), fontContenidoNormal);
        parrafoContenido.add(socio1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(socio2);
        parrafoContenido.add("\n");

        //tipo cuenta
        Chunk tipoCuenta1 = new Chunk("TIPO CUENTA", fontContenidoNegrita);
        Chunk tipoCuenta2 = new Chunk(": " + "INDIVIDUAL", fontContenidoNormal);
        parrafoContenido.add(tipoCuenta1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(tipoCuenta2);
        parrafoContenido.add("\n");

        //tipo moneda
        Chunk tipoMoneda1 = new Chunk("TIPO MONEDA", fontContenidoNegrita);
        Chunk tipoMoneda2;
        if (cuentaBancaria.getIdMoneda().compareTo(BigInteger.ZERO) == 0) {
            tipoMoneda2 = new Chunk(": " + "DOLARES AMERICANOS", fontContenidoNormal);
        } else if (cuentaBancaria.getIdMoneda().compareTo(BigInteger.ONE) == 0) {
            tipoMoneda2 = new Chunk(": " + "NUEVOS SOLES", fontContenidoNormal);
        } else {
            tipoMoneda2 = new Chunk(": " + "EUROS", fontContenidoNormal);
        }
        parrafoContenido.add(tipoMoneda1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(tipoMoneda2);
        parrafoContenido.add("\n");

        //Monto
        Chunk monto1 = new Chunk("MONTO", fontContenidoNegrita);
        Chunk monto2 = new Chunk(": " + moneda.getSimbolo() + df1.format(saldo) + " - "
                + NumLetrasJ.Convierte(integerValue.toString() + "", Tipo.Pronombre).toUpperCase() + " Y "
                + decimalString + "/100 " + moneda.getDenominacion(), fontContenidoNormal);
        parrafoContenido.add(monto1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(monto2);
        parrafoContenido.add("\n");

        //Plazo
        Chunk plazo1 = new Chunk("PLAZO", fontContenidoNegrita);
        Chunk plazo2 = new Chunk(": " + days.getDays() + " D?AS", fontContenidoNormal);
        parrafoContenido.add(plazo1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(plazo2);
        parrafoContenido.add("\n");

        //Fecha Apertura
        Chunk fechaApertura1 = new Chunk("FEC. APERTURA", fontContenidoNegrita);
        Chunk fechaApertura2 = new Chunk(": " + fechaAperturaString, fontContenidoNormal);
        parrafoContenido.add(fechaApertura1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(fechaApertura2);
        parrafoContenido.add("\n");

        //Fecha Vencimiento
        Chunk fechaVencimiento1 = new Chunk("FEC. VENCIMIENTO", fontContenidoNegrita);
        Chunk fechaVencimiento2 = new Chunk(": " + fechaVencimientoString, fontContenidoNormal);
        parrafoContenido.add(fechaVencimiento1);
        parrafoContenido.add(Chunk.SPACETABBING);
        parrafoContenido.add(fechaVencimiento2);
        parrafoContenido.add("\n");

        //tasa efectiva anual
        Chunk tasaEfectivaAnual1 = new Chunk("TASA EFECTIVA ANUAL", fontContenidoNegrita);
        Chunk tasaEfectivaAnual2 = new Chunk(
                ": " + cuentaBancaria.getTasaInteres().multiply(new BigDecimal(100)).toString() + "%",
                fontContenidoNormal);
        parrafoContenido.add(tasaEfectivaAnual1);
        parrafoContenido.add(tasaEfectivaAnual2);
        parrafoContenido.add("\n");

        //frecuencia de capitalizacion
        Chunk frecuenciaCapitalizacion1 = new Chunk("FREC. CAPITALIZACION", fontContenidoNegrita);
        Chunk frecuenciaCapitalizacion2 = new Chunk(": " + "DIARIA", fontContenidoNormal);
        parrafoContenido.add(frecuenciaCapitalizacion1);
        parrafoContenido.add(frecuenciaCapitalizacion2);
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");

        //importante
        Chunk importante = new Chunk("IMPORTANTE: ", fontContenidoNegrita);
        Chunk importanteDetalle1 = new Chunk(
                "DEPSITO CUBIERTO POR EL FONDO DE SEGURO DE DEPOSITOS ESTABLECIDO POR EL BANCO CENTRAL DE RESERVA DEL PER HASTA S/.82,073.00.",
                fontSubTitulo);
        Chunk importanteDetalle2 = new Chunk(
                "LAS PERSONAS JUR?DICAS SIN FINES DE LUCRO SON CUBIERTAS POR EL FONDO DE SEGURO DE DEPSITOS.",
                fontSubTitulo);
        parrafoContenido.add(importante);
        parrafoContenido.add(importanteDetalle1);
        parrafoContenido.add("\n");
        parrafoContenido.add(importanteDetalle2);
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");

        //certificado intranferible
        Chunk certificadoIntransferible = new Chunk("CERTIFICADO INTRANSFERIBLE.", fontContenidoNegrita);
        parrafoContenido.add(certificadoIntransferible);
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");
        parrafoContenido.add("\n");

        //Firmas
        Chunk subGion = new Chunk("___________________", fontContenidoNormal);
        Chunk firmaCajero = new Chunk("CAJERO", fontContenidoNormal);
        Chunk firmaCliente = new Chunk("CLIENTE", fontContenidoNormal);

        parrafoFirmas.add(subGion);
        parrafoFirmas.add(Chunk.SPACETABBING);
        parrafoFirmas.add(Chunk.SPACETABBING);
        parrafoFirmas.add(subGion);
        parrafoFirmas.add("\n");
        parrafoFirmas.add(firmaCajero);
        parrafoFirmas.add(Chunk.SPACETABBING);
        parrafoFirmas.add(Chunk.SPACETABBING);
        parrafoFirmas.add(Chunk.SPACETABBING);
        parrafoFirmas.add(firmaCliente);

        //agregando los parrafos al documento
        document.add(parrafoTitulo);
        document.add(parrafoSubTitulo);
        document.add(parrafoContenido);
        document.add(parrafoFirmas);
        document.close();
        file.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    PdfReader reader;
    try {
        reader = new PdfReader(certificadoURL + "\\" + id + ".pdf");
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        PdfStamper pdfStamper = new PdfStamper(reader, out);
        AcroFields acroFields = pdfStamper.getAcroFields();
        acroFields.setField("field_title", "test");
        pdfStamper.close();
        reader.close();
        return Response.ok(out.toByteArray()).type("application/pdf").build();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(Jsend.getErrorJSend("No encontrado"))
            .build();
}

From source file:PDF.CrearPDF_Ficha.java

public void generarPDF(ServletOutputStream sops, DatosPDF datos, String url) {

    try {/*from  w  w  w  . j a va 2  s.  c o  m*/

        Document documento = new Document();
        //            ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(documento, sops);
        documento.open();

        Image itt_logo;
        try {
            itt_logo = Image.getInstance(url);
            Image Logo_itt = Image.getInstance(itt_logo);
            Logo_itt.setAbsolutePosition(50f, 698f);
            Logo_itt.scaleAbsolute(90, 100);
            documento.add(Logo_itt);
        } catch (BadElementException | IOException ex) {
            Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex);
        }

        PdfContentByte rectangulo_info = writer.getDirectContentUnder();
        drawRectangle(rectangulo_info, 430, 648, 90, 100);
        Paragraph leyendaFoto = new Paragraph("\nFOTO:\n", FontFactory.getFont("arial", 14, Font.BOLD));
        leyendaFoto.setIndentationLeft(200f);
        Paragraph titulo = new Paragraph("INSTITUTO TECNOLGICO DE TOLUCA", FontFactory.getFont("arial", 14));
        titulo.setAlignment(Element.ALIGN_CENTER);

        Paragraph asunto = new Paragraph("FICHA DE EXAMEN", FontFactory.getFont("arial", 12));
        asunto.setAlignment(Element.ALIGN_CENTER);

        Chunk folio1 = new Chunk("FICHA PARA EL EXAMEN DE ADMISIN: ", FontFactory.getFont("arial", 10));
        Chunk folio2 = new Chunk(datos.getFicha(), FontFactory.getFont("arial", 10, Font.BOLD));

        Phrase fol = new Phrase();
        fol.add(folio1);
        fol.add(folio2);

        Paragraph noFicha = new Paragraph(fol);
        noFicha.setAlignment(Element.ALIGN_LEFT);

        Chunk nombre1 = new Chunk("NOMBRE DEL SOLICITANTE: ", FontFactory.getFont("arial", 10));
        Chunk nombre2 = new Chunk(datos.getNombre(), FontFactory.getFont("arial", 10, Font.BOLD));

        Phrase nom = new Phrase();
        nom.add(nombre1);
        nom.add(nombre2);

        Paragraph nombre = new Paragraph(nom);
        nombre.setAlignment(Element.ALIGN_LEFT);

        Chunk in1 = new Chunk("PROCESO PARA EL REGISTRO DE ASPIRANTES EN EL PERIODO: ",
                FontFactory.getFont("arial", 10));
        Chunk in2 = new Chunk(datos.getPeriodoConcursa().toUpperCase(),
                FontFactory.getFont("arial", 10, Font.BOLD));

        Phrase in = new Phrase();
        in.add(in1);
        in.add(in2);

        Paragraph instrucciones = new Paragraph(in);
        instrucciones.setAlignment(Element.ALIGN_LEFT);

        Chunk folCen1 = new Chunk("1.- NMERO DE FOLIO CENEVAL: ", FontFactory.getFont("arial", 10));
        Chunk folCen2 = new Chunk(datos.getFolioCENEVAL(), FontFactory.getFont("arial", 10, Font.BOLD));

        Phrase folC = new Phrase();
        folC.add(folCen1);
        folC.add(folCen2);

        Paragraph folioCENEVAL = new Paragraph(folC);
        folioCENEVAL.setAlignment(Element.ALIGN_LEFT);

        Chunk fechas1 = new Chunk("2.- LOS EX?MENES DE ADMISIN SE APLICAR?N LOS D?AS: ",
                FontFactory.getFont("arial", 10));
        Chunk fechas2 = new Chunk(datos.getFechaExamenCeneval() + " (" + datos.getLugarExamenCeneval() + ")",
                FontFactory.getFont("arial", 10, Font.BOLD));
        Chunk fechas3 = new Chunk(" Y ", FontFactory.getFont("arial", 10));
        Chunk fechas4 = new Chunk(datos.getFechaExamenMate() + " (" + datos.getLugarExamenMate() + ")",
                FontFactory.getFont("arial", 10, Font.BOLD));

        Phrase fechas = new Phrase();
        fechas.add(fechas1);
        fechas.add(fechas2);
        fechas.add(fechas3);
        fechas.add(fechas4);

        Paragraph fechaExamenes = new Paragraph(fechas);
        fechaExamenes.setAlignment(Element.ALIGN_LEFT);

        Phrase lugar = new Phrase();

        Paragraph lugarYhora = new Paragraph(lugar);
        lugarYhora.setAlignment(Element.ALIGN_LEFT);

        Chunk paginaPub1 = new Chunk(
                "3.- LA PUBLICACIN DE LOS RESULTADOS SER? NICAMENTE EN LA P?GINA WEB: ",
                FontFactory.getFont("arial", 10));

        Anchor url_itt = new Anchor(datos.getPagResultados());
        url_itt.setReference(datos.getPagResultados());

        Phrase pag = new Phrase();
        pag.add(paginaPub1);
        pag.add(url_itt);

        Paragraph pagWeb = new Paragraph(pag);

        Chunk diaPub1 = new Chunk("EL D?A: ", FontFactory.getFont("arial", 10));
        Chunk diaPub2 = new Chunk(convertir(datos.getDiaPublicacion() + "-"),
                FontFactory.getFont("arial", 10, Font.BOLD));

        Phrase dia = new Phrase();
        dia.add(diaPub1);
        dia.add(diaPub2);

        Paragraph diaResultados = new Paragraph(dia);
        diaResultados.setAlignment(Element.ALIGN_LEFT);

        Chunk notas = new Chunk("\nNOTAS:\n", FontFactory.getFont("arial", 14, Font.BOLD));

        Chunk uno = new Chunk("1.- ", FontFactory.getFont("arial", 10, Font.BOLD));

        Chunk guias = new Chunk("Guas de estudio:\n   - (CENEVAL) \n", FontFactory.getFont("arial", 10));

        Anchor url_guia_cen = new Anchor("     " + datos.getEstudioCeneval());
        // url_guia_cen.setReference(datos.getEstudioCeneval());

        Chunk ceneval_inter = new Chunk("\n   - (CENEVAL INTERACTIVA) \n", FontFactory.getFont("arial", 10));

        Anchor url_guia_cen_inter = new Anchor("     " + datos.getEstudioCenevalInt());
        url_guia_cen_inter.setReference(datos.getEstudioCenevalInt());

        Chunk tem_mate_itt = new Chunk("\n   - Temario de Matemticas (TECNOLGICO DE TOLUCA)\n\n",
                FontFactory.getFont("arial", 10));
        Chunk dos = new Chunk("2.- ", FontFactory.getFont("arial", 10, Font.BOLD));
        Chunk veri = new Chunk("Verifique que el nmero de folio de Ceneval de esta ficha, coincida con el",
                FontFactory.getFont("arial", 10));
        Chunk fol_ceneval = new Chunk(" FOLIO CENEVAL ", FontFactory.getFont("arial", 10, Font.BOLD));
        Chunk capturado = new Chunk("capturado en la informacin proporcionada por el Tecnlogico.\n\n",
                FontFactory.getFont("arial", 10));
        Chunk tres = new Chunk("3.- ", FontFactory.getFont("arial", 10, Font.BOLD));
        Chunk dia_exam = new Chunk(
                "El da del examen deber presentarse con el presente documento, pase de ingreso al examen(Ceneval), una identificacin con fotografa reciente(credencial escolar, IMSS, ISSSTE, ISSEMYM, licencia, pasaporte), lpiz del nmero 2 y goma.\n\n",
                FontFactory.getFont("arial", 10));
        Chunk cuatro = new Chunk("4.- ", FontFactory.getFont("arial", 10, Font.BOLD));
        Chunk curso = new Chunk(
                "Si curs sus estudios de secundaria o bachillerato en el extranjero deber presentar revalidacin de estudios correspondientes al momento de la inscripcin.\n",
                FontFactory.getFont("arial", 10));
        Chunk cinco = new Chunk("\n5.- ", FontFactory.getFont("arial", 10, Font.BOLD));
        Chunk examenes = new Chunk(
                "Los exmenes que se evaluarn son:       1) ADMISIN Y DIAGNSTICO.     2) MATEM?TICAS.",
                FontFactory.getFont("arial", 10));

        Phrase ulti = new Phrase();
        ulti.add(notas);
        ulti.add(uno);
        ulti.add(guias);
        ulti.add(url_guia_cen);
        ulti.add(ceneval_inter);
        ulti.add(url_guia_cen_inter);
        ulti.add(tem_mate_itt);
        ulti.add(dos);
        ulti.add(veri);
        ulti.add(fol_ceneval);
        ulti.add(capturado);
        ulti.add(tres);
        ulti.add(dia_exam);
        ulti.add(cuatro);
        ulti.add(curso);
        ulti.add(cinco);
        ulti.add(examenes);

        Paragraph ultimo = new Paragraph(ulti);
        ultimo.setAlignment(Element.ALIGN_LEFT);

        documento.addTitle("Ficha de Examen");
        documento.addSubject("Instituto Tecnolgico de Toluca");
        documento.addKeywords("Instituto Tecnolgico de Toluca");
        documento.addAuthor("Departamento de Servicios escolares");
        documento.addCreator("Departamento de Servicios escolares");
        documento.add(titulo);
        documento.add(asunto);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));

        documento.add(noFicha);
        documento.add(nombre);
        documento.add(new Paragraph(" "));
        documento.add(instrucciones);
        documento.add(new Paragraph(" "));
        documento.add(folioCENEVAL);
        documento.add(fechaExamenes);
        documento.add(lugarYhora);
        documento.add(pagWeb);
        documento.add(diaResultados);
        documento.add(new Paragraph(" "));
        documento.add(ultimo);

        documento.close();
    } catch (DocumentException ex) {
        Logger.getLogger(CrearPDF_Ficha.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:PDF.Reportes.java

public static ArrayList<PdfPTable> tablaAspAula(String usuario, String contra, String horario, int opc)
        throws DocumentException {
    ArrayList<PdfPTable> tablas = new ArrayList();
    //        IngresoAbd bd = new IngresoAbd(usuario, contra);
    List<Beans.Reportes> reportes = ReportesDAO.AspPAula(usuario, contra, horario, opc);
    PdfPTable table = new PdfPTable(2);
    //        reportes = bd.AspPAula(horario, opc);
    PdfPCell cell;/*  w  w  w .  ja  v a 2 s.co m*/
    String carrera = "", fecha = "";
    if (reportes.isEmpty()) {

        cell = new PdfPCell(
                new Phrase("Lo sentimos, por el momento an no existe informacin para este reporte."));
        cell.setColspan(5);
        table.addCell(cell);
        tablas.add(table);

    } else if (reportes.get(0).getCodError() != 0) {

        if (reportes.get(0).getCodError() == -1) {
            cell = new PdfPCell(new Phrase(Constants.ERROR1));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -2) {
            cell = new PdfPCell(new Phrase(Constants.ERROR3));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -3) {
            cell = new PdfPCell(new Phrase(Constants.ERROR2));
            cell.setColspan(5);
            table.addCell(cell);
        }
        tablas.add(table);
    } else {
        table = new PdfPTable(5);
        BaseColor color = new BaseColor(217, 217, 217);
        BaseColor colorB = new BaseColor(0, 0, 0);
        cell = new PdfPCell(new Phrase("Ficha(5)", FontFactory.getFont("arial", 12, colorB)));
        cell.setMinimumHeight(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);

        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Folio Ceneval(6)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Nombre(7)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        //            cell = new PdfPCell(new Phrase("Nombre carrera", FontFactory.getFont("arial", 12, colorB)));
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //             cell.setBackgroundColor(color);
        //             cell.setBorderColor(colorB);
        //            table.addCell(cell);
        cell = new PdfPCell(new Phrase("Asistencia(8)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        cell.setColspan(2);
        table.addCell(cell);
        //            cell = new PdfPCell(new Phrase("Firma", FontFactory.getFont("arial", 12, colorB)));
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //             cell.setBackgroundColor(color);
        //             cell.setBorderColor(colorB);
        //            table.addCell(cell);

        for (int i = 0; i < reportes.size(); i++) {

            cell = new PdfPCell(new Phrase(reportes.get(i).getFicha()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getFolio()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getNombre(), FontFactory.getFont("arial", 10)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);

            carrera = reportes.get(i).getNom_carrera();
            //               
            cell = new PdfPCell(new Phrase(reportes.get(i).getAsist()));
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getFirma()));
            table.addCell(cell);
            fecha = reportes.get(i).getFecha();
            if ((i % 34 == 0 || (i + 1) == reportes.size()) && i != 0) {

                table.setWidthPercentage(110);
                table.setWidths(new int[] { 25, 30, 120, 15, 15 });
                tablas.add(table);
                table = new PdfPTable(5);
            }
        }
        String datos[] = horario.split(" ");
        String edificio = datos[0];
        String aula = "";
        if (edificio.length() == 2) {
            edificio = datos[0].charAt(0) + "";
            aula = datos[0].charAt(1) + "";
        }
        if (edificio.length() == 4) {

            edificio = datos[0].charAt(0) + "" + datos[0].charAt(1);
            aula = "" + datos[0].charAt(3);
        }
        if (edificio.length() == 5) {

            edificio = datos[0].charAt(0) + "" + datos[0].charAt(1);
            aula = "" + datos[0].charAt(3) + datos[0].charAt(4);
        }
        PdfPTable tableH = new PdfPTable(7);
        tableH.setTotalWidth(500);
        cell.setMinimumHeight(20);
        cell = new PdfPCell(new Phrase("CARRERA:(1)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(carrera));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(5);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("FECHA DE EXAMEN:(2)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(fecha));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("EDIFICIO:(3)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(edificio));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("AULA:(4)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(aula));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);

        tablas.add(tableH);
    }

    return tablas;
}

From source file:PDF.Reportes.java

public static ArrayList<PdfPTable> firmasAspAula(String usuario, String contra, String horario, int opc)
        throws DocumentException {
    ArrayList<PdfPTable> tablas = new ArrayList();
    //        IngresoAbd bd = new IngresoAbd(usuario, contra);
    List<Beans.Reportes> reportes;
    PdfPTable table = new PdfPTable(2);
    reportes = ReportesDAO.AspPAula(usuario, contra, horario, opc);
    //        reportes = bd.AspPAula(horario, opc);
    String carrera = "", fecha = "";
    if (reportes.isEmpty()) {
        PdfPCell cell;/*  w  w w.j  ava 2s  .co  m*/
        cell = new PdfPCell(
                new Phrase("Lo sentimos, por el momento an no existe informacin para este reporte."));
        cell.setColspan(5);
        table.addCell(cell);
        tablas.add(table);
    } else if (reportes.get(0).getCodError() != 0) {
        PdfPCell cell;
        if (reportes.get(0).getCodError() == -1) {
            cell = new PdfPCell(new Phrase(Constants.ERROR1));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -2) {
            cell = new PdfPCell(new Phrase(Constants.ERROR3));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -3) {
            cell = new PdfPCell(new Phrase(Constants.ERROR2));
            cell.setColspan(5);
            table.addCell(cell);
        }
        tablas.add(table);
    } else {
        PdfPCell cell;
        table = new PdfPTable(6);
        BaseColor color = new BaseColor(217, 217, 217);
        BaseColor colorB = new BaseColor(0, 0, 0);
        cell = new PdfPCell(new Phrase("Ficha(5)", FontFactory.getFont("arial", 12, colorB)));
        cell.setMinimumHeight(10);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);

        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Folio Ceneval(6)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase("Nombre(7)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        //            cell = new PdfPCell(new Phrase("Nombre carrera", FontFactory.getFont("arial", 12, colorB)));
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //             cell.setBackgroundColor(color);
        //             cell.setBorderColor(colorB);
        //            table.addCell(cell);
        cell = new PdfPCell(new Phrase("Asistencia(8)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        cell.setColspan(2);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Firma(9)", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        table.addCell(cell);

        for (int i = 0; i < reportes.size(); i++) {
            cell = new PdfPCell(new Phrase(reportes.get(i).getFicha()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getFolio()));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getNombre(), FontFactory.getFont("arial", 10)));
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(cell);

            carrera = reportes.get(i).getNom_carrera();
            //               
            cell = new PdfPCell(new Phrase(reportes.get(i).getAsist()));
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reportes.get(i).getFirma()));
            table.addCell(cell);

            table.addCell(cell);
            fecha = reportes.get(i).getFecha();

            if ((i % 34 == 0 || (i + 1) == reportes.size()) && i != 0) {

                table.setWidthPercentage(110);
                table.setWidths(new int[] { 25, 30, 90, 15, 15, 30 });
                tablas.add(table);
                table = new PdfPTable(6);
            }
        }
        String datos[] = horario.split(" ");
        String edificio = datos[0];
        String aula = "";
        if (edificio.length() == 2) {
            edificio = datos[0].charAt(0) + "";
            aula = datos[0].charAt(1) + "";
        }
        if (edificio.length() == 4) {

            edificio = datos[0].charAt(0) + "" + datos[0].charAt(1);
            aula = "" + datos[0].charAt(3);
        }
        if (edificio.length() == 5) {

            edificio = datos[0].charAt(0) + "" + datos[0].charAt(1);
            aula = "" + datos[0].charAt(3) + datos[0].charAt(4);
        }
        PdfPTable tableH = new PdfPTable(7);
        tableH.setTotalWidth(500);
        cell.setMinimumHeight(20);
        cell = new PdfPCell(new Phrase("CARRERA:(1)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(carrera));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(5);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("FECHA DE EXAMEN:(2)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(fecha));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("EDIFICIO:(3)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(edificio));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase("AULA:(4)", FontFactory.getFont("arial", 11)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);
        cell = new PdfPCell(new Phrase(aula));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        tableH.addCell(cell);

        tablas.add(tableH);

    }

    return tablas;
}

From source file:PDF.Reportes.java

public static PdfPTable noaltaCen(String usuario, String contra) throws DocumentException {
    PdfPTable table = new PdfPTable(5);
    //        IngresoAbd bd = new IngresoAbd(usuario, contra);
    List<Beans.Reportes> reportes;
    reportes = ReportesDAO.noAltaCen(usuario, contra);
    //        reportes = bd.noAltaCen();
    if (reportes.isEmpty()) {
        PdfPCell cell;/*from   w w  w. ja  va  2s. co m*/
        cell = new PdfPCell(
                new Phrase("Lo sentimos, por el momento an no existe informacin para este reporte."));
        cell.setColspan(5);
        table.addCell(cell);
    } else if (reportes.get(0).getCodError() != 0) {
        PdfPCell cell;
        if (reportes.get(0).getCodError() == -1) {
            cell = new PdfPCell(new Phrase(Constants.ERROR1));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -2) {
            cell = new PdfPCell(new Phrase(Constants.ERROR3));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -3) {
            cell = new PdfPCell(new Phrase(Constants.ERROR2));
            cell.setColspan(5);
            table.addCell(cell);
        }
        //            cell = new PdfPCell(new Phrase(reportes.get(0).getMsjError()));
    } else {
        BaseColor color = new BaseColor(69, 161, 240);
        BaseColor colorB = new BaseColor(255, 255, 255);
        PdfPCell cell;
        cell = new PdfPCell(new Phrase("Preficha", FontFactory.getFont("arial", 12, colorB)));
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Ref. Bancaria", FontFactory.getFont("arial", 12, colorB)));
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Correo", FontFactory.getFont("arial", 12, colorB)));
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Usuario", FontFactory.getFont("arial", 12, colorB)));
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("ltima Act.", FontFactory.getFont("arial", 12, colorB)));
        cell.setBackgroundColor(color);
        cell.setBorderColor(colorB);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);

        for (Beans.Reportes reporte : reportes) {
            cell = new PdfPCell(new Phrase(reporte.getPreficha()));
            cell.setBorderColor(color);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reporte.getReferencia()));
            cell.setBorderColor(color);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reporte.getCorreo()));
            cell.setBorderColor(color);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reporte.getUsuario()));
            cell.setBorderColor(color);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reporte.getUl_act().substring(0, 10)));
            cell.setBorderColor(color);
            table.addCell(cell);

        }

        table.setWidthPercentage(110);
        table.setWidths(new int[] { 50, 55, 100, 56, 56 });
    }

    return table;
}

From source file:PDF.Reportes.java

public static PdfPTable procesoCon(String usuario, String contra) throws DocumentException {

    //        IngresoAbd bd = new IngresoAbd(usuario, contra);
    List<Beans.Reportes> reportes;
    reportes = ReportesDAO.procesoCon(usuario, contra);
    //        reportes = bd.procesoCon();
    PdfPTable table = new PdfPTable(2);

    if (reportes.isEmpty()) {
        PdfPCell cell;//from w  ww . ja  va 2 s  . c om
        cell = new PdfPCell(
                new Phrase("Lo sentimos, por el momento an no existe informacin para este reporte."));
        cell.setColspan(5);
        table.addCell(cell);
    } else if (reportes.get(0).getCodError() != 0) {
        PdfPCell cell;
        if (reportes.get(0).getCodError() == -1) {
            cell = new PdfPCell(new Phrase(Constants.ERROR1));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -2) {
            cell = new PdfPCell(new Phrase(Constants.ERROR3));
            cell.setColspan(5);
            table.addCell(cell);
        }
        if (reportes.get(0).getCodError() == -3) {
            cell = new PdfPCell(new Phrase(Constants.ERROR2));
            cell.setColspan(5);
            table.addCell(cell);
        }
        //            cell = new PdfPCell(new Phrase(reportes.get(0).getMsjError()));
    } else {
        BaseColor color = new BaseColor(69, 161, 240);
        BaseColor colorB = new BaseColor(255, 255, 255);
        PdfPCell cell;
        cell = new PdfPCell(new Phrase("Carrera", FontFactory.getFont("arial", 12, colorB)));

        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderColor(colorB);
        cell.setBackgroundColor(color);
        table.addCell(cell);
        cell = new PdfPCell(
                new Phrase("No. de pre procesos concluidos", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderColor(colorB);

        cell.setBackgroundColor(color);
        table.addCell(cell);
        int total = 0;
        for (Beans.Reportes reporte : reportes) {

            cell = new PdfPCell(new Phrase(reporte.getNombre(), FontFactory.getFont("arial", 8)));

            cell.setBorderColor(color);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(reporte.getPreproc()));

            cell.setBorderColor(color);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            total = total + Integer.parseInt(reporte.getPreproc());
            table.addCell(cell);
        }

        cell = new PdfPCell(new Phrase("Total", FontFactory.getFont("arial", 12, colorB)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBorderColor(colorB);
        cell.setBackgroundColor(color);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(Integer.toString(total), FontFactory.getFont("arial", 12)));
        cell.setBorderColor(color);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        table.setWidthPercentage(110);

    }

    return table;
}