Example usage for com.lowagie.text.pdf PdfPCell PdfPCell

List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell PdfPCell.

Prototype

public PdfPCell() 

Source Link

Document

Constructs an empty PdfPCell.

Usage

From source file:com.conecta.sat.utils.BuildAsignaSoftPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Into BuildImportTokensPDF");
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition",
            "attachment; filename=AsignaToken" + name.format(new Date()) + ".pdf");
    AsignaSoftPDF list = (AsignaSoftPDF) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);//from  w  w w  . j a  v  a2  s.com
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Asignacin de Token a cliente", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph("Asignacin Correcta", font);
    fecha.setAlignment(Element.ALIGN_CENTER);
    document.add(fecha);

    //        Paragraph pNombre = new Paragraph( nombreUsuario , font);
    //        pNombre.setAlignment(Element.ALIGN_RIGHT);
    //        document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Nombre empleado", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Fecha y Hora", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Cliente", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Token", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Tipo de Token", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("Centro Financiero", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Tipo", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Cliente nico", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Fecha de ultima modificacin", font));
    //        table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    //        for (ImportTokensPDF pdf : list) {
    //        ImportTokensPDF pdf;
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getNombre(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(df.format(list.getFecha()), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getCliente(), font2));
    table.addCell(cell);

    if (list.getToken().length() >= 14) {
        list.setTipo("SOFTTOKEN");
    } else {
        list.setTipo("HARDTOKEN");
    }

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getToken(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getTipo(), font2));
    table.addCell(cell);

    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCentro(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getTipo(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCliente(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getLastUpdate(),font2) );
    //            table.addCell(cell);
    //        }

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildAsignaTokenCenFinPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Into BuildImportTokensPDF");
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition",
            "attachment; filename=AsignacionTokensCentroFinanciero" + name.format(new Date()) + ".pdf");
    AsignaTokenCenFinPDF list = (AsignaTokenCenFinPDF) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);/*  ww  w .ja  v  a  2 s.  c om*/
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Asignacin de Hard Token", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph("Asignacin de Tokens a Centro Financiero", font);
    fecha.setAlignment(Element.ALIGN_CENTER);
    document.add(fecha);

    //        Paragraph pNombre = new Paragraph( nombreUsuario , font);
    //        pNombre.setAlignment(Element.ALIGN_RIGHT);
    //        document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    //        cell.setPhrase(new Phrase("Usuario que importo en token", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Fecha y Hora", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Tokens importados", font));
    //        table.addCell(cell);

    //        cell.setPhrase(new Phrase("Centro Financiero", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Tipo", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Cliente nico", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Fecha de ultima modificacin", font));
    //        table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    //        for (ImportTokensPDF pdf : list) {
    //        ImportTokensPDF pdf;
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Nombre empleado", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getNombre(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Fecha de Asignacin", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(df.format(list.getFecha()), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Centro Financiero asignado", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getCentroFinanciero(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Tokens asignados", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getTokens(), font2));
    table.addCell(cell);

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildBitacoraPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition", "attachment; filename=Bitacora" + name.format(new Date()) + ".pdf");
    List<BitacoraPDF> list = (List<BitacoraPDF>) map.get("listBitacora");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(columnas);
    table.setWidthPercentage(100);/*w w w .  jav a2  s.co  m*/
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Bitcora de Actividades", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph(df.format(new Date()), font);
    fecha.setAlignment(Element.ALIGN_RIGHT);
    document.add(fecha);

    Paragraph pNombre = new Paragraph(nombreUsuario, font);
    pNombre.setAlignment(Element.ALIGN_RIGHT);
    document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Nombre de usuario", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Bitcora", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("ltima fecha de Modificaciones", font));
    table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    for (BitacoraPDF bitacora : list) {
        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(bitacora.getNombre(), font2));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(bitacora.getMensaje(), font2));
        table.addCell(cell);
        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(bitacora.getFecha(), font2));
        table.addCell(cell);
        cell = new PdfPCell();
    }

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildDesactivarSoftPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Into BuildImportTokensPDF");
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition",
            "attachment; filename=DesactivarToken" + name.format(new Date()) + ".pdf");
    AsignaSoftPDF list = (AsignaSoftPDF) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);/*  www.  java 2 s.com*/
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Desactivacin de Token a cliente", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph("Cambio de Status Correcto", font);
    fecha.setAlignment(Element.ALIGN_CENTER);
    document.add(fecha);

    //        Paragraph pNombre = new Paragraph( nombreUsuario , font);
    //        pNombre.setAlignment(Element.ALIGN_RIGHT);
    //        document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Nombre empleado", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Fecha y Hora", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Cliente", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Token", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Tipo de Token", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("Centro Financiero", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Tipo", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Cliente nico", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Fecha de ultima modificacin", font));
    //        table.addCell(cell);
    if (list.getToken().length() < 8) {
        list.setTipo("SoftToken");
    } else {
        list.setTipo("HardToken");
    }

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    //        for (ImportTokensPDF pdf : list) {
    //        ImportTokensPDF pdf;
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getNombre(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(df.format(list.getFecha()), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getCliente(), font2));
    table.addCell(cell);
    if (list.getToken().length() > 8) {
        list.setTipo("SOFTTOKEN");
    } else {
        list.setTipo("HARDTOKEN");
    }
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getToken(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getTipo(), font2));
    table.addCell(cell);

    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCentro(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getTipo(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCliente(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getLastUpdate(),font2) );
    //            table.addCell(cell);
    //        }

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildDesasignaSoftPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Into BuildImportTokensPDF");
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition",
            "attachment; filename=CancelarToken" + name.format(new Date()) + ".pdf");
    AsignaSoftPDF list = (AsignaSoftPDF) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(5);
    table.setWidthPercentage(100);//  w  ww  . j  a v a  2 s  . c  om
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Cancelacin de Token a cliente", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph("Cancelacin Correcta", font);
    fecha.setAlignment(Element.ALIGN_CENTER);
    document.add(fecha);

    //        Paragraph pNombre = new Paragraph( nombreUsuario , font);
    //        pNombre.setAlignment(Element.ALIGN_RIGHT);
    //        document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Nombre empleado", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Fecha y Hora", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Cliente", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Token", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Tipo de Token", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("Centro Financiero", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Tipo", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Cliente nico", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Fecha de ultima modificacin", font));
    //        table.addCell(cell);
    if (list.getToken().length() < 8) {
        list.setTipo("SoftToken");
    } else {
        list.setTipo("HardToken");
    }

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    //        for (ImportTokensPDF pdf : list) {
    //        ImportTokensPDF pdf;
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getNombre(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(df.format(list.getFecha()), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getCliente(), font2));
    table.addCell(cell);
    if (list.getToken().length() == 14) {
        list.setTipo("SOFTTOKEN");
    } else {
        list.setTipo("HARDTOKEN");
    }
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getToken(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getTipo(), font2));
    table.addCell(cell);

    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCentro(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getTipo(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCliente(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getLastUpdate(),font2) );
    //            table.addCell(cell);
    //        }

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildDesasignaTokenCenFinPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Into BuildImportTokensPDF");
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition",
            "attachment; filename=DesasignacionTokensCentroFinanciero" + name.format(new Date()) + ".pdf");
    DesasignaTokenCenFinPDF list = (DesasignaTokenCenFinPDF) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(100);//ww w  .j  a v a2s .com
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Desasignacin de Hard Token", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph("Desasignacin de Tokens a Centro Financiero", font);
    fecha.setAlignment(Element.ALIGN_CENTER);
    document.add(fecha);

    //        Paragraph pNombre = new Paragraph( nombreUsuario , font);
    //        pNombre.setAlignment(Element.ALIGN_RIGHT);
    //        document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    //        cell.setPhrase(new Phrase("Usuario que importo en token", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Fecha y Hora", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Tokens importados", font));
    //        table.addCell(cell);

    //        cell.setPhrase(new Phrase("Centro Financiero", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Tipo", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Cliente nico", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Fecha de ultima modificacin", font));
    //        table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    //        for (ImportTokensPDF pdf : list) {
    //        ImportTokensPDF pdf;
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Nombre empleado", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getNombre(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Fecha de Desasignacin", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(df.format(list.getFecha()), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase("Tokens desasignados", font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getTokens(), font2));
    table.addCell(cell);

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildImportTokensPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    System.out.println("Into BuildImportTokensPDF");
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition",
            "attachment; filename=ImportTokens" + name.format(new Date()) + ".pdf");
    ImportTokensPDF list = (ImportTokensPDF) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(3);
    table.setWidthPercentage(100);/*from w w w. j a  v a 2 s .c  om*/
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Reporte de Tokens", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph(df.format(new Date()), font);
    fecha.setAlignment(Element.ALIGN_RIGHT);
    document.add(fecha);

    Paragraph pNombre = new Paragraph(nombreUsuario, font);
    pNombre.setAlignment(Element.ALIGN_RIGHT);
    document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Nmero de empleado que importo en token", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Fecha y Hora", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Tokens importados", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("Centro Financiero", font));
    //        table.addCell(cell);
    //         
    //        cell.setPhrase(new Phrase("Tipo", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Cliente nico", font));
    //        table.addCell(cell);
    //        
    //        cell.setPhrase(new Phrase("Fecha de ultima modificacin", font));
    //        table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    //        for (ImportTokensPDF pdf : list) {
    //        ImportTokensPDF pdf;
    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getUsuario(), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(df.format(list.getFecha()), font2));
    table.addCell(cell);

    cell = new PdfPCell();
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.addElement(new Phrase(list.getTokens(), font2));
    table.addCell(cell);

    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCentro(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getTipo(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getCliente(),font2) );
    //            table.addCell(cell);
    //            
    //            cell = new PdfPCell();
    //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
    //            cell.addElement( new Phrase(pdf.getLastUpdate(),font2) );
    //            table.addCell(cell);
    //        }

    document.add(table);
}

From source file:com.conecta.sat.utils.BuildPDF.java

@Override
protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer,
        HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    //        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    hsr1.setContentType("application/pdf");
    DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss");
    hsr1.setHeader("Content-disposition", "attachment; filename=Reporte" + name.format(new Date()) + ".pdf");
    List<PdfDTO> list = (List<PdfDTO>) map.get("list");
    String nombreUsuario = (String) map.get("nombreUsuario");

    PdfPTable table = new PdfPTable(9);
    table.setWidthPercentage(100);/*from www .ja v  a2s.  c  o  m*/
    table.setSpacingBefore(10);

    Font font = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font.setFamily(fontName);
    } catch (Exception e) {
        font.setFamily("Verdana");
    }

    try {
        ServletContext servletContext = hsr.getSession().getServletContext();
        String relativeWebPath = logoPath;
        String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
        Image logo = Image.getInstance(absoluteDiskPath);
        //            Image logo = Image.getInstance("logo.png");
        System.out.println("La imagen se cargo correctamente");
        logo.scaleToFit(widthLogo, heightLogo);
        document.add(logo);
    } catch (Exception e) {
        System.err.println("ERROR" + Excepciones.getStackTrace(e));
        document.add(new Paragraph("Sin imagen " + logoPath));
    }
    font.setSize(fontSize + 3);
    Paragraph titulo = new Paragraph("Reporte de Tokens", font);
    titulo.setAlignment(Element.ALIGN_RIGHT);
    document.add(titulo);

    Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f));
    document.add(CONNECT);

    DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a");
    font.setSize(fontSize + 2);
    Paragraph fecha = new Paragraph(df.format(new Date()), font);
    fecha.setAlignment(Element.ALIGN_RIGHT);
    document.add(fecha);

    Paragraph pNombre = new Paragraph(nombreUsuario, font);
    pNombre.setAlignment(Element.ALIGN_RIGHT);
    document.add(pNombre);

    font.setSize(fontSize);
    font.setColor(java.awt.Color.white);

    // define table header cell
    PdfPCell cell = new PdfPCell();
    java.awt.Color color = java.awt.Color.LIGHT_GRAY;
    cell.setBackgroundColor(color);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);

    cell.setPadding(5);

    // write table header
    cell.setPhrase(new Phrase("Serial Token", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("Estatus Entrega", font));
    cell.setPhrase(new Phrase("Estatus Entrega al Centro Financiero", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Estatus Entrega al Cliente", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Estatus Activacin", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Centro Financiero", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Tipo", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Cliente nico", font));
    table.addCell(cell);

    cell.setPhrase(new Phrase("Folio Pivotal", font));
    table.addCell(cell);

    //        cell.setPhrase(new Phrase("ID nico", font));
    //        table.addCell(cell);

    cell.setPhrase(new Phrase("Fecha de ltima modificacin", font));
    table.addCell(cell);

    Font font2 = FontFactory.getFont(FontFactory.HELVETICA);
    try {
        font2.setFamily(fontName);
    } catch (Exception e) {
        font2.setFamily("Verdana");
    }
    font2.setSize(fontSize);
    font2.setColor(java.awt.Color.black);
    // write table row data
    for (PdfDTO pdf : list) {
        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getSerial(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getEntrega(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getEntrega(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getActivacion(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getCentro(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getTipo(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getCliente(), font2));
        table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getFolioPivotal(), font2));
        table.addCell(cell);

        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
        //            cell.addElement( new Phrase(pdf.getIdUnico(),font2) );
        //            table.addCell(cell);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.addElement(new Phrase(pdf.getLastUpdate(), font2));
        table.addCell(cell);
    }

    document.add(table);
}

From source file:com.efficio.fieldbook.service.LabelPrintingServiceImpl.java

License:Open Source License

/**
 * Gets the cell height./*www . j a va 2s  .  c  om*/
 *
 * @param numberOfRowsPerPage the number of rows per page
 * @param pageSizeId the page size id
 * @return the cell height
 */
/*
private float getCellHeight(int numberOfRowsPerPage, int pageSizeId){
if(pageSizeId == AppConstants.SIZE_OF_PAPER_A4){
    if(numberOfRowsPerPage == 7){
        return 108f; //ok
    }else if(numberOfRowsPerPage == 8){
        return 97f;//ok
    }else if(numberOfRowsPerPage == 10){
        return 72.5f;
    }
}else{
    if(numberOfRowsPerPage == 7){
        return 108f; //ok
    }else if(numberOfRowsPerPage == 8){
        return 98.1f;//ok
    }else if(numberOfRowsPerPage == 10){
        return 72.5f;//ok
    }
}
           
return 0f;
}
*/
/* (non-Javadoc)
 * @see com.efficio.fieldbook.service.api.LabelPrintingService#generateLabels(com.efficio.fieldbook.web.fieldmap.bean.UserFieldmap)
 */
@Override
public String generatePDFLabels(List<StudyTrialInstanceInfo> trialInstances,
        UserLabelPrinting userLabelPrinting, ByteArrayOutputStream baos) throws MiddlewareQueryException {

    // setUserLabelPrinting(form.getUserLabelPrinting());
    int pageSizeId = Integer.parseInt(userLabelPrinting.getSizeOfLabelSheet());
    int numberOfLabelPerRow = Integer.parseInt(userLabelPrinting.getNumberOfLabelPerRow());
    int numberofRowsPerPageOfLabel = Integer.parseInt(userLabelPrinting.getNumberOfRowsPerPageOfLabel());
    int totalPerPage = numberOfLabelPerRow * numberofRowsPerPageOfLabel;
    String leftSelectedFields = userLabelPrinting.getLeftSelectedLabelFields();
    String rightSelectedFields = userLabelPrinting.getRightSelectedLabelFields();
    String barcodeNeeded = userLabelPrinting.getBarcodeNeeded();

    String firstBarcodeField = userLabelPrinting.getFirstBarcodeField();
    String secondBarcodeField = userLabelPrinting.getSecondBarcodeField();
    String thirdBarcodeField = userLabelPrinting.getThirdBarcodeField();

    String currentDate = DateUtil.getCurrentDate();
    // String fileName = currentDate + ".pdf";

    String fileName = userLabelPrinting.getFilenameDLLocation();

    try {
        FileOutputStream fileOutputStream = new FileOutputStream(fileName);

        try {

            // Image image1 = Image.getInstance(imageLocation);

            // PageSize.A4
            LabelPaper paper = LabelPaperFactory.generateLabelPaper(numberOfLabelPerRow,
                    numberofRowsPerPageOfLabel, pageSizeId);

            Rectangle pageSize = PageSize.LETTER;

            if (pageSizeId == AppConstants.SIZE_OF_PAPER_A4.getInt())
                pageSize = PageSize.A4;

            Document document = new Document(pageSize);
            /*
             * 2, 2, 33.3f, 5
             * 15, 0, 42, 5
             * 10, 0, 17, 5
             * 10, 0, 17, 5
             * 5, 0, 0, 5
             * 15, 0, 37, 5
             * 10, 0, 17, 5
            if (pageSizeId == AppConstants.SIZE_OF_PAPER_LETTER) {
            if (numberofRowsPerPageOfLabel == 7)
                document.setMargins(10, 0, 17, 5);
            else if (numberofRowsPerPageOfLabel == 8)
                document.setMargins(5, 0, 0, 5);
            else if (numberofRowsPerPageOfLabel == 10)
                document.setMargins(2, 2, 33.3f, 5);
            } else if (pageSizeId == AppConstants.SIZE_OF_PAPER_A4) {
            if (numberofRowsPerPageOfLabel == 7)
                document.setMargins(15, 0, 42, 5);
            else if (numberofRowsPerPageOfLabel == 8)
                document.setMargins(15, 0, 37, 5);
            else if (numberofRowsPerPageOfLabel == 10)
                document.setMargins(6, 2, 17.5f, 5);
            }
            */
            //float marginLeft, float marginRight, float marginTop, float marginBottom
            document.setMargins(paper.getMarginLeft(), paper.getMarginRight(), paper.getMarginTop(),
                    paper.getMarginBottom());

            // PdfWriter writer = PdfWriter.getInstance(document, baos);
            PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);
            // step 3
            document.open();
            // step 4

            PdfContentByte canvas = writer.getDirectContent();

            int i = 0;
            int fixTableRowSize = numberOfLabelPerRow;
            PdfPTable table = new PdfPTable(fixTableRowSize);

            // table.writeSelectedRows(0, -1, 10, 12, canvas);
            float columnWidthSize = 265f;// 180f;
            float[] widthColumns = new float[fixTableRowSize];

            for (int counter = 0; counter < widthColumns.length; counter++) {
                widthColumns[counter] = columnWidthSize;
            }

            table.setWidths(widthColumns);
            table.setWidthPercentage(100);
            int width = 600;
            int height = 75;

            List<File> filesToBeDeleted = new ArrayList<File>();
            //float cellHeight = getCellHeight(numberofRowsPerPageOfLabel, pageSizeId);
            float cellHeight = paper.getCellHeight();

            for (StudyTrialInstanceInfo trialInstance : trialInstances) {
                FieldMapTrialInstanceInfo fieldMapTrialInstanceInfo = trialInstance.getTrialInstance();

                Map<String, String> moreFieldInfo = new HashMap<String, String>();
                moreFieldInfo.put("locationName", fieldMapTrialInstanceInfo.getLocationName());
                moreFieldInfo.put("blockName", fieldMapTrialInstanceInfo.getBlockName());
                moreFieldInfo.put("selectedName", trialInstance.getFieldbookName());
                moreFieldInfo.put("trialInstanceNumber", fieldMapTrialInstanceInfo.getTrialInstanceNo());

                for (FieldMapLabel fieldMapLabel : fieldMapTrialInstanceInfo.getFieldMapLabels()) {

                    i++;
                    String barcodeLabel = generateBarcodeField(moreFieldInfo, fieldMapLabel, firstBarcodeField,
                            secondBarcodeField, thirdBarcodeField, barcodeNeeded);
                    if ("0".equalsIgnoreCase(barcodeNeeded)) {
                        barcodeLabel = " ";
                    }

                    BitMatrix bitMatrix = new Code128Writer().encode(barcodeLabel, BarcodeFormat.CODE_128,
                            width, height, null);
                    String imageLocation = System.getProperty("user.home") + "/" + Math.random() + ".png";
                    File imageFile = new File(imageLocation);
                    FileOutputStream fout = new FileOutputStream(imageFile);
                    MatrixToImageWriter.writeToStream(bitMatrix, "png", fout);
                    filesToBeDeleted.add(imageFile);

                    Image mainImage = Image.getInstance(imageLocation);

                    PdfPCell cell = new PdfPCell();
                    cell.setFixedHeight(cellHeight);
                    cell.setNoWrap(false);
                    cell.setPadding(5f);
                    cell.setPaddingBottom(1f);

                    PdfPTable innerImageTableInfo = new PdfPTable(1);
                    innerImageTableInfo.setWidths(new float[] { 1 });
                    innerImageTableInfo.setWidthPercentage(82);
                    PdfPCell cellImage = new PdfPCell();
                    if ("1".equalsIgnoreCase(barcodeNeeded)) {
                        cellImage.addElement(mainImage);
                    } else {
                        cellImage.addElement(new Paragraph(" "));
                    }
                    cellImage.setBorder(Rectangle.NO_BORDER);
                    cellImage.setBackgroundColor(Color.white);
                    cellImage.setPadding(1.5f);

                    innerImageTableInfo.addCell(cellImage);

                    //float fontSize = 6.8f;
                    float fontSize = paper.getFontSize();
                    //if (numberofRowsPerPageOfLabel == 10)
                    //    fontSize = 4.8f;

                    Font fontNormal = FontFactory.getFont("Arial", fontSize, Font.NORMAL);

                    // cell.addElement(mainImage);
                    cell.addElement(innerImageTableInfo);

                    cell.addElement(new Paragraph());
                    for (int row = 0; row < 5; row++) {
                        if (row == 0) {
                            PdfPTable innerDataTableInfo = new PdfPTable(1);
                            innerDataTableInfo.setWidths(new float[] { 1 });
                            innerDataTableInfo.setWidthPercentage(85);

                            Font fontNormalData = FontFactory.getFont("Arial", 5.0f, Font.NORMAL);
                            PdfPCell cellInnerData = new PdfPCell(new Phrase(barcodeLabel, fontNormalData));

                            cellInnerData.setBorder(Rectangle.NO_BORDER);
                            cellInnerData.setBackgroundColor(Color.white);
                            cellInnerData.setPaddingBottom(0.2f);
                            cellInnerData.setPaddingTop(0.2f);
                            cellInnerData.setHorizontalAlignment(Element.ALIGN_MIDDLE);

                            innerDataTableInfo.addCell(cellInnerData);
                            innerDataTableInfo.setHorizontalAlignment(Element.ALIGN_MIDDLE);
                            cell.addElement(innerDataTableInfo);
                        }
                        PdfPTable innerTableInfo = new PdfPTable(2);
                        innerTableInfo.setWidths(new float[] { 1, 1 });
                        innerTableInfo.setWidthPercentage(85);

                        String leftText = generateBarcodeLabel(moreFieldInfo, fieldMapLabel, leftSelectedFields,
                                row);
                        PdfPCell cellInnerLeft = new PdfPCell(new Paragraph(leftText, fontNormal));

                        cellInnerLeft.setBorder(Rectangle.NO_BORDER);
                        cellInnerLeft.setBackgroundColor(Color.white);
                        cellInnerLeft.setPaddingBottom(0.5f);
                        cellInnerLeft.setPaddingTop(0.5f);

                        innerTableInfo.addCell(cellInnerLeft);

                        String rightText = generateBarcodeLabel(moreFieldInfo, fieldMapLabel,
                                rightSelectedFields, row);
                        PdfPCell cellInnerRight = new PdfPCell(new Paragraph(rightText, fontNormal));

                        cellInnerRight.setBorder(Rectangle.NO_BORDER);
                        cellInnerRight.setBackgroundColor(Color.white);
                        cellInnerRight.setPaddingBottom(0.5f);
                        cellInnerRight.setPaddingTop(0.5f);

                        innerTableInfo.addCell(cellInnerRight);

                        cell.addElement(innerTableInfo);
                    }

                    cell.setBorder(Rectangle.NO_BORDER);
                    cell.setBackgroundColor(Color.white);

                    //cell.setBorderColor(Color.BLUE);

                    table.addCell(cell);

                    if (i % numberOfLabelPerRow == 0) {
                        // we go the next line

                        int needed = fixTableRowSize - numberOfLabelPerRow;

                        for (int neededCount = 0; neededCount < needed; neededCount++) {
                            PdfPCell cellNeeded = new PdfPCell();

                            cellNeeded.setBorder(Rectangle.NO_BORDER);
                            cellNeeded.setBackgroundColor(Color.white);

                            table.addCell(cellNeeded);
                        }

                        table.completeRow();
                        if (numberofRowsPerPageOfLabel == 10) {

                            //table.setSpacingAfter(9f);
                            table.setSpacingAfter(paper.getSpacingAfter());
                        }

                        document.add(table);

                        table = new PdfPTable(fixTableRowSize);
                        table.setWidths(widthColumns);
                        table.setWidthPercentage(100);

                    }
                    if (i % totalPerPage == 0) {
                        // we go the next page
                        document.newPage();
                    }
                    fout.flush();
                    fout.close();

                }
            }
            // we need to add the last row
            if (i % numberOfLabelPerRow != 0) {
                // we go the next line

                int needed = fixTableRowSize - numberOfLabelPerRow;
                int remaining = numberOfLabelPerRow - (i % numberOfLabelPerRow);
                for (int neededCount = 0; neededCount < remaining; neededCount++) {
                    PdfPCell cellNeeded = new PdfPCell();

                    cellNeeded.setBorder(Rectangle.NO_BORDER);
                    cellNeeded.setBackgroundColor(Color.white);

                    table.addCell(cellNeeded);
                }

                table.completeRow();
                if (numberofRowsPerPageOfLabel == 10) {

                    table.setSpacingAfter(paper.getSpacingAfter());
                }

                document.add(table);

                table = new PdfPTable(fixTableRowSize);
                table.setWidths(widthColumns);
                table.setWidthPercentage(100);

            }

            document.close();
            for (File file : filesToBeDeleted) {
                file.delete();
            }
            fileOutputStream.close();

        } catch (FileNotFoundException e) {
            LOG.error(e.getMessage(), e);
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }

    } catch (WriterException e) {
        LOG.error(e.getMessage(), e);
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return fileName;
}

From source file:com.geek.tutorial.itext.acroform.TextFieldForm.java

License:Open Source License

public TextFieldForm() throws Exception {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("TextFieldForm.pdf"));
    document.open();/* w ww .java 2s. co  m*/

    PdfPTable table = new PdfPTable(2);
    table.getDefaultCell().setPadding(5f); // Code 1, will only affect empty field
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    PdfPCell cell;

    // Code 2, add name TextField      
    table.addCell("Name");
    TextField nameField = new TextField(writer, new Rectangle(0, 0, 200, 10), "nameField");
    nameField.setBackgroundColor(Color.WHITE);
    nameField.setBorderColor(Color.BLACK);
    nameField.setBorderWidth(1);
    nameField.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
    nameField.setText("");
    nameField.setAlignment(Element.ALIGN_LEFT);
    nameField.setOptions(TextField.REQUIRED);
    cell = new PdfPCell();
    cell.setMinimumHeight(10);
    cell.setCellEvent(new FieldCell(nameField.getTextField(), 200, writer));
    table.addCell(cell);

    // force upper case javascript
    writer.addJavaScript("var nameField = this.getField('nameField');" + "nameField.setAction('Keystroke',"
            + "'forceUpperCase()');" + "" + "function forceUpperCase(){"
            + "if(!event.willCommit)event.change = " + "event.change.toUpperCase();" + "}");

    // Code 3, add empty row
    table.addCell("");
    table.addCell("");

    // Code 4, add age TextField
    table.addCell("Age");
    TextField ageComb = new TextField(writer, new Rectangle(0, 0, 30, 10), "ageField");
    ageComb.setBorderColor(Color.BLACK);
    ageComb.setBorderWidth(1);
    ageComb.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
    ageComb.setText("12");
    ageComb.setAlignment(Element.ALIGN_RIGHT);
    ageComb.setMaxCharacterLength(2);
    ageComb.setOptions(TextField.COMB | TextField.DO_NOT_SCROLL);
    cell = new PdfPCell();
    cell.setMinimumHeight(10);
    cell.setCellEvent(new FieldCell(ageComb.getTextField(), 30, writer));
    table.addCell(cell);

    // validate age javascript
    writer.addJavaScript("var ageField = this.getField('ageField');"
            + "ageField.setAction('Validate','checkAge()');" + "function checkAge(){" + "if(event.value < 12){"
            + "app.alert('Warning! Applicant\\'s age can not" + " be younger than 12.');" + "event.value = 12;"
            + "}}");

    // add empty row
    table.addCell("");
    table.addCell("");

    // Code 5, add age TextField
    table.addCell("Comment");
    TextField comment = new TextField(writer, new Rectangle(0, 0, 200, 100), "commentField");
    comment.setBorderColor(Color.BLACK);
    comment.setBorderWidth(1);
    comment.setBorderStyle(PdfBorderDictionary.STYLE_SOLID);
    comment.setText("");
    comment.setOptions(TextField.MULTILINE | TextField.DO_NOT_SCROLL);
    cell = new PdfPCell();
    cell.setMinimumHeight(100);
    cell.setCellEvent(new FieldCell(comment.getTextField(), 200, writer));
    table.addCell(cell);

    // check comment characters length javascript
    writer.addJavaScript("var commentField = " + "this.getField('commentField');" + "commentField"
            + ".setAction('Keystroke','checkLength()');" + "function checkLength(){"
            + "if(!event.willCommit && " + "event.value.length > 100){" + "app.alert('Warning! Comment can not "
            + "be more than 100 characters.');" + "event.change = '';" + "}}");

    // add empty row
    table.addCell("");
    table.addCell("");

    // Code 6, add submit button   
    PushbuttonField submitBtn = new PushbuttonField(writer, new Rectangle(0, 0, 35, 15), "submitPOST");
    submitBtn.setBackgroundColor(Color.GRAY);
    submitBtn.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
    submitBtn.setText("POST");
    submitBtn.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);
    PdfFormField submitField = submitBtn.getField();
    submitField.setAction(PdfAction.createSubmitForm("http://www.geek-tutorials.com/java/itext/submit.php",
            null, PdfAction.SUBMIT_HTML_FORMAT));
    cell = new PdfPCell();
    cell.setMinimumHeight(15);
    cell.setCellEvent(new FieldCell(submitField, 35, writer));
    table.addCell(cell);

    // Code 7, add reset button
    PushbuttonField resetBtn = new PushbuttonField(writer, new Rectangle(0, 0, 35, 15), "reset");
    resetBtn.setBackgroundColor(Color.GRAY);
    resetBtn.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED);
    resetBtn.setText("RESET");
    resetBtn.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT);
    PdfFormField resetField = resetBtn.getField();
    resetField.setAction(PdfAction.createResetForm(null, 0));
    cell = new PdfPCell();
    cell.setMinimumHeight(15);
    cell.setCellEvent(new FieldCell(resetField, 35, writer));
    table.addCell(cell);

    document.add(table);
    document.close();
}