Example usage for com.lowagie.text Font HELVETICA

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

Introduction

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

Prototype

int HELVETICA

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

Click Source Link

Document

a possible value of a font family.

Usage

From source file:is.idega.idegaweb.egov.printing.business.DocumentBusinessBean.java

License:Open Source License

private int createPasswordLetterContent(DocumentPrintContext dpc) throws ContentCreationException {
    IWBundle iwb = getIWApplicationContext().getIWMainApplication()
            .getBundle(is.idega.idegaweb.egov.message.business.MessageConstants.IW_BUNDLE_IDENTIFIER);
    System.out.println("Default locale: "
            + getIWApplicationContext().getApplicationSettings().getDefaultLocale().toString());
    String sAddrString = "";
    PdfContentByte cb = dpc.getPdfWriter().getDirectContent();
    Document document = dpc.getDocument();
    Locale locale = dpc.getLocale();
    PrintMessage msg = dpc.getMessage();
    // String mail_zip = iwb.getProperty("commune.mail_zip");
    // String mail_name = iwb.getProperty("commune.mail_name");

    try {/*from www  .j  a  va 2  s . c o m*/
        sAddrString = getAddressString(dpc.getMessage().getOwner());
    } catch (Exception nouser) {
        handleNoAddressUser();
        System.err.println(nouser.getMessage());
        // nouser.printStackTrace();
        return ADDRESS_ERROR;
    }
    try {
        if (addTemplateHeader()) {
            ColumnText ct = new ColumnText(cb);
            float margin = getPointsFromMM(14);
            float lly = getPointsFromMM(297 - 22);
            float ury = lly + 60f;
            float urx = 595f - margin - 60f - 5f;
            float llx = 110f + margin;
            Phrase Ph0 = new Phrase(sAddrString, new Font(Font.HELVETICA, 12, Font.BOLD));
            ct.setSimpleColumn(Ph0, llx, lly, urx, ury, 15, Element.ALIGN_LEFT);
            ct.go();

            document.add(new Paragraph("\n\n\n\n\n\n\n"));
        }

        {

            User owner = msg.getOwner();
            HashMap tagmap = new CommuneUserTagMap(getIWApplicationContext(), owner);
            tagmap.putAll(getMessageTagMap(msg, locale));

            XmlPeer date = new XmlPeer(ElementTags.CHUNK, "date");
            date.setContent(new IWTimestamp().getDateString("dd.MM.yyyy"));
            tagmap.put(date.getAlias(), date);
            System.out.println("Date tag: " + date.getTag());

            String letterUrl = getXMLLetterUrl(iwb, locale, "password_letter.xml");
            if (msg.getBody().indexOf("|") > 0) {
                StringTokenizer tokenizer = new StringTokenizer(msg.getBody(), "|");
                XmlPeer peer = new XmlPeer(ElementTags.ITEXT, "letter");
                tagmap.put(peer.getAlias(), peer);

                if (tokenizer.hasMoreTokens()) {
                    peer = new XmlPeer(ElementTags.CHUNK, "username");
                    peer.setContent(tokenizer.nextToken());
                    tagmap.put(peer.getAlias(), peer);
                }
                if (tokenizer.hasMoreTokens()) {
                    peer = new XmlPeer(ElementTags.CHUNK, "password");
                    peer.setContent(tokenizer.nextToken());
                    tagmap.put(peer.getAlias(), peer);
                }

            }
            javax.xml.parsers.SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
            SAXmyHandler handler = new SAXmyHandler(document, tagmap);
            handler.setControlOpenClose(false);

            parser.parse(letterUrl, handler);
        }
    } catch (Exception e) {
        throw new ContentCreationException(e);
    }

    return 0;
}

From source file:ispyb.common.util.export.PdfExporterSample.java

License:Open Source License

/**
 * Exports the file for viewSample for shipment
 * /*  www.ja v  a  2 s.c om*/
 * @return
 * @throws Exception
 */
public ByteArrayOutputStream exportAsPdf() throws Exception {

    // create simple doc and write to a ByteArrayOutputStream
    Document document = new Document(PageSize.A4.rotate(), 20, 20, 20, 20);
    document.addTitle("exportSamplesView");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);
    HeaderFooter header;

    // header + footer
    if (viewName != null)
        header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc + "  ---  " + viewName),
                false);

    else
        header = new HeaderFooter(new Phrase("Samples for Proposal: " + proposalDesc), false);

    header.setAlignment(Element.ALIGN_CENTER);
    header.setBorderWidth(1);
    header.getBefore().getFont().setSize(8);
    HeaderFooter footer = new HeaderFooter(new Phrase("Page n."), true);
    footer.setAlignment(Element.ALIGN_RIGHT);
    footer.setBorderWidth(1);
    footer.getBefore().getFont().setSize(6);

    document.setHeader(header);
    document.setFooter(footer);

    document.open();

    if (aList.isEmpty()) {
        document.add(new Paragraph("There is no samples in this report"));
        document.close();
        return baos;
    }
    // Create first table for samples

    int NumColumns = 19;
    PdfPTable table = new PdfPTable(NumColumns);
    int headerwidths[] = { 6, 6, 6, 6, 6, 4, 6, 4, 4, 4, 4, 4, 4, 8, 5, 5, 5, 10, 6 }; // percentage
    table.setWidths(headerwidths);

    table.setWidthPercentage(100); // percentage
    table.getDefaultCell().setPadding(3);
    table.getDefaultCell().setBorderWidth(1);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    // header
    PdfPCell cell = new PdfPCell();
    table.addCell(new Paragraph("Protein", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample name", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Smp code", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Dewar", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Container", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Loc. in cont.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Space group", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell a", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell b", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell c", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell alpha", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell beta", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Cell gamma", new Font(Font.HELVETICA, 8)));

    cell = new PdfPCell(new Paragraph("Crystal comments", new Font(Font.HELVETICA, 8)));
    table.addCell(cell);

    table.addCell(new Paragraph("Already observed resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Required resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Min. resol.", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample comments", new Font(Font.HELVETICA, 8)));
    table.addCell(new Paragraph("Sample status", new Font(Font.HELVETICA, 8)));

    table.setHeaderRows(1); // this is the end of the table header

    table.getDefaultCell().setBorderWidth(1);
    DecimalFormat df1 = new DecimalFormat("#####0.0");
    DecimalFormat df2 = new DecimalFormat("#####0.00");

    Iterator it = aList.iterator();
    int i = 1;
    String currentContainer = "next";
    String nextContainer = "next";

    while (it.hasNext()) {
        table.getDefaultCell().setGrayFill(0.99f);
        if (i % 2 == 1) {
            table.getDefaultCell().setGrayFill(0.9f);
        }
        BLSample3VO samplefv = (BLSample3VO) it.next();
        LOG.debug("table of datacollections pdf " + samplefv.getBlSampleId());

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null)
            nextContainer = samplefv.getContainerVO().getCode();
        else
            nextContainer = "next";

        // in the case of view sorted by dewar/container, we add a page break afetr each container
        if (sortView.equals("2") && !currentContainer.equals(nextContainer)) {
            document.add(table);
            table.deleteBodyRows();
            document.newPage();
        }

        if (samplefv.getCrystalVO().getProteinVO().getAcronym() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getProteinVO().getAcronym(),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getName() != null)
            table.addCell(new Paragraph(samplefv.getName(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCode() != null)
            table.addCell(new Paragraph(samplefv.getCode(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getDewarVO() != null
                && samplefv.getContainerVO().getDewarVO().getCode() != null)
            table.addCell(new Paragraph(samplefv.getContainerVO().getDewarVO().getCode(),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getContainerVO() != null && samplefv.getContainerVO().getCode() != null) {
            currentContainer = samplefv.getContainerVO().getCode();
            table.addCell(new Paragraph(currentContainer, new Font(Font.HELVETICA, 8)));
        } else {
            currentContainer = "current";
            table.addCell("");
        }

        if (samplefv.getLocation() != null)
            table.addCell(new Paragraph(samplefv.getLocation(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getSpaceGroup() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getSpaceGroup(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellA() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellA()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellB() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellB()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellC() != null)
            table.addCell(
                    new Paragraph(df1.format(samplefv.getCrystalVO().getCellC()), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellAlpha() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellAlpha()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellBeta() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellBeta()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getCellGamma() != null)
            table.addCell(new Paragraph(df1.format(samplefv.getCrystalVO().getCellGamma()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getCrystalVO().getComments() != null)
            table.addCell(new Paragraph(samplefv.getCrystalVO().getComments(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getObservedResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getObservedResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getObservedResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getRequiredResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getRequiredResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getRequiredResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getDiffractionPlanVO() != null
                && samplefv.getDiffractionPlanVO().getMinimalResolution() != null) {
            table.addCell(new Paragraph(df2.format(samplefv.getDiffractionPlanVO().getMinimalResolution()),
                    new Font(Font.HELVETICA, 8)));
        } else if (samplefv.getCrystalVO().getDiffractionPlanVO() != null
                && samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution() != null)
            table.addCell(new Paragraph(
                    df2.format(samplefv.getCrystalVO().getDiffractionPlanVO().getMinimalResolution()),
                    new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getComments() != null && samplefv.getComments() != "")
            table.addCell(new Paragraph(samplefv.getComments(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (samplefv.getBlSampleStatus() != null)
            table.addCell(new Paragraph(samplefv.getBlSampleStatus(), new Font(Font.HELVETICA, 8)));
        else
            table.addCell("");

        if (i % 2 == 1) {
            table.getDefaultCell().setGrayFill(0.0f);
        }

        i++;
    }

    document.add(table);

    document.close();

    return baos;
}

From source file:it.prato.comune.tolomeo.web.TolomeoPrintPDFServlet.java

License:Open Source License

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    LogInterface logger = getLogger(request);

    String titolo = request.getParameter("titolo");
    String descrizione = request.getParameter("descrizione");
    String scala = request.getParameter("scala");
    String mapx = request.getParameter("mapx");
    String mapy = request.getParameter("mapy");
    //creo URL alla mappa
    URL urlMappa = new URL(URLDecoder.decode(request.getParameter("urlMappa"), "UTF-8"));
    URI uriMappa = null;/*from w w w.  j  a va2s.  c  o  m*/
    try {
        uriMappa = new URI(urlMappa.getProtocol(), null, urlMappa.getHost(), urlMappa.getPort(),
                urlMappa.getPath(), urlMappa.getQuery() + "&mode=map&scale=" + scala + "&mapxy=" + mapx + "+"
                        + mapy + "&map_size=500 500",
                null);
        logger.info("URI di stampa mappa: " + uriMappa);
    } catch (URISyntaxException e) {
        logger.error("URI errore di sintassi", e);
    }

    Font BOLD15 = new Font(Font.HELVETICA, 15, Font.BOLD);
    Font FONT12 = new Font(Font.HELVETICA, 12, Font.NORMAL);
    Font FONT10 = new Font(Font.HELVETICA, 10, Font.NORMAL);

    Document doc = new Document();
    ;
    PdfWriter pdf = null;
    Paragraph par = new Paragraph();

    try {

        //creo il PDF
        response.setContentType("application/pdf");
        pdf = PdfWriter.getInstance(doc, response.getOutputStream());

        //attributi file
        doc.addTitle("Mappa di Prato");
        doc.addAuthor("Comune di Prato");
        doc.open();

        //intestazione
        par.setAlignment(Paragraph.ALIGN_CENTER);
        print("Comune di Prato", BOLD15, par, doc);
        print(titolo, FONT10, par, doc);
        print("", FONT10, par, doc);

        //mappa
        Image mappa = Image.getInstance(uriMappa.toURL());
        mappa.setAlignment(Image.MIDDLE);
        mappa.setBorder(Rectangle.BOX);
        mappa.setBorderWidth(1f);
        doc.add(mappa);

    } catch (Exception e) {
        logger.error("Errore durante la creazione del PDF", e);
        printErr(doc);
    } finally {
        doc.close();
        pdf.close();
        response.getOutputStream().close();
    }
}

From source file:jm.fac.pdf.pdfArqueoCaja.java

License:GNU General Public License

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request/*from w  ww.  java 2s.c om*/
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession sesion = request.getSession(true);
    String usuario = (String) sesion.getAttribute("usuario");
    String clave = (String) sesion.getAttribute("clave");

    response.setContentType("application/pdf");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Expires", "Mon, 01 Jan 2001 00:00:01 GMT");
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Cache-Control", "must-revalidate");
    response.setHeader("Cache-Control", "no-cache");

    //PrintWriter out = response.getWriter();

    Configuracion conf = new Configuracion(this._ip, this._puerto, this._db, usuario, clave);
    String titulo = conf.getValor("razon_social");
    conf.cerrar();

    String path = String.valueOf(request.getRequestURL());
    path = path.substring(0, path.lastIndexOf("/"));
    /*Archivo archivo = new Archivo(this._ip, this._puerto, this._db, usuario, clave);
    String logo = path + "/img/" + archivo.getArchivo(this._dir, 1);
    archivo.cerrar();*/

    ArqueoCaja objArqueoCaja = new ArqueoCaja(this._ip, this._puerto, this._db, usuario, clave);

    Empleado objEmpleado = new Empleado(this._ip, this._puerto, this._db, usuario, clave);

    String id = request.getParameter("id");
    //int i=0;

    String num_documento = "0";
    String fecha = Fecha.getFecha("SQL");
    String hora = Fecha.getHora();
    String cajero = "";
    String saldo_caja = "0";
    String num_cheques = "0";
    String valor_cheques = "0";
    String num_comp_pagos = "0";
    String valor_comp_pagos = "0";
    String num_retenciones = "0";
    String valor_retenciones = "0";
    String valor_efectivo = "0";
    String total_caja = "0";
    String diferencia = "0";
    String tipo_diferencia = "0";
    //boolean anulado = false;

    if (id.compareTo("-1") != 0) {
        try {
            ResultSet rsArqueoCaja = objArqueoCaja.getArqueoCaja(id);
            if (rsArqueoCaja.next()) {
                num_documento = (rsArqueoCaja.getString("num_documento") != null)
                        ? rsArqueoCaja.getString("num_documento")
                        : "0";
                fecha = (rsArqueoCaja.getString("fecha") != null) ? rsArqueoCaja.getString("fecha") : "";
                hora = (rsArqueoCaja.getString("Hora") != null) ? rsArqueoCaja.getString("Hora") : "";
                cajero = (rsArqueoCaja.getString("cajero") != null) ? rsArqueoCaja.getString("cajero") : "";
                saldo_caja = (rsArqueoCaja.getString("saldo_caja") != null)
                        ? rsArqueoCaja.getString("saldo_caja")
                        : "";
                num_cheques = (rsArqueoCaja.getString("num_cheques") != null)
                        ? rsArqueoCaja.getString("num_cheques")
                        : "0.00";
                valor_cheques = (rsArqueoCaja.getString("valor_cheques") != null)
                        ? rsArqueoCaja.getString("valor_cheques")
                        : "0.00";
                num_comp_pagos = (rsArqueoCaja.getString("num_comp_pagos") != null)
                        ? rsArqueoCaja.getString("num_comp_pagos")
                        : "0.00";
                valor_comp_pagos = (rsArqueoCaja.getString("valor_comp_pagos") != null)
                        ? rsArqueoCaja.getString("valor_comp_pagos")
                        : "0.00";
                num_retenciones = (rsArqueoCaja.getString("num_retenciones") != null)
                        ? rsArqueoCaja.getString("num_retenciones")
                        : "0";
                valor_retenciones = (rsArqueoCaja.getString("valor_retenciones") != null)
                        ? rsArqueoCaja.getString("valor_retenciones")
                        : "0.00";

                valor_efectivo = (rsArqueoCaja.getString("valor_efectivo") != null)
                        ? rsArqueoCaja.getString("valor_efectivo")
                        : "0.00";
                total_caja = (rsArqueoCaja.getString("total") != null) ? rsArqueoCaja.getString("total")
                        : "0.00";
                diferencia = (rsArqueoCaja.getString("diferencia") != null)
                        ? rsArqueoCaja.getString("diferencia")
                        : "0.00";
                tipo_diferencia = (rsArqueoCaja.getString("tipo_diferencia") != null)
                        ? rsArqueoCaja.getString("tipo_diferencia")
                        : "";
                //anulado = (rsArqueoCaja.getString("anulado")!=null) ? rsArqueoCaja.getBoolean("anulado") : false;
                rsArqueoCaja.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    String sucursal = "";
    String empleado = "";
    try {
        ResultSet rs = objEmpleado.getCajero(cajero);
        if (rs.next()) {
            sucursal = rs.getString("sucursal") != null ? rs.getString("sucursal") : "";
            empleado = rs.getString("empleado") != null ? rs.getString("empleado") : "";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    /* inicio PDF */
    Document doc = new Document(PageSize.A4);// paso 1

    /* tambien establesco el alto del tope para la primera impresion de la factura */

    float ancho = PageSize.A4.getWidth();
    float alto = PageSize.A4.getHeight();

    try {
        PdfWriter writer = PdfWriter.getInstance(doc, response.getOutputStream()); // paso 2

        doc.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);
        tbl_titulo
                .addCell(Addons.setCeldaPDF(titulo, Font.HELVETICA, 14, Font.NORMAL, Element.ALIGN_CENTER, 0));
        tbl_titulo.addCell(Addons.setCeldaPDF("ARQUEO DE CAJA\n\n", Font.HELVETICA, 14, Font.BOLD,
                Element.ALIGN_CENTER, 0));
        tbl_titulo.addCell(Addons.setCeldaPDF("No.   " + num_documento + "\n", Font.HELVETICA, 12, Font.NORMAL,
                Element.ALIGN_RIGHT, 0));
        tbl_titulo.addCell(Addons.setCeldaPDF("Sucursal: " + sucursal, Font.HELVETICA, 10, Font.NORMAL,
                Element.ALIGN_LEFT, 0));
        tbl_titulo.addCell(Addons.setCeldaPDF("Usuario de caja: " + cajero, Font.HELVETICA, 10, Font.NORMAL,
                Element.ALIGN_LEFT, 0));
        tbl_titulo.addCell(Addons.setCeldaPDF("Responsable de caja: " + empleado, Font.HELVETICA, 10,
                Font.NORMAL, Element.ALIGN_LEFT, 0));
        doc.add(tbl_titulo);

        PdfPTable tbl_det = new PdfPTable(2);

        tbl_det.addCell(
                Addons.setCeldaPDF("Fecha: " + fecha, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_LEFT, 0));
        tbl_det.addCell(
                Addons.setCeldaPDF("Hora: " + hora, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_LEFT, 0));

        tbl_det.addCell(Addons.setFilaBlanco(3, 10));

        doc.add(tbl_det);

        /* efectivo */
        try {
            String denominacion = "";
            String cantidad = "";
            String total = "";
            ResultSet rsArqueoEfectivo = objArqueoCaja.getArqueoCajaEfectivo(id);
            if (objArqueoCaja.getFilas(rsArqueoEfectivo) > 0) {
                doc.add(Addons.setCabeceraTabla(new String[] { "DENOMINACION", "CANTIDAD", "TOTAL ($)" },
                        new float[] { 60f, 20f, 20f }));
                PdfPTable tbl_efectivo = new PdfPTable(new float[] { 60f, 20f, 20f });
                while (rsArqueoEfectivo.next()) {
                    denominacion = (rsArqueoEfectivo.getString("denominacion") != null)
                            ? rsArqueoEfectivo.getString("denominacion")
                            : "";
                    cantidad = (rsArqueoEfectivo.getString("cantidad") != null)
                            ? rsArqueoEfectivo.getString("cantidad")
                            : "";
                    total = (rsArqueoEfectivo.getString("total") != null) ? rsArqueoEfectivo.getString("total")
                            : "";
                    tbl_efectivo.addCell(Addons.setCeldaPDF(denominacion, Font.HELVETICA, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1));
                    tbl_efectivo.addCell(Addons.setCeldaPDF(cantidad, Font.HELVETICA, 8, Font.NORMAL,
                            Element.ALIGN_CENTER, 1));
                    tbl_efectivo.addCell(
                            Addons.setCeldaPDF(total, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                tbl_efectivo.addCell(Addons.setFilaBlanco(3, 10));
                doc.add(tbl_efectivo);
            }
            rsArqueoEfectivo.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        /* cheque */
        try {
            String efectivizado = "";
            String banco = "";
            String num_cheque = "";
            String valor = "";
            ResultSet rsArqueoCheque = objArqueoCaja.getArqueoCajaCheque(id);
            if (objArqueoCaja.getFilas(rsArqueoCheque) > 0) {
                doc.add(Addons.setCabeceraTabla(
                        new String[] { "BANCO", "Nro. CHEQUE", "VALOR ($)", "EFECTIVIZADO" },
                        new float[] { 60f, 30f, 20f, 15f }));
                PdfPTable tbl_cheque = new PdfPTable(new float[] { 60f, 30f, 20f, 15f });
                while (rsArqueoCheque.next()) {
                    efectivizado = (rsArqueoCheque.getString("efectivizado") != null)
                            ? rsArqueoCheque.getString("efectivizado")
                            : "";
                    banco = (rsArqueoCheque.getString("banco") != null) ? rsArqueoCheque.getString("banco")
                            : "";
                    num_cheque = (rsArqueoCheque.getString("num_cheque") != null)
                            ? rsArqueoCheque.getString("num_cheque")
                            : "";
                    valor = (rsArqueoCheque.getString("valor") != null) ? rsArqueoCheque.getString("valor")
                            : "";
                    tbl_cheque.addCell(
                            Addons.setCeldaPDF(banco, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                    tbl_cheque.addCell(Addons.setCeldaPDF(num_cheque, Font.HELVETICA, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1));
                    tbl_cheque.addCell(
                            Addons.setCeldaPDF(valor, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                    tbl_cheque.addCell(Addons.setCeldaPDF(efectivizado, Font.HELVETICA, 8, Font.NORMAL,
                            Element.ALIGN_RIGHT, 1));
                }
                tbl_cheque.addCell(Addons.setFilaBlanco(4, 10));
                doc.add(tbl_cheque);
            }
            rsArqueoCheque.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        /* otros documentos */
        try {
            String num_comp_pago = "";
            String valor = "";
            ResultSet rsArqueoDocs = objArqueoCaja.getArqueoCajaOtros(id);
            if (objArqueoCaja.getFilas(rsArqueoDocs) > 0) {
                doc.add(Addons.setCabeceraTabla(new String[] { "Nro. COMP. PAGO", "VALOR ($)" },
                        new float[] { 70f, 30f }));
                PdfPTable tbl_otros = new PdfPTable(new float[] { 70f, 30f });
                while (rsArqueoDocs.next()) {
                    num_comp_pago = (rsArqueoDocs.getString("num_comp_pago") != null)
                            ? rsArqueoDocs.getString("num_comp_pago")
                            : "";
                    valor = (rsArqueoDocs.getString("valor") != null) ? rsArqueoDocs.getString("valor") : "0";
                    tbl_otros.addCell(Addons.setCeldaPDF(num_comp_pago, Font.HELVETICA, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1));
                    tbl_otros.addCell(
                            Addons.setCeldaPDF(valor, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));
                }
                tbl_otros.addCell(Addons.setFilaBlanco(3, 10));
                doc.add(tbl_otros);
            }
            rsArqueoDocs.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        /* retenciones */
        try {
            String num_retencion = "";
            String valor_retencion = "";
            ResultSet rsArqueoRets = objArqueoCaja.getArqueoCajaRetenciones(id);
            if (objArqueoCaja.getFilas(rsArqueoRets) > 0) {
                doc.add(Addons.setCabeceraTabla(new String[] { "Nro. RETENCION", "VALOR ($)" },
                        new float[] { 70f, 30f }));
                PdfPTable tbl_otros = new PdfPTable(new float[] { 70f, 30f });
                while (rsArqueoRets.next()) {
                    num_retencion = (rsArqueoRets.getString("num_retencion") != null)
                            ? rsArqueoRets.getString("num_retencion")
                            : "";
                    valor_retencion = (rsArqueoRets.getString("valor_retencion") != null)
                            ? rsArqueoRets.getString("valor_retencion")
                            : "0";
                    tbl_otros.addCell(Addons.setCeldaPDF(num_retencion, Font.HELVETICA, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1));
                    tbl_otros.addCell(Addons.setCeldaPDF(valor_retencion, Font.HELVETICA, 8, Font.NORMAL,
                            Element.ALIGN_RIGHT, 1));
                }
                tbl_otros.addCell(Addons.setFilaBlanco(3, 10));
                doc.add(tbl_otros);
            }
            rsArqueoRets.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        PdfPTable tbl_totales = new PdfPTable(new float[] { 60f, 40f });
        tbl_totales.addCell(Addons.setFilaBlanco(3, 5));

        tbl_totales.addCell(Addons.setCeldaPDF("Saldo en caja actual:", Font.HELVETICA, 8, Font.NORMAL,
                Element.ALIGN_LEFT, 1));
        tbl_totales.addCell(
                Addons.setCeldaPDF(saldo_caja, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));

        tbl_totales.addCell(Addons.setCeldaPDF("Total monedas y billetes:", Font.HELVETICA, 8, Font.NORMAL,
                Element.ALIGN_LEFT, 1));
        tbl_totales.addCell(
                Addons.setCeldaPDF(valor_efectivo, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));

        tbl_totales.addCell(Addons.setCeldaPDF("Total cheques (" + num_cheques + "):", Font.HELVETICA, 8,
                Font.NORMAL, Element.ALIGN_LEFT, 1));
        tbl_totales.addCell(
                Addons.setCeldaPDF(valor_cheques, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));

        tbl_totales.addCell(Addons.setCeldaPDF("Total comprobantes de pago (" + num_comp_pagos + "):",
                Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
        tbl_totales.addCell(
                Addons.setCeldaPDF(valor_comp_pagos, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));

        tbl_totales.addCell(Addons.setCeldaPDF("Total retenciones (" + num_retenciones + "):", Font.HELVETICA,
                8, Font.NORMAL, Element.ALIGN_LEFT, 1));
        tbl_totales.addCell(
                Addons.setCeldaPDF(valor_retenciones, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));

        tbl_totales.addCell(
                Addons.setCeldaPDF("Total en caja:", Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
        tbl_totales.addCell(
                Addons.setCeldaPDF(total_caja, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));

        tbl_totales.addCell(Addons.setCeldaPDF(
                "Diferencia:        " + (tipo_diferencia.compareTo("f") == 0 ? "faltante"
                        : (tipo_diferencia.compareTo("s") == 0 ? "sobrante" : "")),
                Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
        tbl_totales.addCell(
                Addons.setCeldaPDF(diferencia, Font.HELVETICA, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1));

        doc.add(tbl_totales);

        doc.add(new Paragraph(" "));
        doc.add(new Paragraph(" "));
        doc.add(new Paragraph(" "));

        PdfPTable tbl_firmas = new PdfPTable(3);
        tbl_firmas.addCell(
                Addons.setCeldaPDF("RESPONSABLE", Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_CENTER, 0));
        tbl_firmas.addCell(
                Addons.setCeldaPDF("VERIFICADO", Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_CENTER, 0));
        tbl_firmas.addCell(
                Addons.setCeldaPDF("AUTORIZADO", Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_CENTER, 0));
        doc.add(tbl_firmas);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } finally {
        objEmpleado.cerrar();
        objArqueoCaja.cerrar();
    }

    doc.close(); // paso 5
    /* fin PDF */
}

From source file:jm.nom.clas.Carnet.java

public void imprimir(HttpServletResponse response, ResultSet rsCarnets, String path) {
    response.setContentType("application/pdf");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Expires", "Mon, 01 Jan 2001 00:00:01 GMT");
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Cache-Control", "must-revalidate");
    response.setHeader("Cache-Control", "no-cache");

    /*try{//from ww w. ja  v a2  s .c  o m
        rsCarnets = objEmpleado.getCarnets(id);
        if(rsCarnets.next()){
            id_sucursal = ((rsCarnets.getString("id_sucursal")!=null) ? rsCarnets.getString("id_sucursal") : "");
            id_instalacion = ((rsCarnets.getString("id_instalacion")!=null) ? rsCarnets.getString("id_instalacion") : "");
            serie_factura = ((rsCarnets.getString("serie_factura")!=null) ? rsCarnets.getString("serie_factura") : "");
            num_factura = ((rsCarnets.getString("num_factura")!=null) ? rsCarnets.getString("num_factura") : "");
            razon_social = ((rsCarnets.getString("razon_social")!=null) ? rsCarnets.getString("razon_social") : "CONSUMIDOR FINAL");
            fecha_emision = ((rsCarnets.getString("fecha_emision")!=null) ? Fecha.ISOaSQL(rsCarnets.getString("fecha_emision")) : "");
            direccion = ((rsCarnets.getString("direccion")!=null) ? rsCarnets.getString("direccion") : "");
            vendedor = ((rsCarnets.getString("vendedor")!=null) ? rsCarnets.getString("vendedor") : "");
            total = ((rsCarnets.getString("total")!=null) ? rsCarnets.getString("total") : "0.00");
            de_activo = ((rsCarnets.getString("de_activo")!=null) ? rsCarnets.getBoolean("de_activo") : false);
            rsCarnets.close();
        }
    }catch(Exception ie){
        ie.printStackTrace();
    }*/
    try {
        /* inicio PDF */
        Document document = new Document(PageSize.A4.rotate());// paso 1
        document.setMargins(-47, 0, 38, 0); /*Izquierda, derecha, tope, pie */

        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Carnet(this._dir));
        document.open(); // paso 3

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

        /* todo el cuerpo del doc es el paso 4 */

        //PdfPTable tbl = new PdfPTable(new float[]{40f,60f});
        PdfPTable tbl = new PdfPTable(4);
        int i = 0;
        try {
            //rsCarnets = objEmpleado.getCarnets(id);
            while (rsCarnets.next()) {
                PdfPTable tbl1 = new PdfPTable(1);
                PdfPTable tbl2 = new PdfPTable(new float[] { 90f, 5f, 5f });
                String foto = ((rsCarnets.getString("padre_nombre") != null)
                        ? rsCarnets.getString("padre_nombre")
                        : "");
                //_dir="C:\\Users\\SoulGael\\Documents\\NetBeansProjects\\trunk\\saitel\\build\\web\\img\\luis.jpg";

                tbl1.addCell(Addons.setCeldaPDFBottom(" ", Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT,
                        0, 26, 0));
                tbl1.addCell(Addons.setLogoCarnet(_dir + foto, 79, 103));
                //tbl1.addCell(Addons.setLogoCarnet(_dir,79,103));
                String nombre = ((rsCarnets.getString("nombre") != null) ? rsCarnets.getString("nombre") : "");
                String apellidos = ((rsCarnets.getString("apellido") != null) ? rsCarnets.getString("apellido")
                        : "");
                String cargo = ((rsCarnets.getString("cargo") != null) ? rsCarnets.getString("cargo") : "");
                ;
                String[] nombresArray = nombre.split(" ");
                String[] apellidosArray = apellidos.split(" ");
                String n_completos = nombresArray[0] + " " + apellidosArray[0];
                String CI = ((rsCarnets.getString("dni") != null) ? rsCarnets.getString("dni") : "");
                ;
                String sangre = ((rsCarnets.getString("tipo_sangre") != null)
                        ? rsCarnets.getString("tipo_sangre")
                        : "");
                ;
                String carnet = ((rsCarnets.getString("carnet") != null) ? rsCarnets.getString("carnet") : "");
                //String carnet="A,B,C,D,E,F,G";
                Color A = Color.WHITE;
                Color B = Color.WHITE;
                Color C = Color.WHITE;
                Color D = Color.WHITE;
                Color E = Color.WHITE;
                Color F = Color.WHITE;
                Color G = Color.WHITE;

                String[] carnetArray = carnet.split(",");
                for (int j = 0; j < carnetArray.length; j++) {
                    if (carnetArray[j].equals("A")) {
                        A = Color.ORANGE;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("B")) {
                        B = Color.ORANGE;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("C")) {
                        C = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("D")) {
                        D = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("E")) {
                        E = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("F")) {
                        F = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    if (carnetArray[j].equals("G")) {
                        G = Color.ORANGE;
                        ;
                        j++;
                        if (j > carnetArray.length - 1)
                            j = carnetArray.length - 1;
                    }
                    break;
                }

                tbl1.addCell(Addons.setCeldaPDFBottom(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(n_completos, Font.ITALIC, 13, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(cargo, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER,
                        0, 0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(CI, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 0));
                tbl1.addCell(Addons.setCeldaPDFBottom(sangre, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER,
                        0, 0, 0));

                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("  LICENCIA INTERNA DE ", Font.ITALIC, 9, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("  PREVENCION DE RIESGOS", Font.ITALIC, 9, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("   Con la induccin recibida y aprobada usted",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("   est autorizado para:", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      a. Trabajo de Oficina.", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, A));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      b. Trabajo de Marketing y propaganda", Font.ITALIC,
                        8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, B));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      c. Trabajo de mantenimiento y limpieza",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, C));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      d. Trabajo de instalaciones menores a los ",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 2));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      ocho metros sobre el nivel.", Font.ITALIC, 8,
                        Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 0, 0, D));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      (Domicilios, postes, cableado)", Font.ITALIC, 8,
                        Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        2, 2));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      e. Trabajo de instalaciones, antenas,",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        0, 2));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      infraestructura mayores a los ocho", Font.ITALIC,
                        8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 0, 0, E));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet("      metros sobre el nivel", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0,
                        2, 2));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      f. Planes de emergencia y contingencia",
                        Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, F));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(Addons.setCeldaPDFCarnet("      g. Planes de rescate", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_LEFT, 0, 2, 0));
                tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 1, 2, 0, G));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0));

                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(
                        Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 10, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3));
                tbl2.addCell(Addons.setCeldaPDFCarnet("Ing. FREDDY ROSERO", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                tbl2.addCell(Addons.setCeldaPDFCarnet("GERENTE", Font.ITALIC, 8, Font.BOLD,
                        Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                tbl2.addCell(Addons.setCeldaPDFCarnet("Fecha de Expedicin: Mayo 2015", Font.ITALIC, 5,
                        Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                tbl2.addCell(Addons.setCeldaPDFCarnet("Fecha de Caducidad: Mayo 2016", Font.ITALIC, 5,
                        Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE));
                /* tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("nombres")!=null) ? rsCarnets.getString("nombres") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("rol")!=null) ? rsCarnets.getString("rol") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                        
                tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("dni")!=null) ? rsCarnets.getString("dni") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("tipo_sangre")!=null) ? rsCarnets.getString("tipo_sangre") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1));
                        
                String idcarnet=(rsCarnets.getString("id_empleado")!=null) ? rsCarnets.getString("id_empleado") : "";*/

                tbl.addCell(Addons.setCeldaPDF(tbl1, 0, 0));
                tbl.addCell(Addons.setCeldaPDF(tbl2, 0, 0));
                if (i % 2 != 0) {
                    tbl1.addCell(
                            Addons.setCeldaPDF(" ", Font.ITALIC, 10, Font.BOLD, Element.ALIGN_LEFT, 0, 16, 3));
                }
                i++;
            }
            if (i % 2 != 0) {
                tbl.addCell(" ");
                tbl.addCell(" ");
            }

            /*Archivo archivo = new Archivo(_ip, _puerto, _db, _usuario, _clave);
                //path = path.substring(0, path.lastIndexOf("/"));
                String carnet = path + "/img/" + archivo.getArchivo(_dir, "vta_empleado", idcarnet, "padre_nombre", "foto");
                archivo.cerrar();
                Image imagen = null;
                try{
                    imagen = Image.getInstance(carnet);
                    imagen.scaleAbsolute(50, 70);
                    PdfPCell celdaImg = new PdfPCell(imagen);
                    celdaImg.setBorderWidth(0);
                    celdaImg.setPadding(0);
                    tbl.addCell(celdaImg);
                    document.add(tbl1);
                }catch(Exception e){
                    tbl.addCell(" ");
                }*/

        } catch (Exception e) {
            e.printStackTrace();
        }
        document.add(tbl);

        document.close(); // paso 5
        /* fin PDF */

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPCell setFilaBlanco(int colSpan, int alto) {
    PdfPCell celda = new PdfPCell(new Paragraph(" ", new Font(Font.HELVETICA, alto, Font.NORMAL)));
    celda.setBorderWidth(0);/*  w  w  w  . j a  v a 2s  .  c o m*/
    celda.setPadding(0);
    celda.setColspan(colSpan);
    return celda;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPCell setBarra(int colSpan, float color) {
    PdfPCell celda = new PdfPCell(new Paragraph(" ", new Font(Font.HELVETICA, 1, Font.NORMAL)));
    celda.setGrayFill(color);/*from w w w .  j a v  a 2s  .c o m*/
    celda.setBorderWidth(0);
    celda.setPadding(0);
    celda.setColspan(colSpan);
    return celda;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPTable setHistorial(ResultSet histo) {
    float bar[] = new float[103];
    bar[0] = 20f;// w  w w .ja va2  s  .c  o m
    bar[1] = 2f;
    for (int i = 2; i <= 101; i++) {
        bar[i] = 1f;
    }
    bar[102] = 20f;

    PdfPTable tabla = new PdfPTable(bar);
    tabla.addCell(Addons.setFilaBlanco(103, 1));

    String historial[][] = DatosDinamicos.ResultSetToMatriz(histo);
    float maximo = DatosDinamicos.valMaximo(historial, 1); /* es el valor mximo de los consumos */

    int porcentaje = 100;
    if (maximo / 10000 >= 1) {
        porcentaje = 100000;
    }
    if (maximo / 1000 >= 1) {
        porcentaje = 10000;
    }
    if (maximo / 100 >= 1) {
        porcentaje = 1000;
    }

    for (int i = 0; i < historial.length; i++) {
        tabla.addCell(Addons.setCeldaPDF(historial[i][0], Font.HELVETICA, 5, Font.NORMAL, Element.ALIGN_RIGHT,
                0, 0, 1));
        tabla.addCell(Addons.setCeldaPDF(" ", Font.HELVETICA, 5, Font.NORMAL, Element.ALIGN_RIGHT, 0, 0, 1));
        int ancho = Math.round(Float.parseFloat(historial[i][1]) * maximo / porcentaje);
        tabla.addCell(Addons.setBarra(ancho, 0f)); /* barra de consumo */
        if (ancho == 0) {
            ancho = 1;
        }
        tabla.addCell(Addons.setBarra(100 - ancho, 10f)); /* barra complementaria blanca */
        tabla.addCell(Addons.setCeldaPDF(" " + historial[i][1], Font.HELVETICA, 3, Font.NORMAL,
                Element.ALIGN_LEFT, 0, 0, 1));
        tabla.addCell(Addons.setFilaBlanco(103, 2));
    }

    return tabla;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static PdfPTable setCabecera(String logo, String titulo, String ruc, String subtitulo, String direccion,
        String sucursal) {/*from w w w.  j  a  v  a2s  .c  o m*/
    PdfPTable encabezado = new PdfPTable(new float[] { 80f, 400f });
    PdfPTable tbl_encab = new PdfPTable(1);
    Image imagelogo = null;
    try {
        imagelogo = Image.getInstance(logo);
        imagelogo.scaleAbsolute(150, 70);
        PdfPCell celdaImg = new PdfPCell(imagelogo);
        celdaImg.setBorderWidth(0);
        celdaImg.setPadding(0);
        encabezado.addCell(celdaImg);
    } catch (Exception e) {
        encabezado.addCell("");
    }
    tbl_encab.addCell(Addons.setCeldaPDF(titulo, Font.HELVETICA, 13, Font.BOLD, Element.ALIGN_CENTER, 0));
    tbl_encab.addCell(Addons.setCeldaPDF(direccion, Font.HELVETICA, 11, Font.NORMAL, Element.ALIGN_CENTER, 0));
    if (ruc.compareTo("") != 0) {
        tbl_encab.addCell(
                Addons.setCeldaPDF("RUC: " + ruc, Font.HELVETICA, 11, Font.NORMAL, Element.ALIGN_CENTER, 0));
    }
    tbl_encab.addCell(Addons.setCeldaPDF(subtitulo, Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_CENTER, 0));

    encabezado.addCell(Addons.setCeldaPDF(tbl_encab, Element.ALIGN_CENTER, 0));

    encabezado.addCell(Addons.setFilaBlanco(2, 6));

    if (sucursal.compareTo("") != 0) {
        encabezado.addCell(Addons.setCeldaPDF("Sucursal: " + sucursal, Font.HELVETICA, 10, Font.NORMAL,
                Element.ALIGN_LEFT, 0, 0, 2));
    }

    encabezado.addCell(Addons.setCeldaPDF("Fecha de impresin: " + Fecha.getFecha("SQL"), Font.HELVETICA, 10,
            Font.NORMAL, Element.ALIGN_LEFT, 0, 0, 2));

    encabezado.addCell(Addons.setFilaBlanco(2, 4));

    return encabezado;
}

From source file:jm.web.Addons.java

License:GNU General Public License

public static void setEncabezado(PdfWriter writer, Document document, String texto) {
    if (writer.getPageNumber() > 1) {
        try {//from w w  w.  ja v a2s .c o m
            PdfPTable encabezado = new PdfPTable(1);
            encabezado.setTotalWidth(document.right() - document.left() - 120);
            encabezado.addCell(Addons.setCeldaPDF(texto, Font.HELVETICA, 9, Font.BOLD, Element.ALIGN_LEFT, 0));
            encabezado.writeSelectedRows(0, -1, 60, document.top() + 25, writer.getDirectContent());

            PdfContentByte cb = writer.getDirectContent();
            cb.setLineWidth(2);
            cb.moveTo(60, document.top() + 10);
            cb.lineTo(document.right() - document.left() - 58, document.top() + 10);
        } catch (Exception e) {
            throw new ExceptionConverter(e);
        }
    }
}