List of usage examples for com.itextpdf.text.pdf PdfPTable setFooterRows
public void setFooterRows(int footerRows)
From source file:Capa_Modelo.Reportes.java
public void generarReporteInventario() { Connection con;/*w w w . j a va 2s . c om*/ 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.Composicion, Medicamento.FechaVencimiento, Medicamento.Laboratorio FROM Inventario inner join Medicamento on Inventario.ID_Medicamento = Medicamento.ID_Medicamento "); PdfWriter.getInstance(documento, new FileOutputStream( "reportes/reporte_de_inventario " + fechaActual() + " " + horaActual() + ".pdf")); documento.open(); float[] columnWidths = { 2, 2, 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 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 Elaboracion"); table.addCell("Fecha de Vencimiento"); table.addCell("Cantidad minima"); table.addCell("Cantidad actual"); table.addCell("Cantidad maxima"); } 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("FechaElaboracion")); table.addCell(res.getString("FechaVencimiento")); table.addCell(res.getString("Cantidadmin")); table.addCell(res.getString("Cantidad")); table.addCell(res.getString("Cantidadmax")); } documento.add(table); documento.close(); JOptionPane.showMessageDialog(null, "Reporte de Inventario 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 generarReporteVencimiento() { Connection con;/*ww w. j a va 2s .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;/* www. j a 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;/*from w w w. j a va2s .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:com.vectorprint.report.itext.style.stylers.Table.java
License:Open Source License
private PdfPTable style(PdfPTable t) throws VectorPrintException { super.style(t, null); t.setWidthPercentage(getRelwidth()); try {// w ww. ja va 2 s .c o m float[] w = getWidths(); t.setWidths(w); t.setTotalWidth(w); t.setHeaderRows(getHeaderrows()); t.setFooterRows(getFooterrows()); } catch (DocumentException ex) { throw new VectorPrintException("number of widths differs from number of columns in table", ex); } return t; }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
private PdfPTable prepareTable(List<? extends Column> visibleColumns) throws DocumentException { java.util.List<Integer> widths = new ArrayList<>(); for (Column column : visibleColumns) { widths.add(column.getColumnWidth()); }// w w w . j a va 2s .c o m PdfPTable table = new PdfPTable(widths.size()); table.setWidths(ArrayUtils.toPrimitive(widths.toArray(new Integer[widths.size()]))); table.getDefaultCell().setBackgroundColor(HEADER_BACKGROUND); table.getDefaultCell().setPadding(CELL_PADDING); table.setWidthPercentage(WIDTH_PERCENTAGE); table.setSpacingBefore(TABLE_SPACING); table.setHeaderRows(2); table.setFooterRows(1); setTableHeader(table, visibleColumns); setBlankFooter(table, visibleColumns.size()); return table; }
From source file:timeclock.reports.EmployeeListReport.java
@Override public PdfPTable createTable(List list) { PdfPTable table = new PdfPTable(new float[] { 2, 3, 4, 1, 1 }); table.setWidthPercentage(100f);/*from ww w . jav a2 s . c om*/ PdfPCell dCell = table.getDefaultCell(); dCell.setUseAscender(true); dCell.setUseDescender(true); dCell.setPadding(3); dCell.setHorizontalAlignment(Element.ALIGN_CENTER); dCell.setBackgroundColor(BaseColor.DARK_GRAY); table.addCell(new Phrase("Employee ID", MyFonts.font.get("header"))); table.addCell(new Phrase("First Name", MyFonts.font.get("header"))); table.addCell(new Phrase("Last Name", MyFonts.font.get("header"))); table.addCell(new Phrase("Salary", MyFonts.font.get("header"))); table.addCell(new Phrase("Admin", MyFonts.font.get("header"))); dCell.setBackgroundColor(null); table.setHeaderRows(1); table.setFooterRows(0); // used for alternating row color int rowCount = 0; // Display all employees for (Object obj : list) { Employee emp = (Employee) obj; rowCount++; dCell.setBackgroundColor((rowCount % 2 == 0 ? BaseColor.LIGHT_GRAY : null)); table.addCell(new Paragraph(Integer.toString(emp.getEmployeeID()), MyFonts.font.get("normal"))); table.addCell(new Paragraph(emp.getFirstName(), MyFonts.font.get("normal"))); table.addCell(new Paragraph(emp.getLastName(), MyFonts.font.get("normal"))); table.addCell(new Paragraph(emp.getIsSalary_bool() ? "Yes" : "No", MyFonts.font.get("normal"))); table.addCell(new Paragraph(emp.getIsAdmin_bool() ? "Yes" : "No", MyFonts.font.get("normal"))); } return table; }
From source file:timeclock.reports.EmployeeTimeReport.java
@Override public PdfPTable createTable(List list) { // Create table and set basic table properties PdfPTable table = new PdfPTable(new float[] { 1, 4, 4, 3 }); table.setWidthPercentage(100f);/*from ww w . j a v a 2s . c o m*/ PdfPCell dCell = table.getDefaultCell(); dCell.setUseAscender(true); dCell.setUseDescender(true); dCell.setPadding(3); dCell.setHorizontalAlignment(Element.ALIGN_CENTER); // Set header background color dCell.setBackgroundColor(BaseColor.DARK_GRAY); // Display the employee first in header table.addCell(new Phrase(Integer.toString(employee.getEmployeeID()), MyFonts.font.get("header"))); table.addCell(new Phrase(employee.getFirstName(), MyFonts.font.get("header"))); table.addCell(new Phrase(employee.getLastName(), MyFonts.font.get("header"))); table.addCell(new Phrase("", MyFonts.font.get("header"))); // Display the column names in header table.addCell(new Phrase("", MyFonts.font.get("header"))); table.addCell(new Phrase("Time In", MyFonts.font.get("header"))); table.addCell(new Phrase("Time Out", MyFonts.font.get("header"))); table.addCell(new Phrase("Time Worked", MyFonts.font.get("header"))); // Reset the cell background color dCell.setBackgroundColor(null); // Set the number of rows included in the header and footer table.setHeaderRows(2); table.setFooterRows(0); // Make a variable to hold the total of all time worked long totalTimeDiff = 0; // used for alternating row color int rowCount = 0; // Display all time punches for (Object obj : list) { TimePunch tp = (TimePunch) obj; rowCount++; dCell.setBackgroundColor((rowCount % 2 == 0 ? BaseColor.LIGHT_GRAY : null)); Timestamp ts1, ts2; ts1 = tp.getPunchInTimestamp(); ts2 = tp.getPunchOutTimestamp(); totalTimeDiff += ts2.getTime() - ts1.getTime(); String id = Integer.toString(tp.getPunchId()); String in = DateUtils.getDateTimeFromTimestamp(ts1); String out = DateUtils.getDateTimeFromTimestamp(ts2); String diff = DateUtils.getTimestampDiff_Str(ts1, ts2); // Add information to row table.addCell(new Paragraph("", MyFonts.font.get("normal"))); table.addCell(new Paragraph(in, MyFonts.font.get("normal"))); table.addCell(new Paragraph(out, MyFonts.font.get("normal"))); table.addCell(new Paragraph(diff, MyFonts.font.get("normal"))); } // Set background to null dCell.setBackgroundColor(null); // Get total time worked and create a totals row table.addCell(new Paragraph("", MyFonts.font.get("normal"))); table.addCell(new Paragraph("", MyFonts.font.get("normal"))); table.addCell(new Paragraph("Total:", MyFonts.font.get("bold"))); table.addCell(new Paragraph(DateUtils.getTimeStrFromLong(totalTimeDiff), MyFonts.font.get("bold"))); return table; }