List of usage examples for com.lowagie.text.pdf PdfPCell setColspan
public void setColspan(int colspan)
From source file:pruebareportes.rptTardC.java
public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin) throws DocumentException { /**/*from w w w .jav a2 s . com*/ * Procesamiento para info para generar tablas */ List<RegistroAsistencia> registros = rg.buscarXEmpleadoXFecha1(dnis, fechaInicio, fechaFin); Calendar fechaInicioC = Calendar.getInstance(); Calendar fechaFinC = Calendar.getInstance(); fechaInicioC.setTime(fechaInicio); fechaFinC.setTime(fechaFin); int diaMesInicio, diaMesFin; diaMesInicio = fechaInicioC.get(Calendar.DAY_OF_MONTH); diaMesFin = fechaFinC.get(Calendar.DAY_OF_MONTH); //Definir numero de columnas de dias ArrayList<Integer> listaInt = new ArrayList<Integer>(); Calendar fechaRegistro = Calendar.getInstance(); for (RegistroAsistencia registro : registros) { fechaRegistro.setTime(registro.getFecha()); Integer diaRegistro = fechaRegistro.get(Calendar.DAY_OF_MONTH); if (listaInt.contains(diaRegistro) != true) { if (diaRegistro >= diaMesInicio && diaRegistro <= diaMesFin) { listaInt.add(diaRegistro); } } } //Ordenamos arraylist int indice, menor, aux; for (int i = 0; i < listaInt.size(); i++) { menor = listaInt.get(i); indice = i; aux = 0; for (int j = i + 1; j < listaInt.size(); j++) { aux = listaInt.get(j); indice = aux < menor ? j : indice; menor = aux < menor ? aux : menor; } listaInt.set(indice, listaInt.get(i)); listaInt.set(i, menor); } /** * Procesamiento para elaborar tabla con datos */ int nroColumnas = listaInt.size() + 2; PdfPTable tabla = new PdfPTable(nroColumnas); tabla.setWidthPercentage(100); //Asignamos los tamaos a las columnas int[] widthColumna = new int[nroColumnas]; for (int i = 0; i < nroColumnas; i++) { if (i == 0) { widthColumna[i] = 6; } else if (i == (nroColumnas - 1)) { widthColumna[i] = 2; } else { widthColumna[i] = 1; } } tabla.setWidths(widthColumna); //Definimos celdas iniciales Font fontCabecera = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); Font fontCelda = new Font(Font.TIMES_ROMAN, 9); PdfPCell h1 = new PdfPCell(new Phrase("Nombre del empleado", fontCabecera)); h1.setHorizontalAlignment(3); h1.setGrayFill(0.7f); h1.setRowspan(2); h1.setColspan(1); tabla.addCell(h1); PdfPCell h2 = new PdfPCell(new Phrase("Das Hbiles", fontCabecera)); h2.setHorizontalAlignment(1); h2.setGrayFill(0.7f); h2.setColspan(nroColumnas - 2); tabla.addCell(h2); PdfPCell h3 = new PdfPCell(new Phrase("Total (minutos)", fontCabecera)); h3.setHorizontalAlignment(3); h3.setGrayFill(0.7f); h3.setColspan(1); h3.setRowspan(2); tabla.addCell(h3); PdfPCell diaColumna = new PdfPCell(); for (int i = 0; i < (nroColumnas - 2); i++) { String celda = (listaInt.get(i).toString()); diaColumna.setPhrase(new Phrase(celda, fontCabecera)); diaColumna.setHorizontalAlignment(1); tabla.addCell(diaColumna); } Calendar cal = Calendar.getInstance(); List<Integer> conteoDias = new ArrayList<Integer>(); for (int i = 0; i < dnis.size(); i++) { List<Empleado> listaEmpleado = new ArrayList<Empleado>(); listaEmpleado = em.buscarXPatron(dnis.get(i)); Empleado empleado = new Empleado(); empleado = listaEmpleado.get(0); BigDecimal totalTardanza = new BigDecimal(0.00); PdfPCell celdaNombre = new PdfPCell(new Phrase(empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno() + " " + empleado.getNombre(), fontCelda)); celdaNombre.setHorizontalAlignment(0); tabla.addCell(celdaNombre); List<RegistroAsistencia> registrosDni = rg.buscarXEmpleadoXFecha2(dnis.get(i), fechaInicio, fechaFin); System.out.println("Numero de registros: " + registrosDni.size()); if (!registrosDni.isEmpty()) { } for (RegistroAsistencia registro : registrosDni) { cal.setTime(registro.getFecha()); for (int j = 0; j < listaInt.size(); j++) { if (cal.get(Calendar.DAY_OF_MONTH) == listaInt.get(j)) { if (registro.getMinTardanza() != null) { int numero = registro.getMinTardanza().intValue(); String celda = "" + numero; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); totalTardanza = totalTardanza.add(registro.getMinTardanza()); } else { String celda = "0.0"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } conteoDias.add(listaInt.get(j)); break; } else { if (conteoDias.contains(listaInt.get(j))) { } else { String celda = "n.r"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); conteoDias.add(listaInt.get(j)); } } } } if (registrosDni.size() < (nroColumnas - 2)) { int dfNumRegistros = (nroColumnas - 2) - registrosDni.size(); for (int j = 0; j < dfNumRegistros; j++) { String celda = "n.r"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } } System.out.println("ConteoDias: " + conteoDias.size()); System.out.println("Total tardanzas: " + totalTardanza); conteoDias.clear(); String tardanzaTotal = totalTardanza.toString(); celdaNombre.setPhrase(new Phrase(tardanzaTotal, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } return tabla; }
From source file:pruebareportes.rptTardCx.java
public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin) throws DocumentException { /**//from w w w .j a v a 2 s . co m * Procesamiento para info para generar tablas */ //List<RegistroAsistencia> registros = rg.buscarXEmpleadoXFecha1(dnis, fechaInicio, fechaFin); Calendar fechaInicioC = Calendar.getInstance(); Calendar fechaFinC = Calendar.getInstance(); fechaInicioC.setTime(fechaInicio); fechaFinC.setTime(fechaFin); int diaMesInicio, diaMesFin; diaMesInicio = fechaInicioC.get(Calendar.DAY_OF_MONTH); diaMesFin = fechaFinC.get(Calendar.DAY_OF_MONTH); // Dias contados desde un inicio y fin fecha ArrayList<Integer> listaInt = new ArrayList<>(); for (int i = diaMesInicio; i <= diaMesFin; i++) { listaInt.add(i); } //Ordenamos arraylist int indice, menor, aux; for (int i = 0; i < listaInt.size(); i++) { menor = listaInt.get(i); indice = i; aux = 0; for (int j = i + 1; j < listaInt.size(); j++) { aux = listaInt.get(j); indice = aux < menor ? j : indice; menor = aux < menor ? aux : menor; } listaInt.set(indice, listaInt.get(i)); listaInt.set(i, menor); } /** * Procesamiento para elaborar tabla con datos */ //agrege una columna mas (Descuento sin goce) int nroColumnas = listaInt.size() + 3; PdfPTable tabla = new PdfPTable(nroColumnas); tabla.setWidthPercentage(100); //Asignamos los tamaos a las columnas //MOdifique para tomar en cuenta la nueva columna de dewscuento int[] widthColumna = new int[nroColumnas]; for (int i = 0; i < nroColumnas; i++) { if (i == 0) { widthColumna[i] = 6; } else if (i == (nroColumnas - 1) || i == (nroColumnas - 2)) { widthColumna[i] = 2; } else { widthColumna[i] = 1; } } tabla.setWidths(widthColumna); //Definimos celdas iniciales Font fontCabecera = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); Font fontCelda = new Font(Font.TIMES_ROMAN, 9); PdfPCell h1 = new PdfPCell(new Phrase("Nombre del empleado", fontCabecera)); h1.setHorizontalAlignment(3); h1.setGrayFill(0.7f); h1.setRowspan(2); h1.setColspan(1); tabla.addCell(h1); PdfPCell h2 = new PdfPCell(new Phrase("Das Hbiles", fontCabecera)); h2.setHorizontalAlignment(1); h2.setGrayFill(0.7f); h2.setColspan(nroColumnas - 3); tabla.addCell(h2); PdfPCell h3 = new PdfPCell(new Phrase("Total (minutos)", fontCabecera)); h3.setHorizontalAlignment(3); h3.setGrayFill(0.7f); h3.setColspan(1); h3.setRowspan(2); tabla.addCell(h3); //Agregado de columna de descuento sin goce PdfPCell h4 = new PdfPCell(new Phrase("Descuento S/G", fontCabecera)); h4.setHorizontalAlignment(3); h4.setGrayFill(0.7f); h4.setColspan(1); h4.setRowspan(2); tabla.addCell(h4); PdfPCell diaColumna = new PdfPCell(); for (int i = 0; i < (nroColumnas - 3); i++) { String celda = (listaInt.get(i).toString()); diaColumna.setPhrase(new Phrase(celda, fontCabecera)); diaColumna.setHorizontalAlignment(1); tabla.addCell(diaColumna); } Calendar cal = Calendar.getInstance(); List<Integer> conteoDias = new ArrayList<>(); int diasDescuento = 0; double minDescuento = 0; for (int i = 0; i < dnis.size(); i++) { List<Empleado> listaEmpleado = new ArrayList<>(); listaEmpleado = em.buscarXPatron(dnis.get(i)); Empleado empleado; empleado = listaEmpleado.get(0); BigDecimal totalTardanza = new BigDecimal(0.00); PdfPCell celdaNombre = new PdfPCell(new Phrase(empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno() + " " + empleado.getNombre(), fontCelda)); celdaNombre.setHorizontalAlignment(0); tabla.addCell(celdaNombre); List<RegistroAsistencia> registrosDni = rg.buscarXEmpleadoXFecha2(dnis.get(i), fechaInicio, fechaFin); System.out.println( "Numero de registros: " + registrosDni.size() + " Empleado: " + empleado.getApellidoPaterno() + " " + empleado.getApellidoPaterno() + " " + empleado.getNombre()); List<Integer> listaPermisos = new ArrayList<>(); if (!registrosDni.isEmpty()) { for (RegistroAsistencia registro : registrosDni) { //========================DESCUENTOS LICENCIAS================================================= AsignacionPermiso asignaciones = asp.buscarXDia(empleado.getNroDocumento(), registro.getFecha()); if (asignaciones != null) { System.out.println("Asignacion: " + asignaciones.getPermiso().toString()); Permiso permisoProcesar = asignaciones.getPermiso(); System.out.println("Tiene un permiso" + permisoProcesar.getMotivo()); if (permisoProcesar.getTipoPermiso().getTipoDescuento() == 'S') { if (permisoProcesar.getOpcion() == 'F') { if (!listaPermisos.contains(permisoProcesar.getId().intValue())) { Date fechaInicio1 = permisoProcesar.getFechaInicio(); Date fechaFin1 = permisoProcesar.getFechaFin(); if (fechaInicio1.compareTo(fechaFin1) < 0) { cal.setTime(fechaInicio1); int diaInicio = cal.get(Calendar.DAY_OF_MONTH); cal.setTime(fechaFin1); int diaFin = cal.get(Calendar.DAY_OF_MONTH); diasDescuento += diaFin - diaInicio + 1; } else if (fechaInicio1.compareTo(fechaFin1) == 0) { diasDescuento = 1; } listaPermisos.add(permisoProcesar.getId().intValue()); } } else { if (permisoProcesar.getOpcion() == 'H') { Date horaInicio1 = permisoProcesar.getHoraInicio(); Date horaFin1 = permisoProcesar.getHoraFin(); if (horaInicio1.compareTo(horaFin1) < 0) { minDescuento = permisoProcesar.getHoraFin().getTime() - permisoProcesar.getHoraInicio().getTime(); } } } } } else { System.out.println("No hay registros"); } //========================DESCUENTOS LICENCIAS================================================= cal.setTime(registro.getFecha()); for (int j = 0; j < listaInt.size(); j++) { if (cal.get(Calendar.DAY_OF_MONTH) == listaInt.get(j)) { if (registro.getMinTardanza() != null) { int numero = registro.getMinTardanza().intValue(); String celda = "" + numero; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); totalTardanza = totalTardanza.add(registro.getMinTardanza()); } else { String celda = "0.0"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } conteoDias.add(listaInt.get(j)); break; } else { if (conteoDias.contains(listaInt.get(j))) { } else { String celda = "n.r"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); conteoDias.add(listaInt.get(j)); } } } } } else { for (Integer dia : listaInt) { String celda = "n.r"; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } } System.out.println("ConteoDias: " + conteoDias.size()); System.out.println("Total tardanzas: " + totalTardanza); conteoDias.clear(); //String tardanzaTotal = totalTardanza.toString(); String hora1 = ""; if (totalTardanza.intValue() < 60) { hora1 = totalTardanza.intValue() + " min"; } else if (totalTardanza.intValue() >= 60 && totalTardanza.intValue() < 480) { int resto = totalTardanza.intValue() % 60; int totalH = (totalTardanza.intValue() - resto) / 60; hora1 = totalH + " h " + resto + " min"; } else if (totalTardanza.intValue() >= 480) { int restoHoras = totalTardanza.intValue() % 480; int totalD = (totalTardanza.intValue() - restoHoras) / 480; int restoMinutos = restoHoras % 60; int totalH = (restoHoras - restoMinutos) / 60; hora1 = totalD + " d " + totalH + " h " + restoMinutos + " m"; } celdaNombre.setPhrase(new Phrase(hora1, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); //Descuento int minutosT = diasDescuento * 480; int minutosTotal = (int) (minutosT + minDescuento); String hora = ""; if (minutosTotal < 60) { hora = minutosTotal + " min"; } else if (minutosTotal >= 60 && minutosTotal < 480) { int resto = minutosTotal % 60; int totalH = (minutosTotal - resto) / 60; hora = totalH + " h " + resto + " min"; } else if (minutosTotal >= 480) { int restoHoras = minutosTotal % 480; int totalD = (minutosTotal - restoHoras) / 480; int restoMinutos = restoHoras % 60; int totalH = (restoHoras - restoMinutos) / 60; hora = totalD + " d " + totalH + " h " + restoMinutos + " m"; } celdaNombre.setPhrase(new Phrase(hora, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } return tabla; }
From source file:questions.tables.AutomaticExtensionOfTables.java
public static void createPdf(int rows) throws IOException, DocumentException { Document document = new Document(PageSize.LETTER); PdfWriter.getInstance(document, new FileOutputStream(RESULT[rows])); document.open();/*from ww w . ja v a 2 s .co m*/ PdfPTable outer = new PdfPTable(2); outer.setExtendLastRow(true); PdfPTable inner1 = new PdfPTable(5); for (int i = 0; i < ROWS[rows]; i++) { inner1.addCell("A" + i); inner1.addCell("B" + i); inner1.addCell("C" + i); inner1.addCell("D" + i); inner1.addCell("E" + i); } PdfPCell cell = new PdfPCell(inner1); cell.setColspan(2); outer.addCell(cell); PdfPTable inner2 = new PdfPTable(5); for (int i = 0; i < 20; i++) { inner2.addCell("testA"); } outer.addCell(inner2); PdfPTable inner3 = new PdfPTable(3); for (int i = 0; i < 20; i++) { inner3.addCell("testB"); } outer.addCell(inner3); document.add(outer); document.close(); }
From source file:questions.tables.TableHeaderAlternateBackground.java
public static void main(String[] args) { // step 1: creation of a document-object Document document = new Document(PageSize.A4.rotate()); try {/* ww w . j a v a2s . co m*/ // step 2: // we create a writer PdfWriter.getInstance( // that listens to the document document, // and directs a PDF-stream to a file new FileOutputStream(RESULT)); // step 3: we open the document document.open(); // step 4: we add a table to the document PdfPTable datatable = new PdfPTable(10); datatable.setTableEvent(new AlternateBackground()); int headerwidths[] = { 10, 24, 12, 12, 7, 7, 7, 7, 7, 7 }; datatable.setWidths(headerwidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(5); // The header starts with a cell that spans 10 columns PdfPCell cell = new PdfPCell(new Phrase("Administration - System Users Report", FontFactory.getFont(FontFactory.HELVETICA, 24, Font.BOLD))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidth(2); cell.setColspan(10); cell.setBackgroundColor(Color.YELLOW); cell.setUseDescender(true); datatable.addCell(cell); // We need 4 cells with rowspan 2 datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setBackgroundColor(Color.YELLOW); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell("User Id"); datatable.addCell("Name\nAddress"); datatable.addCell("Company"); datatable.addCell("Department"); datatable.getDefaultCell().setBackgroundColor(null); // we use a nested table to fake this PdfPTable permissions = new PdfPTable(6); permissions.getDefaultCell().setBackgroundColor(Color.YELLOW); permissions.getDefaultCell().setBorderWidth(2); permissions.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); permissions.getDefaultCell().setColspan(6); permissions.addCell("Permissions"); permissions.getDefaultCell().setColspan(1); permissions.addCell("Admin"); permissions.addCell("Data"); permissions.addCell("Expl"); permissions.addCell("Prod"); permissions.addCell("Proj"); permissions.addCell("Online"); PdfPCell permission = new PdfPCell(permissions); permission.setColspan(6); datatable.addCell(permission); // this is the end of the table header // as far as PdfPTable is concerned there are 2 rows in the header datatable.setHeaderRows(2); // we add the data to the table datatable.getDefaultCell().setBorderWidth(1); for (int i = 1; i < 50; i++) { datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell("myUserId"); datatable.addCell("Person " + i); datatable.addCell("No Name Company"); datatable.addCell("D" + i); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); for (int j = 0; j < 6; j++) datatable.addCell(Math.random() > .5 ? "Yes" : "No"); } document.add(datatable); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5: we close the document document.close(); }
From source file:recite18th.controller.Controller.java
License:Open Source License
public void print(String action) { /** thanks to http://www.java2s.com/Code/Java/PDF-RTF/DemonstratesthecreatingPDFinportraitlandscape.htm * QUICK FIX : do landscape//from w ww . j av a 2 s . c o m */ response.setContentType("application/pdf"); // Code 1 if (action.equals("download")) { response.setHeader("Content-Transfer-Encoding", "binary"); response.setHeader("Content-Disposition", "attachment; filename=\"" + "Report " + controllerName + ".pdf\""); } Document document = new Document(PageSize.A1.rotate()); try { PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // Code 2 document.open(); // various fonts BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false); BaseFont bf_times = BaseFont.createFont(BaseFont.TIMES_ROMAN, "Cp1252", false); BaseFont bf_courier = BaseFont.createFont(BaseFont.COURIER, "Cp1252", false); BaseFont bf_symbol = BaseFont.createFont(BaseFont.SYMBOL, "Cp1252", false); String headerImage = Config.base_path + "images/report-logo.gif"; Image imghead = Image.getInstance(headerImage); imghead.setAbsolutePosition(0, 0); PdfContentByte cbhead = writer.getDirectContent(); PdfTemplate tpLogo = cbhead.createTemplate(600, 300); tpLogo.addImage(imghead); PdfTemplate tpTitle = cbhead.createTemplate(1100, 300); String txtHeader = "BADAN KEPEGAWAIAN DAERAH PEMERINTAH DAERAH";//Config.application_title; tpTitle.beginText(); tpTitle.setFontAndSize(bf_times, 36); tpTitle.showText(txtHeader); tpTitle.endText(); PdfTemplate tpTitle2 = cbhead.createTemplate(900, 300); String txtHeader2 = " KABUPATEN BANTUL YOGYAKARTA"; tpTitle2.beginText(); tpTitle2.setFontAndSize(bf_times, 36); tpTitle2.showText(txtHeader2); tpTitle2.endText(); PdfTemplate tpAlamat = cbhead.createTemplate(1000, 400); tpAlamat.beginText(); tpAlamat.setFontAndSize(bf_times, 24); tpAlamat.showText( "Alamat : Jln. R. W. Monginsidi No. 01 Kompleks Parasamya Bantul, Telp. (0274) 367509"); tpAlamat.endText(); DateFormat df = new SimpleDateFormat("dd MMM yyyy"); java.util.Date dt = new java.util.Date(); PdfTemplate tp3 = cbhead.createTemplate(600, 300); tp3.beginText(); tp3.setFontAndSize(bf_times, 16); tp3.showText("Tanggal : " + df.format(dt)); tp3.endText(); cbhead.addTemplate(tpLogo, 800, 1500);//logo cbhead.addTemplate(tpTitle, 1000, 1580); cbhead.addTemplate(tpTitle2, 1000, 1540); cbhead.addTemplate(tpAlamat, 1000, 1500);//alamat cbhead.addTemplate(tp3, 270, 1500);//tanggal HeaderFooter header = new HeaderFooter(new Phrase(cbhead + "", new Font(bf_helv)), false); header.setAlignment(Element.ALIGN_CENTER); document.setHeader(header); //PdfContentByte cb = writer.getDirectContent(); Paragraph par = new Paragraph( "\n\n\n\n\n\n\nLAPORAN DATA SELURUH " + controllerName.toUpperCase() + "\n"); par.getFont().setStyle(Font.BOLD); par.getFont().setSize(18); par.setAlignment("center"); document.add(par); document.add(new Paragraph("\n\n")); // get data initSqlViewDataPerPage(); if (sqlViewDataPerPageForReport == null) { sqlViewDataPerPageForReport = sqlViewDataPerPage; } PreparedStatement pstmt = Db.getCon().prepareStatement(sqlViewDataPerPageForReport, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet resultSet = pstmt.executeQuery(); ResultSetMetaData metaColumn = resultSet.getMetaData(); int nColoumn = metaColumn.getColumnCount(); // thanks to set cell width http://www.jexp.ru/index.php/Java/PDF_RTF/Table_Cell_Size#Setting_Cell_Widths if (nColoumn > 0) { Model model = initModel(); String tableName = model.getTableName(); // create table header // float[] widths = {1, 4}; PdfPTable table;// = new PdfPTable(nColoumn); PdfPCell cell = new PdfPCell(new Paragraph("Daftar " + controllerName)); Hashtable hashModel = TableCustomization.getTable(model.getTableName()); int ncolumnHeader = nColoumn + 1; // +1 because of row. number if (hashModel != null) { ncolumnHeader = Integer.parseInt("" + hashModel.get("columnCount")) + 1; } table = new PdfPTable(ncolumnHeader); cell.setColspan(ncolumnHeader); cell.setHorizontalAlignment(Element.ALIGN_CENTER); Paragraph p2 = new Paragraph("No."); p2.getFont().setSize(20); PdfPCell cellColNo = new PdfPCell(p2); cellColNo.setNoWrap(true); cellColNo.setMinimumHeight(50); cellColNo.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellColNo); if (hashModel != null) { Enumeration k = hashModel.keys(); while (k.hasMoreElements()) { String key = (String) k.nextElement(); if (key.equals("columnCount")) { continue; } PdfPCell cellCol = new PdfPCell(new Paragraph(hashModel.get(key) + "")); cellCol.setNoWrap(true); cellCol.setMinimumHeight(50); cellCol.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellCol); } } else { for (int i = 1; i < ncolumnHeader; i++) { System.out.println("DATA = " + metaColumn.getColumnName(i)); Paragraph p1 = new Paragraph(metaColumn.getColumnName(i) + ""); p1.getFont().setSize(20); PdfPCell cellCol = new PdfPCell(p1); cellCol.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellCol); } } //iterate all columns : table data resultSet.beforeFirst(); int row = 1; while (resultSet.next()) { System.out.println(row); Paragraph p3 = new Paragraph(row + ""); p3.getFont().setSize(20); cell = new PdfPCell(p3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); if (hashModel != null) {//skip dulu u/ kasus ga pny class kustomasi table Enumeration k = hashModel.keys(); while (k.hasMoreElements()) { String key = (String) k.nextElement(); if (key.equals("columnCount")) { continue; } table.addCell(resultSet.getObject(key) + ""); } } else { for (int i = 1; i < ncolumnHeader; i++) { System.out.println("DATA = " + metaColumn.getColumnName(i)); Paragraph p1 = new Paragraph(resultSet.getObject(metaColumn.getColumnName(i)) + ""); p1.getFont().setSize(18); PdfPCell cellCol = new PdfPCell(p1); cellCol.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellCol); } } row++; } document.add(table); document.add(new Paragraph("\n\n")); par = new Paragraph("Mengetahui"); par.setAlignment("center"); document.add(par); par = new Paragraph("Kepada Badan Kepegawaian"); par.setAlignment("center"); document.add(par); par = new Paragraph("\n\n\n"); document.add(par); par = new Paragraph("Drs. Maman Permana"); par.setAlignment("center"); document.add(par); par = new Paragraph("Nip: 197802042006041013"); par.setAlignment("center"); document.add(par); } document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:rollyroll.com.servlet.ModuloServlet.java
private void exportar_ModulosaPDF(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { try {/* w w w.j av a2 s. com*/ // String[] headers = new String[]{"CODIGO", "NOMBRE", "ACCION", "ORDEN", "ICONO", "ESTADO"}; String[] headers = new String[] { "NOMBRE", "ACCION", "ICONO" }; ArrayList<Modulo> lista = null; lista = moduloService.listar_Modulos(); PdfPTable table = new PdfPTable(headers.length); table.setHorizontalAlignment(0); table.setWidthPercentage(95); float[] espaciocolumna = new float[] { 25f, 38f, 50f }; table.setWidths(espaciocolumna); for (int i = 0; i < headers.length; i++) { String header = headers[i]; PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(Color.YELLOW); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setPhrase(new Phrase(header.toUpperCase(), new Font(Font.HELVETICA, 10, Font.BOLD))); table.addCell(cell); } table.completeRow(); PdfPCell cell; // int codigomodulo = 0; String nombremodulo = ""; String accionmodulo = ""; // int ordenmodulo = 0; String iconomodulo = ""; // int estadomodulo = 0; for (Modulo modulo : lista) { // codigomodulo += Integer.parseInt(modulo.getCodigomodulo()); nombremodulo += modulo.getNombremodulo(); accionmodulo += modulo.getAccionmodulo(); // ordenmodulo += Integer.parseInt(modulo.getOrdenmoduloS()); iconomodulo += modulo.getIconomodulo(); // estadomodulo += Byte.parseByte(modulo.getEstadomoduloS()); // cell = new PdfPCell(); // cell.setPhrase(new Phrase(modulo.getCodigomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL))); // cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); // table.addCell(cell); // cell = new PdfPCell(); cell.setPhrase(new Phrase(modulo.getNombremodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL))); cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(); cell.setPhrase(new Phrase(modulo.getAccionmodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL))); cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(cell); // cell = new PdfPCell(); // cell.setPhrase(new Phrase(modulo.getOrdenmoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL))); // cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); // table.addCell(cell); cell = new PdfPCell(); cell.setPhrase(new Phrase(modulo.getIconomodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL))); cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(cell); // cell = new PdfPCell(); // cell.setPhrase(new Phrase(modulo.getEstadomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL))); // cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER); // table.addCell(cell); } table.completeRow(); //incia diseo de documento exportado Document document = new Document(PageSize.A4.rotate(), 20, 5, 5, 5); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); document.addTitle("Reporte de Ventas Generales"); document.add( new Paragraph("Reporte: Ventas Generales 2016", new Font(Font.HELVETICA, 16, Font.UNDERLINE))); document.add(new Paragraph("_")); document.add(table); document.add(Chunk.NEWLINE); document.add(new Paragraph( "Leyenda: AB: Inicio, BA: Retorno (Importante: No se consideran unidades sin GPS)")); document.addAuthor("Quispe Roque Alex Christian"); table = new PdfPTable(4); table.setHorizontalAlignment(0); table.setWidthPercentage(40); espaciocolumna = new float[] { 10f, 40f, 20f, 20f }; table.setWidths(espaciocolumna); cell = new PdfPCell(); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); cell.setPhrase(new Phrase("RESUMEN", new Font(Font.HELVETICA, 10, Font.BOLD))); cell.setColspan(7); table.addCell(cell); table.completeRow(); //aqui iniciamos asignacion de datos //=================================================================== // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setBackgroundColor(Color.yellow); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("FLOTA OPERATIVA", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase(lista.size() + "", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("UNIDADES", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // table.completeRow(); // // //================================================================================== // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("2", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setBackgroundColor(Color.yellow); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("NRO DE VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase((totalAB + totalBA) + "", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); // cell.setPhrase(new Phrase("VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD))); // table.addCell(cell); // // table.completeRow(); //================================================================================== document.add(Chunk.NEWLINE); document.add(table); document.left(1); document.top(1); document.close(); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); // response.setHeader("Content-Disposition", "attachment; filename=ReporteGeneraldeModulos.pdf"); response.setHeader("Content-Disposition", "filename=ReporteGeneraldeModulos.pdf"); response.setHeader("Pragma", "public"); response.setContentType("application/pdf"); response.setContentLength(baos.size()); ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (Exception e) { RequestDispatcher rd2; rd2 = request.getRequestDispatcher("vista/include/error_404.jsp"); rd2.forward(request, response); System.out.println( "rollyroll.com.servlet.ModuloServlet.exportar_ModulosaPDF() => ERROR GRAVE AL GENERAR PDF"); e.getMessage(); } }
From source file:sms.ReportForms.java
public void utext(String query, String Name, String dob, String house, String formclass, String kcpe, String imgurl, String kcpegrade, String id) { methods nn = new methods(); String u = unig();//from w w w . j a v a 2 s .c o m checkPreviousResults(u, kcpe, kcpegrade, id); ArrayList<ExamDbDataHolder> users = selectExamResults(u, query); if (users.size() < 2) { Form1Exams n = new Form1Exams(); String[] Subjects = n.findSubjectid(); String[] Subjectsnames = n.findSubjectname(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(",")); chooser.setDialogTitle("Save at"); chooser.setApproveButtonText("save"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try { Document pdfp = new Document(); PdfWriter w = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(), "" + sid.getText() + ".pdf"))); pdfp.open(); PdfContentByte canvas = w.getDirectContentUnder(); Image imgb = Image.getInstance("C:\\Users\\kimani kogi\\Pictures\\icons\\logo.png"); imgb.setAbsolutePosition(2, 2); imgb.scaleAbsoluteHeight(PageSize.A4.getHeight() / 4); imgb.scaleAbsoluteWidth(PageSize.A4.getWidth() / 4); canvas.saveState(); PdfGState state = new PdfGState(); state.setFillOpacity(0.6f); canvas.setGState(state); canvas.addImage(imgb); canvas.restoreState(); PdfPTable tbl1 = new PdfPTable(2); // tbl.setWidthPercentage(100); tbl1.setTotalWidth(575); tbl1.setLockedWidth(true); tbl1.setWidths(new int[] { 1, 4 }); if (imgurl.equals("image")) { tbl1.addCell("no image "); String img = imgurl; } else { tbl1.addCell(createImageCell(imgurl)); } tbl1.addCell(createTextCell(schooldetails)); PdfPTable tbl = new PdfPTable(8); // tbl.setWidthPercentage(100); tbl.setTotalWidth(575); tbl.setLockedWidth(true); tbl.setSpacingBefore(8); tbl.setSpacingAfter(6); tbl.getDefaultCell().setBorderWidthTop(2); tbl.getDefaultCell().setBorderWidthLeft(0); tbl.getDefaultCell().setBorderWidthRight(0); tbl.setWidths(new int[] { 1, 1, 1, 2, 1, 1, 1, 1 }); tbl.addCell("Adm No:"); tbl.addCell(sid.getText()); tbl.addCell("Name:"); tbl.addCell(Name); tbl.addCell("Form:"); tbl.addCell(formclass); tbl.addCell("Kcpe:"); tbl.addCell(kcpe); tbl.addCell("House:"); tbl.addCell(house); tbl.addCell("Term:"); tbl.addCell("Second term"); tbl.addCell("Year:"); tbl.addCell("2017"); tbl.addCell("DOB:"); tbl.addCell(dob); PdfPTable tbl2 = new PdfPTable(5); // tbl.setWidthPercentage(100); tbl2.setTotalWidth(575); tbl2.setLockedWidth(true); // tbl2.getDefaultCell().setFixedHeight(35f); tbl2.setWidths(new int[] { 2, 1, 1, 2, 2 }); tbl2.addCell(creatTextCellHeader("Subjects")); tbl2.addCell(creatTextCellHeader("Exams")); tbl2.addCell(creatTextCellHeader("Grade")); tbl2.addCell(creatTextCellHeader("Ratings")); tbl2.addCell(creatTextCellHeader("Remarks")); // String [] Subjectsnames=n.findSubjectname(); for (int i = 0; i < users.size(); i++) { for (int a = 0; a < Subjectsnames.length; a++) { tbl2.addCell(Subjectsnames[a]); String re = null; if (Subjects[a].equals("s1")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMathematics()); re = ((ExamDbDataHolder) users.get(i)).getMathematics(); // JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics()); // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics(); } else if (Subjects[a].equals("s2")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getEnglish()); re = ((ExamDbDataHolder) users.get(i)).getEnglish(); //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish(); // c++; } else if (Subjects[a].equals("s3")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili()); re = ((ExamDbDataHolder) users.get(i)).getKiswahili(); // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili(); // c++; } else if (Subjects[a].equals("s4")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getPhysics()); re = ((ExamDbDataHolder) users.get(i)).getPhysics(); // row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics(); // c++; } else if (Subjects[a].equals("s5")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getChemistry()); re = ((ExamDbDataHolder) users.get(i)).getChemistry(); // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry(); // c++; } else if (Subjects[a].equals("s6")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBiology()); re = ((ExamDbDataHolder) users.get(i)).getBiology(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBiology(); // c++; } else if (Subjects[a].equals("s7")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHistory()); re = ((ExamDbDataHolder) users.get(i)).getHistory(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHistory(); // c++; } else if (Subjects[a].equals("s8")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getGeography()); re = ((ExamDbDataHolder) users.get(i)).getGeography(); // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography(); // c++; } else if (Subjects[a].equals("s9")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getCre()); re = ((ExamDbDataHolder) users.get(i)).getCre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getCre(); // c++; } else if (Subjects[a].equals("s10")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getIre()); re = ((ExamDbDataHolder) users.get(i)).getIre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getIre(); // c++; } else if (Subjects[a].equals("s11")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHre()); re = ((ExamDbDataHolder) users.get(i)).getHre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHre(); // c++; } else if (Subjects[a].equals("s12")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture()); re = ((ExamDbDataHolder) users.get(i)).getAgriculture(); // row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture(); // c++; } else if (Subjects[a].equals("s13")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHomescience()); re = ((ExamDbDataHolder) users.get(i)).getHomescience(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience(); // c++; } else if (Subjects[a].equals("s14")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign()); re = ((ExamDbDataHolder) users.get(i)).getArtdesign(); // row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign(); // c++; } else if (Subjects[a].equals("s15")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getComputer()); re = ((ExamDbDataHolder) users.get(i)).getComputer(); // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer(); // c++; } else if (Subjects[a].equals("s16")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBuilding()); re = ((ExamDbDataHolder) users.get(i)).getBuilding(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding(); // c++; } else if (Subjects[a].equals("s17")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork()); re = ((ExamDbDataHolder) users.get(i)).getWoodwork(); // row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork(); // c++; } else if (Subjects[a].equals("s18")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork()); re = ((ExamDbDataHolder) users.get(i)).getMetalwork(); // row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork(); // c++; } else if (Subjects[a].equals("s19")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMusic()); re = ((ExamDbDataHolder) users.get(i)).getMusic(); // row[c] = ((ExamDbDataHolder)users.get(i)).getMusic(); // c++; } else if (Subjects[a].equals("s20")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getFrench()); re = ((ExamDbDataHolder) users.get(i)).getFrench(); // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench(); // c++; } else if (Subjects[a].equals("s21")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getGerman()); re = ((ExamDbDataHolder) users.get(i)).getGerman(); // row[c] = ((ExamDbDataHolder)users.get(i)).getGerman(); // c++; } else if (Subjects[a].equals("s22")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getArabic()); re = ((ExamDbDataHolder) users.get(i)).getArabic(); // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic(); // c++; } else if (Subjects[a].equals("s23")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBusiness()); re = ((ExamDbDataHolder) users.get(i)).getBusiness(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness(); // c++; } String[] gr = nn.checkGrade(re, Subjects[a]); tbl2.addCell(gr[0]); tbl2.addCell(gr[1]); tbl2.addCell(""); } } //add for all other subjects PdfPTable tbl3 = new PdfPTable(4); // tbl.setWidthPercentage(100); tbl3.setTotalWidth(575); tbl3.setLockedWidth(true); tbl3.setSpacingBefore(8); tbl3.setSpacingAfter(6); // tbl3.getDefaultCell().setBorderWidthTop(0); tbl3.getDefaultCell().setBorder(0); // tbl3.getDefaultCell().setBorderWidthLeft(0); // tbl3.getDefaultCell().setBorderWidthRight(0); tbl3.setWidths(new int[] { 1, 1, 1, 1 }); tbl3.addCell(creatTextCellHeader("CURRENT MARKS:")); tbl3.addCell(creatTextCellHeader(String.valueOf(((ExamDbDataHolder) users.get(0)).getTotal()))); float g = Float.valueOf(((ExamDbDataHolder) users.get(0)).getTotal()); // tbl.addCell(String.format("%.1f", g)); String gr = nn.checkGrade(yearid, String.format("%.1f", g / getYear())); tbl3.addCell(creatTextCellHeader("PREVIOUS MARKS:")); tbl3.addCell(creatTextCellHeader("459")); tbl3.addCell(creatTextCellHeader("AVERAGE MARKS:")); tbl3.addCell(creatTextCellHeader(String.format("%.1f", g / getYear()))); tbl3.addCell(creatTextCellHeader("PREVIOUS AVERAGE:")); tbl3.addCell(creatTextCellHeader("50")); tbl3.addCell(creatTextCellHeader("MEAN GRADE:")); tbl3.addCell(creatTextCellHeader(gr)); tbl3.addCell(creatTextCellHeader("PREVIOUS MEAN GRADE:")); tbl3.addCell(creatTextCellHeader("B")); tbl3.addCell(creatTextCellHeader("POS")); tbl3.addCell(creatTextCellHeader("3 ")); tbl3.addCell(creatTextCellHeader("OUT OF")); tbl3.addCell(creatTextCellHeader("79")); PdfPTable tbl4 = new PdfPTable(2); // tbl.setWidthPercentage(100); tbl4.setHorizontalAlignment(0); //tbl4.HorizontalAlignment=Element.ALIGN_LEFT; tbl4.setTotalWidth(575 / 2); tbl4.setLockedWidth(true); tbl4.setSpacingBefore(8); tbl4.setSpacingAfter(6); // tbl3.getDefaultCell().setBorderWidthTop(0); tbl4.getDefaultCell().setBorder(0); // tbl3.getDefaultCell().setBorderWidthLeft(0); // tbl3.getDefaultCell().setBorderWidthRight(0); tbl4.setWidths(new int[] { 2, 1 }); PdfPCell cell = new PdfPCell(new Paragraph("REMARKS")); cell.setColspan(2); tbl4.addCell(cell); tbl4.addCell(creatTextCellHeader( "CLASS TEACHERS........................................................." + ":............................\n\n\n")); tbl4.addCell(creatTextCellChart("chart")); tbl4.addCell(creatTextCellHeader( "SIGNATURE-------------------------------------------------------------" + "-------------------------------\n\n\n")); tbl4.addCell(creatTextCellHeader( "-------------\n\n\n-----------------------------------------------------------" + "-----------------------------")); pdfp.add(tbl1); pdfp.add(tbl); pdfp.add(tbl2); pdfp.add(tbl3); pdfp.add(tbl4); // Paragraph p=new Paragraph(); // p.setAlignment(Element.ALIGN_CENTER); // p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,18,Font.BOLD)); // Paragraph po=new Paragraph(); // po.setAlignment(Element.ALIGN_CENTER); // po.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,16,Font.BOLD)); // // Paragraph pd=new Paragraph(); // pd.setAlignment(Element.ALIGN_CENTER); // pd.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,14,Font.BOLD)); // p.add("ITHANGA SECONDARY SCHOOL"); // po.add("PO.BOX 238 ITHANGA THIKA"); // pd.add(new Date().toString()); // pdfp.add(p); // pdfp.add(po); // pdfp.add(pd); // // // // pdfp.add(new Paragraph("\n.................................................................." // + ".................................................................................\n")); // String []names= n.findSubjectname(); // PdfPTable tbl=new PdfPTable(names.length+6); // tbl.setWidths(new float[]{1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1}); // // tbl.setWidthPercentage(100); // tbl.setTotalWidth(575); // tbl.setLockedWidth(true); // PdfPTable tbl1=new PdfPTable(names.length+6); // tbl1.setWidths(new float[]{1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1}); // // tbl.setWidthPercentage(100); // tbl1.setTotalWidth(575); // tbl1.setLockedWidth(true); // PdfPCell cell=new PdfPCell (new Paragraph("RESULTS")); // cell.setColspan((names.length+4)*2); // cell.setBackgroundColor(Color.CYAN); // tbl1.addCell(cell); // tbl1.addCell("Pos"); // tbl1.addCell("id"); // tbl1.addCell("Name"); // int a; pdfp.close(); } catch (Exception j) { j.printStackTrace(); } // Image img=new Image.getInstance("j.png"); } } }
From source file:sms.ViewResults.java
private void itextPrint() { // String searchQuery = "SELECT * FROM `exam` WHERE `yearid` ='" + yearid + "'AND `termid`='"+termid+"'AND `examid`='"+yearid+"'" // + "AND CONCAT(`class`) LIKE '%" + stream + "%'AND YEAR(updated_at)='"+yearchooser.getYear()+"'"; methods nn = new methods(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(",")); chooser.setDialogTitle("Save at"); chooser.setApproveButtonText("save"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try {//from w ww . j a v a2 s . c o m Form1Exams n = new Form1Exams(); Document pdfp = new Document(); PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(), "report.pdf"))); pdfp.open(); Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_CENTER); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD)); Paragraph po = new Paragraph(); po.setAlignment(Element.ALIGN_CENTER); po.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD)); Paragraph pd = new Paragraph(); pd.setAlignment(Element.ALIGN_CENTER); pd.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 14, Font.BOLD)); p.add("ITHANGA SECONDARY SCHOOL"); po.add("PO.BOX 238 ITHANGA THIKA"); pd.add(new Date().toString()); pdfp.add(p); pdfp.add(po); pdfp.add(pd); pdfp.add(new Paragraph("\n.................................................................." + ".................................................................................\n")); String[] names = n.findSubjectname(); PdfPTable tbl = new PdfPTable(names.length + 6); tbl.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); // tbl.setWidthPercentage(100); tbl.setTotalWidth(575); tbl.setLockedWidth(true); PdfPTable tbl1 = new PdfPTable(names.length + 6); tbl1.setWidths(new float[] { 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); // tbl.setWidthPercentage(100); tbl1.setTotalWidth(575); tbl1.setLockedWidth(true); PdfPCell cell = new PdfPCell(new Paragraph("RESULTS")); cell.setColspan((names.length + 4) * 2); cell.setBackgroundColor(Color.CYAN); tbl1.addCell(cell); tbl1.addCell("Pos"); tbl1.addCell("id"); tbl1.addCell("Name"); int a; for (a = 0; a < names.length; a++) { String s = names[a]; tbl1.addCell(s.substring(0, Math.min(s.length(), 3))); } tbl1.addCell("Tot"); tbl1.addCell("Ave"); tbl1.addCell("Agg"); pdfp.add(tbl1); try { String[] Subjects = n.findSubjectid(); String[] Subjectsnames = n.findSubjectname(); int subjectCount = Subjects.length; ArrayList<ExamDbDataHolder> users = ListUsers(this.sid.getText()); for (int i = 0; i < users.size(); i++) { tbl.addCell(String.valueOf(i + 1)); String id = ((ExamDbDataHolder) users.get(i)).getSid(); String nam = nn.getStudentName(id); String name = "Eric"; tbl.addCell(id); tbl.addCell(nam); int c = 2; for (int s = 0; s < Subjects.length; s++) { if (Subjects[s].equals("s1")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMathematics()); // JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics()); // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics(); c++; } else if (Subjects[s].equals("s2")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getEnglish()); //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish(); c++; } else if (Subjects[s].equals("s3")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili()); // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili(); c++; } else if (Subjects[s].equals("s4")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getPhysics()); // row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics(); c++; } else if (Subjects[s].equals("s5")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getChemistry()); // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry(); c++; } else if (Subjects[s].equals("s6")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBiology()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBiology(); c++; } else if (Subjects[s].equals("s7")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHistory()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHistory(); c++; } else if (Subjects[s].equals("s8")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getGeography()); // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography(); c++; } else if (Subjects[s].equals("s9")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getCre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getCre(); c++; } else if (Subjects[s].equals("s10")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getIre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getIre(); c++; } else if (Subjects[s].equals("s11")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHre()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHre(); c++; } else if (Subjects[s].equals("s12")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture()); // row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture(); c++; } else if (Subjects[s].equals("s13")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getHomescience()); // row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience(); c++; } else if (Subjects[s].equals("s14")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign()); // row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign(); c++; } else if (Subjects[s].equals("s15")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getComputer()); // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer(); c++; } else if (Subjects[s].equals("s16")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBuilding()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding(); c++; } else if (Subjects[s].equals("s17")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork()); // row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork(); c++; } else if (Subjects[s].equals("s18")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork()); // row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork(); c++; } else if (Subjects[s].equals("s19")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getMusic()); // row[c] = ((ExamDbDataHolder)users.get(i)).getMusic(); c++; } else if (Subjects[s].equals("s20")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getFrench()); // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench(); c++; } else if (Subjects[s].equals("s21")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getGerman()); // row[c] = ((ExamDbDataHolder)users.get(i)).getGerman(); c++; } else if (Subjects[s].equals("s22")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getArabic()); // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic(); c++; } else if (Subjects[s].equals("s23")) { tbl.addCell(((ExamDbDataHolder) users.get(i)).getBusiness()); // row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness(); c++; } } int tt = ((ExamDbDataHolder) users.get(i)).getTotal(); tbl.addCell(String.valueOf(tt)); float g = Float.valueOf(tt) / 11; tbl.addCell(String.format("%.1f", g)); String gr = nn.checkGrade(yearid, String.format("%.1f", g)); tbl.addCell(gr); } pdfp.add(tbl); } catch (Exception j) { j.printStackTrace(); } pdfp.close(); // Image img=new Image.getInstance("j.png"); } catch (DocumentException ex) { Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(ViewResults.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:tk.diginspect.main.SoOFSignatories.java
private void insertCell(PdfPTable table, String text, int align, int colspan, String color, float BorderWidthTop, float BorderWidthBottom) { PdfPCell cell = new PdfPCell(new Paragraph(Font.TIMES_ROMAN, text)); cell.setHorizontalAlignment(align);//from w w w .ja v a2s .co m cell.setColspan(colspan); cell.setBackgroundColor(WebColors.getRGBColor(color)); cell.setPadding(5); cell.setBorderWidthTop(BorderWidthTop); cell.setBorderWidthBottom(BorderWidthBottom); table.addCell(cell); }
From source file:vistas.reportes.procesos.rptAsistenciaEntrada.java
public PdfPTable crearTabla(List<String> dnis, Date fechaInicio, Date fechaFin) throws DocumentException { /**//from w w w . j av a 2 s.c o m * Procesamiento para info para generar tablas */ Calendar fechaInicioC = Calendar.getInstance(); Calendar fechaFinC = Calendar.getInstance(); fechaInicioC.setTime(fechaInicio); fechaFinC.setTime(fechaFin); /** * Procesamiento para elaborar tabla con datos */ int nroColumnas = 6; PdfPTable tabla = new PdfPTable(nroColumnas); tabla.setWidthPercentage(100); //Asignamos los tamaos a las columnas //MOdifique para tomar en cuenta la nueva columna de dewscuento int[] widthColumna = new int[nroColumnas]; widthColumna[0] = 1; widthColumna[1] = 5; widthColumna[2] = 2; widthColumna[3] = 2; widthColumna[4] = 2; widthColumna[5] = 2; tabla.setWidths(widthColumna); //Definimos celdas iniciales Font fontCabecera = new Font(Font.HELVETICA, 8, Font.BOLD); Font fontCelda = new Font(Font.HELVETICA, 7); PdfPCell h0 = new PdfPCell(new Phrase("DNI", fontCabecera)); h0.setHorizontalAlignment(1); h0.setGrayFill(0.7f); h0.setColspan(1); tabla.addCell(h0); PdfPCell h1 = new PdfPCell(new Phrase("NOMBRE EMPLEADO", fontCabecera)); h1.setHorizontalAlignment(1); h1.setGrayFill(0.7f); h1.setColspan(1); tabla.addCell(h1); PdfPCell h2 = new PdfPCell(new Phrase("MARCACION ENTRADA", fontCabecera)); h2.setHorizontalAlignment(1); h2.setGrayFill(0.7f); h2.setColspan(1); tabla.addCell(h2); PdfPCell h3 = new PdfPCell(new Phrase("ASISTENCIA", fontCabecera)); h3.setHorizontalAlignment(1); h3.setGrayFill(0.7f); h3.setColspan(1); tabla.addCell(h3); //Agregado de columna de descuento sin goce PdfPCell h4 = new PdfPCell(new Phrase("OBSERVACION", fontCabecera)); h4.setHorizontalAlignment(1); h4.setGrayFill(0.7f); h4.setColspan(1); tabla.addCell(h4); PdfPCell h5 = new PdfPCell(new Phrase("VACACION", fontCabecera)); h5.setHorizontalAlignment(1); h5.setGrayFill(0.7f); h5.setColspan(1); tabla.addCell(h5); /** * Procesamiento de los datos para generar los registros de la entrada */ for (String dni : dnis) { List<Marcacion> marcaciones = mc.buscarXFecha(dni, fechaInicio); String Asistencia = ""; String Permiso = ""; String Vacaciones = ""; String marcacion = ""; String condicion = ""; System.out.println("DNI: " + dni); Empleado empleado = ec.buscarPorDni(dni); List<EmpleadoOpcionInfo> infoEmpleado = eoc.buscarTodos(Integer.parseInt(dni)); if (!infoEmpleado.isEmpty()) { if (infoEmpleado.get(0).getSFieldValue5().equals("0") || infoEmpleado.get(0).getSFieldValue5().equals("") || infoEmpleado.get(0).getSFieldValue5().equals(" ")) { condicion = "NORMAL"; } else if (infoEmpleado.get(0).getSFieldValue5().equals("1")) { condicion = "EXONERADO"; } else if (infoEmpleado.get(0).getSFieldValue5().equals("2")) { condicion = "DESIGNADO"; } else if (infoEmpleado.get(0).getSFieldValue5().equals("3")) { condicion = "OTRA SEDE"; } } else { condicion = "Sin dato"; } System.out.println("Condicion: " + condicion); //Datos de horario, jornada, empleado List<DetalleGrupoHorario> detallesGrupos = dc.buscarXEmpleado(empleado); if (condicion.equals("NORMAL")) { if (!marcaciones.isEmpty()) { Marcacion primeraMarcacion = marcaciones.get(0); marcacion = primeraMarcacion.getHora().toString(); if (!detallesGrupos.isEmpty()) { DetalleGrupoHorario detalleGrupoEmpleado = detallesGrupos.get(0); List<AsignacionHorario> asignaciones = ashc .buscarXGrupo(detalleGrupoEmpleado.getGrupoHorario()); AsignacionHorario asignacionEmpleado = asignaciones.get(0); Horario horarioEmpleado = asignacionEmpleado.getHorario(); Jornada jornadaEmpleado = horarioEmpleado.getJornada(); //Validacion de asistencia if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHE()) == 0 || primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHE()) < 0) { Asistencia = "Asistencia Normal"; } else if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTardanzaHE()) < 0 && primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTurnoHE()) > 0) { Asistencia = "Tardanza"; } else if (primeraMarcacion.getHora().compareTo(jornadaEmpleado.getTardanzaHE()) > 0) { Asistencia = "Falta"; } } else { Asistencia = "No tiene grupo horario"; } } else { marcacion = "Sin marcacion"; Asistencia = "Falta"; } } else if (condicion.equals("EXONERADO")) { marcacion = "Sin marcacion"; Asistencia = condicion; } else if (condicion.equals("DESIGNADO")) { marcacion = "Sin marcacion"; Asistencia = condicion; } else if (condicion.equals("OTRA SEDE")) { marcacion = "Sin marcacion"; Asistencia = condicion; } else { marcacion = "Sin marcacion"; Asistencia = "Condicin sin especificar"; } //Validacion de permiso //Procesar permisos con horas tbm si no encuentra permisos por fechas AsignacionPermiso asignacionPermisoEmpleado = aspc.buscarXDia(dni, fechaInicio); if (asignacionPermisoEmpleado != null) { Permiso = asignacionPermisoEmpleado.getPermiso().getTipoPermiso().getNombre(); Asistencia = "Permiso"; } else { Permiso = "Sin permiso"; } //Validacion de Vacaciones Vacacion vacacionEmpleado = vc.buscarXDia(dni, fechaInicio); if (vacacionEmpleado != null) { Vacaciones = ReporteUtil.obtenerFechaDiaMes(vacacionEmpleado.getFechaInicio()) + " al " + ReporteUtil.obtenerFechaDiaMes(vacacionEmpleado.getFechaFin()); Asistencia = "Vacaciones"; } else { Vacaciones = "No tiene vacaciones"; } //DNI PdfPCell celdaNombre = new PdfPCell(new Phrase(empleado.getNroDocumento(), fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); //Nombre String celda0 = empleado.getApellidoPaterno() + " " + empleado.getApellidoMaterno() + " " + empleado.getNombre(); celdaNombre.setPhrase(new Phrase(celda0, fontCelda)); celdaNombre.setHorizontalAlignment(0); tabla.addCell(celdaNombre); //Hora Marcacion String celda = marcacion; celdaNombre.setPhrase(new Phrase(celda, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); //Asistencia String celda1 = Asistencia; celdaNombre.setPhrase(new Phrase(celda1, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); //Permiso String celda2 = Permiso; celdaNombre.setPhrase(new Phrase(celda2, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); //Vacacion String celda3 = Vacaciones; celdaNombre.setPhrase(new Phrase(celda3, fontCelda)); celdaNombre.setHorizontalAlignment(1); tabla.addCell(celdaNombre); } return tabla; }