List of usage examples for com.lowagie.text Document add
public boolean add(Element element) throws DocumentException
Element
to the Document
. 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 va 2s . 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("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);//from w w w . java 2 s . 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("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 a 2 s . 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("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);/*from w w 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("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);//ww w . 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("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);// w w w .ja v a 2 s . 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("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);//w w w . j av a 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("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 w w w. j ava 2s. 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("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.crm.webapp.util.PDFCustomExporter.java
License:Apache License
@Override public void export(ActionEvent event, String tableId, FacesContext context, String filename, String tableTitle, boolean pageOnly, boolean selectionOnly, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor, boolean subTable) throws IOException { try {// w ww.j av a 2s .co m Document document = new Document(); if (orientation.equalsIgnoreCase("Landscape")) { document.setPageSize(PageSize.A4.rotate()); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); StringTokenizer st = new StringTokenizer(tableId, ","); while (st.hasMoreElements()) { String tableName = (String) st.nextElement(); UIComponent component = SearchExpressionFacade.resolveComponent(context, event.getComponent(), tableName); if (component == null) { throw new FacesException("Cannot find component \"" + tableName + "\" in view."); } if (!(component instanceof DataTable || component instanceof DataList)) { throw new FacesException("Unsupported datasource target:\"" + component.getClass().getName() + "\", exporter must target a PrimeFaces DataTable/DataList."); } if (preProcessor != null) { preProcessor.invoke(context.getELContext(), new Object[] { document }); } if (!document.isOpen()) { document.open(); } if (tableTitle != null && !tableTitle.isEmpty() && !tableId.contains("" + ",")) { Font tableTitleFont = FontFactory.getFont(FontFactory.TIMES, encodingType, Font.DEFAULTSIZE, Font.BOLD); Paragraph title = new Paragraph(tableTitle, tableTitleFont); document.add(title); Paragraph preface = new Paragraph(); addEmptyLine(preface, 3); document.add(preface); } PdfPTable pdf; DataList list = null; DataTable table = null; if (component instanceof DataList) { list = (DataList) component; pdf = exportPDFTable(context, list, pageOnly, encodingType); } else { table = (DataTable) component; pdf = exportPDFTable(context, table, pageOnly, selectionOnly, encodingType, subTable); } if (pdf != null) { document.add(pdf); } // add a couple of blank lines Paragraph preface = new Paragraph(); addEmptyLine(preface, datasetPadding); document.add(preface); if (postProcessor != null) { postProcessor.invoke(context.getELContext(), new Object[] { document }); } } document.close(); writePDFToResponse(context.getExternalContext(), baos, filename); } catch (DocumentException e) { throw new IOException(e.getMessage()); } }
From source file:com.efficio.fieldbook.service.LabelPrintingServiceImpl.java
License:Open Source License
/** * Gets the cell height./* www . j a va2s.com*/ * * @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; }