List of usage examples for com.lowagie.text FontFactory TIMES_BOLD
String TIMES_BOLD
To view the source code for com.lowagie.text FontFactory TIMES_BOLD.
Click Source Link
From source file:mx.avanti.siract.ui.RACTBeanUI.java
public void postProcessPDF(Object document) throws IOException, DocumentException { final Document pdf = (Document) document; TreeNode[] selectedNodesPDF = selectedNodes; if (selectedNodes != null) { for (TreeNode nodo : selectedNodes) { System.out.println("*********************" + ((NodoMultiClass) nodo.getData()).getNombre()); }// w w w . j a v a2s . c o m } pdf.setPageSize(PageSize.A4.rotate()); pdf.open(); String nombrep = profesor.getPronombre() + " " + profesor.getProapellidoPaterno() + " " + profesor.getProapellidoMaterno(); String numEmpPro = Integer.toString(profesor.getPronumeroEmpleado()); String porAv = Float.toString(porcentajeAvance); SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); //Obtener el nombre del programa educativo seleccionado String nombreProgEdu = ""; int programaEducativoSeleccionado2 = Integer.parseInt(programaEducativoSeleccionado); for (int x = 0; x < programasEducativos.size(); x++) { if (programasEducativos.get(x).getPedid() == programaEducativoSeleccionado2) { nombreProgEdu = programasEducativos.get(x).getPednombre(); } } //---------------------------------------------------------------------------------- //Obtener el nombre de la unidad de aprendizaje y clave seleccionada String nombreUniApr = ""; String nombreclave = ""; int uniAprselec2 = Integer.parseInt(unidadAprendizajeSeleccionada); for (int x = 0; x < unidadesaprendisaje.size(); x++) { if (unidadesaprendisaje.get(x).getUapclave() == uniAprselec2) { nombreUniApr = unidadesaprendisaje.get(x).getUapnombre(); nombreclave = Integer.toString(unidadesaprendisaje.get(x).getUapclave()); } } //---------------------------------------------------------------------- // rutaImagen es la ruta para acceder a la imagen guardada en el folder resources del proyecto try { // Image imagenLogo = Image.getInstance("C:\\Users\\Y\\Desktop\\RACT 22-01-2015\\RACT\\build\\web\\resources\\imagenes\\logo.jpg"); Image imagenLogo = Image.getInstance(RACTBeanUI.class.getResource("imagenes/logo.jpg")); //Posicion de imagen (Horizontal, Vertiacal) imagenLogo.setAbsolutePosition(120f, 460f); //Tamao de imagen (Ancho, largo) imagenLogo.scaleAbsolute(90, 120); //imagenLogo.scaleAbsoluteWidth(100f); //imagenLogo.scaleAbsoluteHeight(150f); //imagenLogo.scaleToFit(100f, 120f); Esta es la buena //Image imagenLogo = Image.getInstance("http://ed.uabc.mx/sed/images/logo.jpg"); //imagenLogo.scaleAbsolute(70f, 90f); pdf.add(imagenLogo); } catch (Exception exception) { System.out.println("****NO SE ENCONTRO LA RUTA DE IMAGEN ESPECIFICADA"); } //Tabla con UABC y Nombre del profesor(a) PdfPTable pdfTabletitulo = new PdfPTable(2); pdfTabletitulo.getDefaultCell().setBorder(PdfPCell.NO_BORDER); PdfPTable pdfTabletitulo2 = new PdfPTable(2); pdfTabletitulo2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); Paragraph UABC = new Paragraph("Universidad Autnoma de Baja California", FontFactory.getFont(FontFactory.TIMES, 22, Font.BOLD, new Color(0, 113, 65))); UABC.setAlignment(Element.ALIGN_CENTER); Paragraph esp = new Paragraph(" "); pdf.add(UABC); pdf.add(esp); pdf.add(esp); pdf.add(esp); pdf.add(esp); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("")); pdfTabletitulo.addCell(new Paragraph("Profesor(a): ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdfTabletitulo.addCell(new Paragraph(nombrep)); pdfTabletitulo2.addCell(new Paragraph("Num. de Empleado: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdfTabletitulo2.addCell(new Paragraph(numEmpPro)); pdfTabletitulo.setHorizontalAlignment(25); //pdfTabletitulo.setHorizontalAlignment(Element.ALIGN_CENTER); //document.add(table); float[] columnWidthsss = new float[] { 4f, 28 }; pdfTabletitulo.setWidths(columnWidthsss); pdf.add(pdfTabletitulo); float[] columnWidthss = new float[] { 10f, 38 }; pdfTabletitulo2.setWidths(columnWidthss); pdf.add(pdfTabletitulo2); pdf.add(new Phrase(" ")); //---------------------------------------------------------------------- //Tabla Cabezera PdfPTable pdftablecabezera = new PdfPTable(4); pdftablecabezera.getDefaultCell().setBorder(PdfPCell.NO_BORDER); PdfPTable pdftablecabezera2 = new PdfPTable(5); pdftablecabezera2.getDefaultCell().setBorder(PdfPCell.NO_BORDER); pdftablecabezera.addCell(new Paragraph("Programa educativo: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera.addCell(new Paragraph("Fecha: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera.addCell(new Paragraph("Ciclo Escolar: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera.addCell(new Paragraph("Avance Global: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera.addCell(new Paragraph(nombreProgEdu)); pdftablecabezera.addCell(new Paragraph(formato.format(new Date()))); pdftablecabezera.addCell(new Paragraph(" " + cicloEscolar)); pdftablecabezera.addCell(new Paragraph(" " + porAv)); pdftablecabezera.addCell(new Paragraph(" ")); pdftablecabezera.addCell(new Paragraph(" ")); pdftablecabezera.addCell(new Paragraph(" ")); pdftablecabezera.addCell(new Paragraph(" ")); pdftablecabezera2.addCell(new Paragraph("Unidad de Aprendizaje: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph("Clave: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph("Grupo: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph("Subgrupo: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph("Tipo Grupo: ", FontFactory.getFont(FontFactory.TIMES, 14, Font.BOLD, new Color(0, 0, 0)))); pdftablecabezera2.addCell(new Paragraph(nombreUnidadSeleccionado)); pdftablecabezera2.addCell(new Paragraph(claveUnidadAprendizajeSeleccionada)); pdftablecabezera2.addCell(new Paragraph(" " + grupo)); pdftablecabezera2.addCell(new Paragraph(" " + subGrupo)); String tipoGrupo = ""; switch (this.tipoUnidadAprendizaje) { case "C": tipoGrupo = "Clase"; break; case "L": tipoGrupo = "Laboratorio"; break; case "T": tipoGrupo = "Taller"; break; case "P": tipoGrupo = "Practica"; break; case "CL": tipoGrupo = "Practicas Clinica"; break; } pdftablecabezera2.addCell(new Paragraph(" " + tipoGrupo)); pdftablecabezera2.addCell(new Paragraph(" ")); pdftablecabezera.setHorizontalAlignment(25); float[] columnWidths = new float[] { 38f, 10f, 14f, 18f }; pdftablecabezera.setWidths(columnWidths); pdf.add(pdftablecabezera); pdftablecabezera2.setHorizontalAlignment(25); float[] columnWidthss2 = new float[] { 38f, 10f, 8f, 11f, 14f }; pdftablecabezera2.setWidths(columnWidthss2); pdf.add(pdftablecabezera2); pdf.add(new Phrase(" ")); //---------------------------------------------------------------------- Paragraph numrep = new Paragraph("Reporte # " + numeroReporte, FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLD, new Color(0, 0, 0))); numrep.setAlignment(Element.ALIGN_CENTER); pdf.add(numrep); pdf.add(new Paragraph(" ")); //Tabla con Datos PdfPTable pdfTable = new PdfPTable(3); pdfTable.addCell(new Phrase("Nombre", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); pdfTable.addCell(new Phrase("Porcentaje", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); pdfTable.addCell(new Phrase("Observaciones", FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); //Evitar Null pointer exception por no tener nodoes en selectedNodes //Se utiliza un auxiliar de selectedNodes por que hay posibilidad de que selectedNodes se modifique durante el proceso de generacion del PDF if (selectedNodesPDF != null && selectedNodesPDF.length > 0) { //Regresar a lo basicoString int nns = selectedNodesPDF.length; String[] ns = new String[nns]; for (int x = 0; x < selectedNodesPDF.length; x++) { ns[x] = ((NodoMultiClass) selectedNodesPDF[x].getData()).getNumero() + "--" + ((NodoMultiClass) selectedNodes[x].getData()).getNombre() + "--" + ((NodoMultiClass) selectedNodes[x].getData()).getPorcentajeAvance() + "--" + ((NodoMultiClass) selectedNodes[x].getData()).getObservaciones() + " -- "; } String[] filas = new String[4]; String[] nstr = new String[3]; String[] filas2 = new String[4]; String[] nstr2 = new String[3]; for (int x = 1; x < ns.length; x++) { for (int y = 0; y < ns.length - x; y++) { //Obtengo los valores para hacer las comparaciones int[] n = new int[3]; int[] n2 = new int[3]; filas = ns[y].split("--"); nstr = filas[0].split("\\."); for (int z = 0; z < nstr.length; z++) { if (nstr == null) { n[z] = 0; } else { n[z] = Integer.parseInt(nstr[z]); } } filas2 = ns[y + 1].split("--"); nstr2 = filas2[0].split("\\."); for (int z = 0; z < nstr2.length; z++) { if (nstr2 == null) { n2[z] = 0; } else { n2[z] = Integer.parseInt(nstr2[z]); } } //-------------------------------------------------comparacion if (n[0] == n2[0]) { if (n[1] == n2[1]) { if (n[2] > n2[2]) { String aux = ns[y]; ns[y] = ns[y + 1]; ns[y + 1] = aux; } } else { if (n[1] > n2[1]) { String aux = ns[y]; ns[y] = ns[y + 1]; ns[y + 1] = aux; } } } else { if (n[0] > n2[0]) { String aux = ns[y]; ns[y] = ns[y + 1]; ns[y + 1] = aux; } } //------------------------------------------------------------- } } String[] auxNum = new String[4]; for (int x = 0; x < ns.length; x++) { filas = ns[x].split("--"); num = filas[0].split("\\."); //Auxiliar para agregar padre de tema/subtema int auxMargen = 1; //Agregar unidad a la que pertenece el tema/subtema String[] auxNum2 = auxNum; int tamanoArbol = root.getChildCount(); //AGREGAR A TEMA if (Integer.parseInt(num[0]) > tamanoArbol) { auxMargen = Integer.parseInt(num[0]) - tamanoArbol; } if (num.length >= 2 && auxNum2[0] != null && !auxNum2[0].equals(num[0])) { if (!num[1].equals("0")) { while (!num[0].equals(auxNum2[0]) && auxMargen > 0) { System.out.println("XXXXXXIteracion para encontrar padre XXXXXXX 0" + auxMargen); auxNum2 = (((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNumero()).split("\\."); //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){ if (num[0].equals(auxNum2[0])) { } else { auxMargen--; } } System.out.println("***Unidad Padre" + ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNombre()); NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()); //UTIL PARA PONER TEXTO TACHADO // Chunk strikethrough = new Chunk("Strikethrough."); // strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location // document.add(strikethrough); pdfTable.addCell(new Phrase(auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(auxNodo.getObservaciones()); } } else { if (auxNum2[0] == null && num.length >= 2) { auxNum2 = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen) .getData()).getNumero()).split("\\."); while (!num[0].equals(auxNum2[0]) && auxMargen > 0) { System.out.println("XXXXXXIteracion para encontrar padre XXXXXXX 0" + auxMargen); auxNum2 = (((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNumero()).split("\\."); //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){ if (num[0].equals(auxNum2[0])) { } else { auxMargen--; } } System.out.println("***Unidad Padre" + ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()).getNombre()); NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()); //UTIL PARA PONER TEXTO TACHADO // Chunk strikethrough = new Chunk("Strikethrough."); // strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location // document.add(strikethrough); pdfTable.addCell(new Phrase(auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(auxNodo.getObservaciones()); } } //AGREGAR A SUBTEMA String[] auxNumeroUnidad = new String[4]; int auxMargen2 = 1; if (num.length == 3 && auxNum[1] != null && !auxNum[1].equals(num[1])) { if (!num[2].equals("0")) { while (!num[0].equals(auxNum[0]) && auxMargen >= 0) { NodoMultiClass auxNodoUnidad = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()); auxNumeroUnidad = auxNodoUnidad.getNumero().split("\\."); tamanoArbol = root.getChildren().get(Integer.parseInt(num[0])).getChildCount(); if (Integer.parseInt(num[1]) > tamanoArbol) { auxMargen2 = Integer.parseInt(num[1]) - tamanoArbol; } while (auxNumeroUnidad[0].equals(num[0]) && !num[1].equals(auxNum[1]) && auxMargen > 0) { System.out.println("XXXXXXIteracion para encontrar padre XXXXXXX 0" + auxMargen); auxNum = (((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getChildren() .get(Integer.parseInt(num[1]) - auxMargen2).getData()).getNumero()) .split("\\."); //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){ if (num[1].equals(auxNum[1])) { } else { auxMargen2--; } } // auxNum = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[1]) - auxMargen).getData()).getNumero()).split("\\."); if (num[0].equals(auxNum[0])) { } else { auxMargen--; } } System.out.println("*****Unidad Padre(SUBTEMA)" + ((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen) .getChildren().get(Integer.parseInt(num[1]) - auxMargen2).getData()) .getNombre()); NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getChildren() .get(Integer.parseInt(num[1]) - auxMargen2).getData()); //UTIL PARA PONER TEXTO TACHADO // Chunk strikethrough = new Chunk("Strikethrough."); // strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location // document.add(strikethrough); pdfTable.addCell( new Phrase(" " + auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(auxNodo.getObservaciones()); } } else { if (auxNum[0] == null && num.length == 3) { auxNum = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen) .getData()).getNumero()).split("\\."); while (!num[0].equals(auxNum[0]) && auxMargen > 0) { NodoMultiClass auxNodoUnidad = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getData()); auxNumeroUnidad = auxNodoUnidad.getNumero().split("\\."); tamanoArbol = root.getChildren().get(Integer.parseInt(num[0])).getChildCount(); if (Integer.parseInt(num[1]) > tamanoArbol) { auxMargen2 = Integer.parseInt(num[1]) - tamanoArbol; } while (auxNumeroUnidad[0].equals(num[0]) && !num[1].equals(auxNum[1]) && auxMargen > 0) { System.out.println("Iteracion para encontrar padre XXXXXXX 0" + auxMargen); auxNum = (((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getChildren() .get(Integer.parseInt(num[1]) - auxMargen2).getData()).getNumero()) .split("\\."); //if(auxNum[0]!=null&&Integer.parseInt(num[0])>Integer.parseInt(auxNum[0])){ if (num[1].equals(auxNum[1])) { } else { auxMargen2--; } } // auxNum = (((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[1]) - auxMargen).getData()).getNumero()).split("\\."); if (num[0].equals(auxNum[0])) { } else { auxMargen--; } } System.out.println("***Unidad Padre(SUBTEMA)" + ((NodoMultiClass) root.getChildren().get(Integer.parseInt(num[0]) - auxMargen) .getChildren().get(Integer.parseInt(num[1]) - auxMargen2).getData()) .getNombre()); NodoMultiClass auxNodo = ((NodoMultiClass) root.getChildren() .get(Integer.parseInt(num[0]) - auxMargen).getChildren() .get(Integer.parseInt(num[1]) - auxMargen2).getData()); //UTIL PARA PONER TEXTO TACHADO // Chunk strikethrough = new Chunk("Strikethrough."); // strikethrough.setUnderline(0.1f, 3f); //0.1 thick, 2 y-location // document.add(strikethrough); pdfTable.addCell( new Phrase(" " + auxNodo.getNumero() + ".- " + auxNodo.getNombre(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(new Phrase(auxNodo.getPorcentajeAvance(), FontFactory .getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(154, 151, 151)))); pdfTable.addCell(auxNodo.getObservaciones()); } } auxNum = num; //FIN AGREGAR PADRE DE TEMA/SUBTEMA boolean banpor = true; if (num.length == 1) { pdfTable.addCell(new Phrase(filas[0] + ".- " + filas[1], FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); pdfTable.addCell(new Phrase(String.valueOf(dosDecimales(Float.parseFloat(filas[2]))), FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD, new Color(0, 0, 0)))); banpor = false; } if (num.length == 2) { pdfTable.addCell(new Phrase(" " + filas[0] + ".- " + filas[1])); } if (num.length == 3) { pdfTable.addCell(new Phrase(" " + filas[0] + ".- " + filas[1], FontFactory.getFont(FontFactory.TIMES_ITALIC, 12))); pdfTable.addCell(new Phrase(String.valueOf(dosDecimales(Float.parseFloat(filas[2]))), FontFactory.getFont(FontFactory.TIMES_ITALIC, 12))); banpor = false; } if (banpor) { pdfTable.addCell(String.valueOf(dosDecimales(Float.parseFloat(filas[2])))); pdfTable.addCell(filas[3]); } else { pdfTable.addCell(filas[3]); } } } else { pdfTable.addCell("No hay nada seleccionado"); pdfTable.addCell(""); pdfTable.addCell(""); } pdfTable.setHorizontalAlignment(15); float[] columnWidths2 = new float[] { 32f, 8f, 14f }; pdfTable.setWidths(columnWidths2); pdf.add(pdfTable); //---------------------------------------------------------------------- }
From source file:sms.ReportForms.java
public PdfPCell creatTextCellHeader(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD)); p.add(text);/*from w w w . j a va 2s . co m*/ cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); return cell; }
From source file:sms.ReportForms.java
public PdfPCell creatTextCellChart(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD)); p.add(text);// w w w . j a va 2 s . c om cell.addElement(p); cell.setRowspan(2); cell.setBorder(Rectangle.NO_BORDER); return cell; }
From source file:sms.ReportForms.java
public PdfPCell createTextCell(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD)); // p.setFont(Font.BOLD); p.setAlignment(Element.ALIGN_CENTER); p.add(text);//from ww w . j a va 2 s . c om cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }
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 ww w . ja va 2s . co 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:storemanagment.Printing.java
public PdfPCell creatTextCellTitles(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.BOLD)); p.add(text);/*www . ja va 2s. c om*/ cell.addElement(p); // cell.setBorder(Rectangle.NO_BORDER); return cell; }