List of usage examples for com.itextpdf.text.pdf PdfPTable getDefaultCell
public PdfPCell getDefaultCell()
PdfPCell
that will be used as reference for all the addCell
methods except addCell(PdfPCell)
. From source file:Capa_Modelo.Reportes.java
public void generarReporteVencimiento() { Connection con;/*w w w. ja v a 2 s .c o m*/ ResultSet res; Statement sentencia; Document documento = new Document(PageSize.A4); con = ConexionDB.GetConnection(); try { sentencia = con.createStatement(); res = sentencia.executeQuery( "SELECT Cantidad, Cantidadmin, Cantidadmax, Medicamento.Nombre, Medicamento.FechaElaboracion, Medicamento.FechaVencimiento, Medicamento.Laboratorio FROM Inventario inner join Medicamento on Inventario.ID_Medicamento = Medicamento.ID_Medicamento "); PdfWriter.getInstance(documento, new FileOutputStream( "reportes/reporte_de_vencimiento " + fechaActual() + " " + horaActual() + ".pdf")); documento.open(); float[] columnWidths = { 2, 2, 2, 2 }; PdfPTable table = new PdfPTable(columnWidths); table.setWidthPercentage(100); table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(true); Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE); PdfPCell cell = new PdfPCell(new Phrase("Reporte de Vencimiento", f)); cell.setBackgroundColor(GrayColor.GRAYBLACK); cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); cell.setColspan(4); table.addCell(cell); table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f)); for (int i = 0; i < 2; i++) { table.addCell("Medicamento"); table.addCell("Laboratorio"); table.addCell("Fecha de Vencimiento"); table.addCell("Cantidad actual"); } table.setHeaderRows(3); table.setFooterRows(1); table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE); table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); while (res.next()) { if (vencido(res.getDate("FechaVencimiento"))) { table.addCell(res.getString("Nombre")); table.addCell(res.getString("Laboratorio")); table.addCell(res.getString("FechaVencimiento")); table.addCell(res.getString("Cantidad")); } } documento.add(table); documento.close(); JOptionPane.showMessageDialog(null, "Reporte de Vencimiento generado correctamente"); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Error en conectar con base de datos"); } catch (DocumentException ex) { Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, "El documento no se pudo generar"); } catch (FileNotFoundException ex) { Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, "EL archivo no se abri"); } }
From source file:Capa_Modelo.Reportes.java
public void generarReporteConsumoMedicamentos() { DecimalFormat df = new DecimalFormat("####0.00"); Connection con;/*from www . ja v a 2 s .c o m*/ ResultSet res; Statement sentencia; Document documento = new Document(PageSize.A4); double consumo, cantidad; double porcentaje; consumo = cantidad = 0; con = ConexionDB.GetConnection(); try { sentencia = con.createStatement(); res = sentencia.executeQuery( "SELECT Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio, Inventario.Cantidad, SUM(MedicinaPaciente.Cantidad) as Consumo FROM MedicinaPaciente INNER JOIN Medicamento ON MedicinaPaciente.ID_Medicamento = Medicamento.ID_Medicamento INNER JOIN Inventario ON MedicinaPaciente.ID_Medicamento = Inventario.ID_Medicamento GROUP BY Medicamento.Nombre, Medicamento.Composicion , Medicamento.Laboratorio, Inventario.Cantidad ORDER BY Consumo"); PdfWriter.getInstance(documento, new FileOutputStream( "reportes/reporte_de_consumo_medicamentos " + fechaActual() + " " + horaActual() + ".pdf")); documento.open(); float[] columnWidths = { 2, 2, 2, 2, 2, 2 }; PdfPTable table = new PdfPTable(columnWidths); table.setWidthPercentage(100); table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(true); Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE); PdfPCell cell = new PdfPCell(new Phrase("Reporte de Consumo Medicamentos", f)); cell.setBackgroundColor(GrayColor.GRAYBLACK); cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); cell.setColspan(8); table.addCell(cell); table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f)); for (int i = 0; i < 2; i++) { table.addCell("Medicamento"); table.addCell("Composicion"); table.addCell("Laboratorio"); table.addCell("Cantidad"); table.addCell("Unidades consumidas"); table.addCell("Porcentaje de consumo"); } table.setHeaderRows(3); table.setFooterRows(1); table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE); table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); while (res.next()) { consumo = res.getInt("Consumo"); cantidad = res.getInt("Cantidad"); porcentaje = consumo / cantidad * 100; System.out.println("consumo: " + consumo + " cantidad: " + cantidad + " porcentaje: " + porcentaje); table.addCell(res.getString("Nombre")); table.addCell(res.getString("Composicion")); table.addCell(res.getString("Laboratorio")); table.addCell(res.getString("Cantidad")); table.addCell(res.getString("Consumo")); table.addCell(((df.format(porcentaje))) + "%"); } documento.add(table); documento.close(); JOptionPane.showMessageDialog(null, "Reporte de Consumo de Medicamentos generado correctamente"); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Error al conectar con la base de datos"); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, "Error al generar la ruta del archivo"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error al generar el archivo"); } }
From source file:Capa_Modelo.Reportes.java
public void generarReporteESMedicamentos() { Connection con;//w ww . jav a 2 s. c o m ResultSet res, res2; Statement sentencia; Document documento = new Document(PageSize.A4); con = ConexionDB.GetConnection(); try { sentencia = con.createStatement(); res = sentencia.executeQuery( "SELECT Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio, Medicamento.FechaLlegada, Inventario.Cantidad FROM Medicamento INNER JOIN Inventario ON Medicamento.ID_Medicamento = Inventario.ID_Medicamento ORDER BY Inventario.Cantidad, Medicamento.Nombre desc"); PdfWriter.getInstance(documento, new FileOutputStream("reportes/reporte_de_entrada-salida_medicamentos " + fechaActual() + " " + horaActual() + ".pdf")); documento.open(); float[] columnWidths = { 2, 2, 2, 2, 2 }; PdfPTable table = new PdfPTable(columnWidths); table.setWidthPercentage(100); table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(true); Font f = new Font(Font.FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.GRAYWHITE); PdfPCell cell = new PdfPCell(new Phrase("Reporte de Entrada de Medicamentos", f)); cell.setBackgroundColor(GrayColor.GRAYBLACK); cell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); cell.setColspan(8); table.addCell(cell); table.getDefaultCell().setBackgroundColor(new GrayColor(0.75f)); for (int i = 0; i < 2; i++) { table.addCell("Medicamento"); table.addCell("Composicion"); table.addCell("Laboratorio"); table.addCell("Fecha de Entrada"); table.addCell("Cantidad"); } table.setHeaderRows(3); table.setFooterRows(1); table.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE); table.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); while (res.next()) { table.addCell(res.getString("Nombre")); table.addCell(res.getString("Composicion")); table.addCell(res.getString("Laboratorio")); table.addCell(res.getString("FechaLlegada")); table.addCell(res.getString("Cantidad")); } documento.add(table); documento.newPage(); res2 = sentencia.executeQuery( "SELECT Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio, MedicinaPaciente.FechaEntrega, SUM(MedicinaPaciente.Cantidad) AS Entregados FROM Medicamento INNER JOIN MedicinaPaciente ON Medicamento.ID_Medicamento = MedicinaPaciente.ID_Medicamento group by Medicamento.Nombre, Medicamento.Composicion, Medicamento.Laboratorio,MedicinaPaciente.FechaEntrega ORDER BY Entregados"); float[] columnWidths2 = { 2, 2, 2, 2, 2 }; PdfPTable table2 = new PdfPTable(columnWidths); table2.setWidthPercentage(100); table2.getDefaultCell().setUseAscender(true); table2.getDefaultCell().setUseDescender(true); PdfPCell cell2 = new PdfPCell(new Phrase("Reporte de Salida de Medicamentos", f)); cell2.setBackgroundColor(GrayColor.GRAYBLACK); cell2.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); cell2.setColspan(8); table2.addCell(cell2); table2.getDefaultCell().setBackgroundColor(new GrayColor(0.75f)); for (int i = 0; i < 2; i++) { table2.addCell("Medicamento"); table2.addCell("Composicion"); table2.addCell("Laboratorio"); table2.addCell("Fecha de Salida"); table2.addCell("Cantidad"); } table2.setHeaderRows(3); table2.setFooterRows(1); table2.getDefaultCell().setBackgroundColor(GrayColor.GRAYWHITE); table2.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); while (res2.next()) { table2.addCell(res2.getString("Nombre")); table2.addCell(res2.getString("Composicion")); table2.addCell(res2.getString("Laboratorio")); table2.addCell(res2.getString("FechaEntrega")); table2.addCell(res2.getString("Entregados")); } documento.add(table2); documento.close(); JOptionPane.showMessageDialog(null, "Reporte de Entrada y Salida de Medicamentos generado correctamente"); } catch (SQLException ex) { JOptionPane.showMessageDialog(null, "Error al conectar con la base de datos"); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, "Error al generar la ruta del archivo"); } catch (DocumentException ex) { JOptionPane.showMessageDialog(null, "Error al generar el archivo"); } }
From source file:cl.preguntame.clases.Cabecera.java
/** * Esta es el metodo a llamar cuando ocurra el evento onEndPage, es en este * evento donde crearemos el encabeazado de la pagina con los elementos * indicados./*from ww w . ja v a 2s .com*/ */ public void onEndPage(PdfWriter writer, Document document) { PdfPTable table = new PdfPTable(3); try { // Se determina el ancho y altura de la tabla table.setWidths(new int[] { 24, 24, 2 }); table.setTotalWidth(527); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); // Borde de la celda table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.addCell(encabezado); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Pagina % 01d de ", writer.getPageNumber())); PdfPCell cell = new PdfPCell(Image.getInstance(total)); cell.setBorder(Rectangle.BOTTOM); table.addCell(cell); // Esta linea escribe la tabla como encabezado table.writeSelectedRows(0, -1, 34, 803, writer.getDirectContent()); } catch (DocumentException de) { throw new ExceptionConverter(de); } }
From source file:com.ainfosec.macresponse.report.PdfGenerator.java
License:Open Source License
private static void createDataSection(Paragraph paragraph, DisplayObject displayObject) { if (displayObject == null || displayObject.getObjects() == null) { return;/* w w w . ja va2 s . c o m*/ } // See if the DisplayObject has a list or a single object if (displayObject.getObjects().size() == 1) { TreeObject treeObject = displayObject.getObjects().get(0); // There's only 1 item // For each column, create/add a label with the title and the data int i = 0; for (String columnName : displayObject.getColumnNames()) { StringBuffer sb = new StringBuffer(); // Add the column title sb.append(displayObject.getColumnTitles()[i]); sb.append(": "); // Get the value of the field try { Field field = treeObject.getClass().getDeclaredField(columnName); String val = (String) field.get(treeObject); if (val == null) { val = ""; } // Add the value sb.append(val); sb.append("\n"); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Put the string into the paragraph paragraph.add(sb.toString()); i++; } } else { PdfPTable table = new PdfPTable(displayObject.getColumnTitles().length); table.setWidthPercentage(100); table.setHorizontalAlignment(Element.ALIGN_CENTER); for (String columnName : displayObject.getColumnTitles()) { table.getDefaultCell().setBackgroundColor(BaseColor.CYAN); table.addCell(columnName); table.getDefaultCell().setBackgroundColor(BaseColor.WHITE); } for (TreeObject to1 : displayObject.getObjects()) { for (String columnName : displayObject.getColumnNames()) { try { Field field = to1.getClass().getDeclaredField(columnName); String val = (String) field.get(to1); if (val == null) { val = ""; } table.addCell(val); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } table.getDefaultCell().setColspan(displayObject.getColumnTitles().length); table.getDefaultCell().setBorder(SWT.NONE); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // TODO Paul number the tables table.addCell("Table: " + displayObject.getTitle()); paragraph.add(table); } }
From source file:com.asae.controllers.BeanGestionRutinas.java
public void generarPdf() { Document document = new Document(); try {/*from ww w . java2 s.com*/ File file = File.createTempFile("rutina-", ".pdf", new File("/var/webapp/pdf")); pdfFileName = file.getName(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Font bold = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD); URL url = FacesContext.getCurrentInstance().getExternalContext() .getResource("/resources/img/logo-unicauca-negro.png"); Image imgLogoUnicauca = Image.getInstance(url); imgLogoUnicauca.scaleAbsolute(118f, 131f); PdfPTable tableEncabezado = new PdfPTable(2); tableEncabezado.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEncabezado.setWidthPercentage(100); tableEncabezado.setSpacingAfter(5); PdfPCell cell1 = new PdfPCell(imgLogoUnicauca); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(new Paragraph("Vicerrectoria Administrativa")); cell2.setBorder(Rectangle.NO_BORDER); cell2.setVerticalAlignment(Element.ALIGN_BOTTOM); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); PdfPCell cell3 = new PdfPCell(new Paragraph("Universidad del Cauca", bold)); cell3.setBorder(Rectangle.NO_BORDER); PdfPCell cell4 = new PdfPCell(new Paragraph("Gimnasio y Actividad Fsica", bold)); cell4.setBorder(Rectangle.NO_BORDER); cell4.setHorizontalAlignment(Element.ALIGN_RIGHT); tableEncabezado.addCell(cell1); tableEncabezado.addCell(cell2); tableEncabezado.addCell(cell3); tableEncabezado.addCell(cell4); PdfPTable tableDatosUsuario = new PdfPTable(3); tableDatosUsuario.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDatosUsuario.setWidthPercentage(100); tableDatosUsuario.setSpacingBefore(20); PdfPCell cell5 = new PdfPCell(new Paragraph("Nombre: " + rutinaVisualizar.getIdusuario().getFisrtname() + " " + rutinaVisualizar.getIdusuario().getSecondname() + " " + rutinaVisualizar.getIdusuario().getFirstlastname() + " " + rutinaVisualizar.getIdusuario().getSecondlastname())); cell5.setBorder(Rectangle.NO_BORDER); PdfPCell cell6 = new PdfPCell(); cell6.setBorder(Rectangle.NO_BORDER); PdfPCell cell7 = new PdfPCell(); cell7.setBorder(Rectangle.NO_BORDER); tableDatosUsuario.addCell(cell5); tableDatosUsuario.addCell(cell6); tableDatosUsuario.addCell(cell7); PdfPTable tableFechas = new PdfPTable(3); tableFechas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableFechas.setWidthPercentage(100); tableFechas.setSpacingBefore(10); PdfPCell cell8 = new PdfPCell( new Paragraph("Fecha de inicio: " + getMyFormattedDate(rutinaVisualizar.getFechaInicio()))); cell8.setBorder(Rectangle.NO_BORDER); PdfPCell cell9 = new PdfPCell( new Paragraph("Fecha de fin: " + getMyFormattedDate(rutinaVisualizar.getFechaFin()))); cell9.setBorder(Rectangle.NO_BORDER); PdfPCell cell10 = new PdfPCell(); cell10.setBorder(Rectangle.NO_BORDER); tableFechas.addCell(cell8); tableFechas.addCell(cell9); tableFechas.addCell(cell10); PdfPTable tableMedidas = new PdfPTable(4); tableMedidas.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableMedidas.setWidthPercentage(100); tableMedidas.setSpacingBefore(10); Usuario usuAux = rutinaVisualizar.getIdusuario(); List<Evaluacion> lstEvalAux = usuAux.getEvaluacionList(); Evaluacion evalAux; double peso = 0; if (lstEvalAux.size() > 0) { evalAux = lstEvalAux.get(lstEvalAux.size() - 1); peso = evalAux.getPeso().doubleValue(); } double estatura = 0; MedidasGenerales medGenAux = usuAux.getMedidasGenerales(); if (medGenAux != null) { estatura = medGenAux.getEstatura().doubleValue(); } PdfPCell cell11 = new PdfPCell(new Paragraph("Peso: " + peso)); cell11.setBorder(Rectangle.NO_BORDER); PdfPCell cell12 = new PdfPCell(new Paragraph("Talla: " + estatura)); cell12.setBorder(Rectangle.NO_BORDER); double imc = 0; if (peso != 0 && estatura != 0) { imc = peso / Math.pow(estatura, 2); } PdfPCell cell13 = new PdfPCell(new Paragraph("I.M.C: " + imc)); cell13.setBorder(Rectangle.NO_BORDER); PdfPCell cell14 = new PdfPCell(new Paragraph("Rutina: " + rutinaVisualizar.getCodigoRutina())); cell14.setBorder(Rectangle.NO_BORDER); tableMedidas.addCell(cell11); tableMedidas.addCell(cell12); tableMedidas.addCell(cell13); tableMedidas.addCell(cell14); PdfPTable tableDias = new PdfPTable(2); tableDias.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableDias.setWidthPercentage(100); tableDias.setSpacingBefore(20); tableDias.setHorizontalAlignment(Element.ALIGN_LEFT); tableDias.setWidths(new int[] { 1, 9 }); List<Dia> lstDiasPDF = rutinaVisualizar.getDiaList(); PdfPCell cellCabezeraDia = new PdfPCell(new Paragraph("Da", bold)); PdfPCell cellCabezeraDia2 = new PdfPCell(); cellCabezeraDia2.setBorder(Rectangle.NO_BORDER); tableDias.addCell(cellCabezeraDia); tableDias.addCell(cellCabezeraDia2); for (Dia dia : lstDiasPDF) { PdfPCell cellDia = new PdfPCell(new Paragraph(dia.getNumDia().toString())); PdfPCell cellDia2 = new PdfPCell(); cellDia2.setBorder(Rectangle.NO_BORDER); List<GrupoMuscular> lstGMuscularPDF = dia.getGrupoMuscularList(); if (lstGMuscularPDF.size() > 0) { PdfPTable tableGMuscular = new PdfPTable(2); tableGMuscular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableGMuscular.setWidthPercentage(100); tableGMuscular.setHorizontalAlignment(Element.ALIGN_LEFT); tableGMuscular.setWidths(new int[] { 1, 6 }); PdfPCell cellCabezeraGMuscular = new PdfPCell(new Paragraph("Grupo Muscular", bold)); cellCabezeraGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); PdfPCell cellCabezeraGMuscular2 = new PdfPCell(); cellCabezeraGMuscular2.setBorder(Rectangle.NO_BORDER); tableGMuscular.addCell(cellCabezeraGMuscular); tableGMuscular.addCell(cellCabezeraGMuscular2); int aux = 1; for (GrupoMuscular gMuscularFor : lstGMuscularPDF) { PdfPCell cellGMuscular = new PdfPCell( new Paragraph(gMuscularFor.getIdgrupoMuscularGeneral().getNombre())); cellGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); PdfPCell cellGMuscular2 = new PdfPCell(); cellGMuscular2.setBorder(Rectangle.NO_BORDER); List<EjercicioGm> lstEjerciciosGMuscularPDF = gMuscularFor.getEjercicioGmList(); BaseColor myColor = WebColors.getRGBColor("#CCEEFF"); if (lstEjerciciosGMuscularPDF.size() > 0) { PdfPTable tableEjercicioGMsucular = new PdfPTable(5); tableEjercicioGMsucular.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableEjercicioGMsucular.setWidthPercentage(100); tableEjercicioGMsucular.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cellCabezeraEjercicioGM = new PdfPCell(new Paragraph("Ejercicio", bold)); cellCabezeraEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM.setLeading(20f, 0f); cellCabezeraEjercicioGM.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM); PdfPCell cellCabezeraEjercicioGM2 = new PdfPCell(new Paragraph("Series", bold)); cellCabezeraEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM2.setLeading(20f, 0f); cellCabezeraEjercicioGM2.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM2); PdfPCell cellCabezeraEjercicioGM3 = new PdfPCell(new Paragraph("Repeticiones", bold)); cellCabezeraEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM3.setLeading(20f, 0f); cellCabezeraEjercicioGM3.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM3); PdfPCell cellCabezeraEjercicioGM4 = new PdfPCell(new Paragraph("Receso", bold)); cellCabezeraEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM4.setLeading(20f, 0f); cellCabezeraEjercicioGM4.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM4); PdfPCell cellCabezeraEjercicioGM5 = new PdfPCell(new Paragraph("Peso", bold)); cellCabezeraEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP); cellCabezeraEjercicioGM5.setLeading(20f, 0f); cellCabezeraEjercicioGM5.setBackgroundColor(myColor); tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM5); int aux2 = 1; for (EjercicioGm ejercicioGm : lstEjerciciosGMuscularPDF) { PdfPCell cellEjercicioGM = new PdfPCell( new Paragraph(ejercicioGm.getEjercicio().getNombre())); cellEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM.setLeading(20f, 0f); PdfPCell cellEjercicioGM2 = new PdfPCell( new Paragraph(ejercicioGm.getNumeroSeries().toString())); cellEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM2.setLeading(20f, 0f); PdfPCell cellEjercicioGM3 = new PdfPCell( new Paragraph(ejercicioGm.getRepeticiones().toString())); cellEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM3.setLeading(20f, 0f); PdfPCell cellEjercicioGM4 = new PdfPCell( new Paragraph(ejercicioGm.getReceso().toString())); cellEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM4.setLeading(20f, 0f); PdfPCell cellEjercicioGM5 = new PdfPCell( new Paragraph(ejercicioGm.getPeso().toString())); cellEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT); cellEjercicioGM5.setLeading(20f, 0f); if (aux2 % 2 == 0) { cellEjercicioGM.setBackgroundColor(myColor); cellEjercicioGM2.setBackgroundColor(myColor); cellEjercicioGM3.setBackgroundColor(myColor); cellEjercicioGM4.setBackgroundColor(myColor); cellEjercicioGM5.setBackgroundColor(myColor); } tableEjercicioGMsucular.addCell(cellEjercicioGM); tableEjercicioGMsucular.addCell(cellEjercicioGM2); tableEjercicioGMsucular.addCell(cellEjercicioGM3); tableEjercicioGMsucular.addCell(cellEjercicioGM4); tableEjercicioGMsucular.addCell(cellEjercicioGM5); aux2++; } cellGMuscular2.addElement(tableEjercicioGMsucular); } tableGMuscular.addCell(cellGMuscular); tableGMuscular.addCell(cellGMuscular2); aux++; } cellDia2.addElement(tableGMuscular); } tableDias.addCell(cellDia); tableDias.addCell(cellDia2); } LineSeparator ls = new LineSeparator(); document.add(tableEncabezado); document.add(ls); document.add(tableDatosUsuario); document.add(tableFechas); document.add(tableMedidas); document.add(tableDias); document.close(); } catch (DocumentException | FileNotFoundException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(BeanGestionRutinas.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.athena.chameleon.engine.core.PDFCommonEventHelper.java
License:Apache License
/** * header ? footer /* www . j ava 2 s . c o m*/ */ public void onEndPage(PdfWriter writer, Document document) { if (titleFlag) return; Font font = new Font(bfKorean, 9); PdfPTable hTable = new PdfPTable(1); PdfPTable ftable = new PdfPTable(3); try { hTable.setWidths(new int[] { 100 }); hTable.setTotalWidth(500); hTable.setLockedWidth(true); hTable.getDefaultCell().setFixedHeight(15); hTable.getDefaultCell().setBorder(Rectangle.BOTTOM); hTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); hTable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.header.title"), font)); hTable.writeSelectedRows(0, -1, 50, 803, writer.getDirectContent()); ftable.setWidths(new int[] { 100, 100, 100 }); ftable.setTotalWidth(500); ftable.setLockedWidth(true); ftable.getDefaultCell().setBorder(Rectangle.TOP); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); ftable.addCell(new Phrase(MessageUtil.getMessage("pdf.message.footer.left"), font)); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); if (pagingFlag) ftable.addCell(new Phrase( MessageUtil.getMessage("pdf.message.footer.center", String.valueOf(writer.getPageNumber())), font)); else ftable.addCell(""); ftable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); ftable.addCell(new Phrase(String.valueOf(new SimpleDateFormat("yyyy/MM/dd").format(new Date())), font)); ftable.writeSelectedRows(0, -1, 50, 55, writer.getDirectContent()); } catch (Exception de) { throw new ExceptionConverter(de); } }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * /*from ww w .ja va2 s. c o m*/ * PDF Title Page * * @param doc * @param writer */ public static void setTitleMainPage(Document doc, PdfWriter writer, PDFCommonEventHelper event, Upload upload) throws Exception { Font fnTitle = new Font(bfKorean, 20, Font.BOLD); Font fnLabel = new Font(bfKorean, 11, Font.BOLD); Font fnText = new Font(bfKorean, 11); LineSeparator UNDERLINE = new LineSeparator(1, 80, null, com.itextpdf.text.Element.ALIGN_CENTER, -5); doc.newPage(); doc.add(Chunk.NEWLINE); event.setTitleFlag(true); int toc = writer.getPageNumber(); Image img = Image.getInstance(PDFDocGenerator.class.getResource("/image/title.gif")); img.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); img.scalePercent(80, 80); doc.add(img); Paragraph titlePh = new Paragraph(MessageUtil.getMessage("pdf.message.main.title"), fnTitle); titlePh.setAlignment(com.itextpdf.text.Element.ALIGN_CENTER); titlePh.setSpacingBefore(50); titlePh.setSpacingAfter(30); doc.add(titlePh); doc.add(UNDERLINE); PdfPTable t1 = new PdfPTable(2); t1.setSpacingBefore(20); t1.setWidths(new int[] { 110, 290 }); t1.getDefaultCell().setBorder(0); t1.getDefaultCell().setFixedHeight(32); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_name"), fnLabel)); t1.addCell(new Phrase(upload.getProjectNm(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.department"), fnLabel)); t1.addCell(new Phrase(upload.getDepartment(), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.focus_name"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.focus_name"), fnText)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.product"), fnLabel)); t1.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.text.product", upload.getBeforeWas(), upload.getAfterWas()), fnText)); doc.add(t1); doc.add(UNDERLINE); Paragraph executedPh = new Paragraph(MessageUtil.getMessage("pdf.message.main.label.executed"), fnLabel); executedPh.setSpacingBefore(30); executedPh.setSpacingAfter(15); executedPh.setIndentationLeft(50); doc.add(executedPh); PdfPTable t2 = new PdfPTable(2); t2.getDefaultCell().setFixedHeight(28); t2.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); t2.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.owner"), fnLabel)); t2.addCell(new Phrase(MessageUtil.getMessage("pdf.message.main.label.project_role"), fnLabel)); t2.getDefaultCell().setBackgroundColor(new BaseColor(255, 255, 255)); t2.addCell(new Phrase(upload.getPerson(), fnText)); t2.addCell(new Phrase(upload.getOrgRole(), fnText)); doc.add(t2); doc.newPage(); int total = writer.reorderPages(null); int[] order = new int[total]; for (int i = 0; i < total; i++) { order[i] = i + toc; if (order[i] > total) order[i] -= total; } // apply the new order writer.reorderPages(order); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * // w ww . ja v a2s .c o m * Table * * @param section table? section ? * @param e table element * @throws Exception */ public static void setTable(Section section, Element e) throws Exception { int colSize = Integer.parseInt(e.getAttributeValue("size")); PdfPTable t = new PdfPTable(colSize); if (e.getAttributeValue("width") != null) t.setTotalWidth(Float.parseFloat(e.getAttributeValue("width"))); t.setSpacingAfter(12); t.getDefaultCell().setLeading(0.0F, 1.3F); t.getDefaultCell().setMinimumHeight(22); t.getDefaultCell().setPaddingBottom(8); t.getDefaultCell().setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); setTableHeader(e, t, colSize); setTableRow(e, t); section.add(t); }
From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * /*from ww w . j a v a 2s . c o m*/ * ?? header * * @param e table element * @param t header table ? * @param colCount column * @throws Exception */ public static void setTableHeader(Element e, PdfPTable t, int colCount) throws Exception { t.getDefaultCell().setBackgroundColor(new BaseColor(217, 217, 217)); t.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); ArrayList<Integer> colWidth = new ArrayList<Integer>(); for (Element e1 : e.getChild("header").getChildren()) { t.addCell(new Phrase(e1.getText(), fnNormalBold)); if (e1.getAttributeValue("width") != null) colWidth.add(Integer.parseInt(e1.getAttributeValue("width"))); } if (colCount == colWidth.size()) { int[] col = new int[colCount]; for (int i = 0; i < colCount; i++) col[i] = colWidth.get(i); t.setWidths(col); } }