List of usage examples for com.itextpdf.text.pdf PdfPTable setHeaderRows
public void setHeaderRows(int headerRows)
From source file:PDFmaker.java
private static void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(2); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Uitgiftepunt")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//from w w w. j a v a2s .c o m c1 = new PdfPCell(new Phrase("Pakketten deze week (" + LocalDate.now() + ")")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); try { SQLget sql = new SQLget(); ResultSet rs = sql.getProductielijst(); while (rs.next()) { String uitgiftepunt = rs.getString("Uitgiftepunt"); int aantalPakketten = rs.getInt("Pakketten"); table.addCell(uitgiftepunt); table.addCell(Integer.toString(aantalPakketten)); } } catch (Exception e) { } subCatPart.add(table); }
From source file:Pdfsave.java
private static void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(3); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);/* w w w .j ava 2 s. c o m*/ c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); table.addCell("1.0"); table.addCell("1.1"); table.addCell("1.2"); table.addCell("2.1"); table.addCell("2.2"); table.addCell("2.3"); subCatPart.add(table); }
From source file:CrearPdf.java
private void createTable(Document document) throws BadElementException, DocumentException { PdfPTable table = new PdfPTable(6); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1;//ww w. j a va2 s.co m for (int i = 0; i < columnas.length; i++) { c1 = new PdfPCell(new Phrase(columnas[i])); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); System.out.println("columnas" + columnas[i]); } table.setHeaderRows(1); for (int i = 0; i < d; i++) { for (int j = 0; j < columnas.length; j++) { System.out.print(datos[i][j] + " "); table.addCell(datos[i][j]); } System.out.println(); } document.add(table); }
From source file:Almacen.Conciliacion.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed // TODO add your handling code here: try {//from ww w . j a v a2 s .co m javax.swing.JFileChooser archivo = new javax.swing.JFileChooser(); archivo.setFileFilter(new ExtensionFileFilter("pdf document (*.pdf)", new String[] { "PDF" })); String ruta = null; if (archivo.showSaveDialog(null) == archivo.APPROVE_OPTION) { ruta = archivo.getSelectedFile().getAbsolutePath(); if (ruta != null) { Session session = HibernateUtil.getSessionFactory().openSession(); ArrayList datos = new ArrayList(); Query query = session.createSQLQuery( "select compania.nombre, orden.tipo_nombre, orden.modelo, orden.no_serie, clientes.nombre as nombres,orden.id_orden \n" + "from orden inner join compania on compania.id_compania=orden.id_compania inner join clientes on clientes.id_clientes=orden.id_cliente\n" + "where orden.id_orden=" + Integer.parseInt(orden) + ""); query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP); datos = (ArrayList) query.list(); // PDF reporte = new PDF(); reporte.Abrir2(PageSize.LEGAL.rotate(), "CONCILIACIN", ruta + ".pdf"); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); float[] nuevos = new float[] { 40, 40, 25, 40, 145, 20, 50, 50, 50, 50, 50, 50, 100, 50, 20 }; com.itextpdf.text.Font font = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.HELVETICA, 7, com.itextpdf.text.Font.NORMAL); com.itextpdf.text.Font font1 = new com.itextpdf.text.Font( com.itextpdf.text.Font.FontFamily.HELVETICA, 7, com.itextpdf.text.Font.NORMAL); BaseColor contenido = BaseColor.WHITE; BaseColor contenido1 = BaseColor.DARK_GRAY; int centro = com.itextpdf.text.Element.ALIGN_CENTER; int izquierda = com.itextpdf.text.Element.ALIGN_LEFT; int derecha = com.itextpdf.text.Element.ALIGN_RIGHT; reporte.inicioTexto(); reporte.agregaObjeto(reporte.crearImagen("imagenes/empresa300115.jpg", 730, -90, 45)); reporte.contenido.setFontAndSize(bf, 20); reporte.contenido.setColorFill(BaseColor.BLACK); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_CENTER, "CONCILIACIN PARA FACTURACIN", 395, 577, 0); reporte.contenido.setFontAndSize(bf, 12); reporte.contenido.setColorFill(BaseColor.BLACK); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "COMPAIA:", 38, 540, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "TIPO DE UNIDAD:", 38, 520, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "MODELO:", 38, 500, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "SERIE VIN:", 38, 480, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "CLIENTE:", 38, 460, 0); reporte.contenido.roundRectangle(170, 540, 410, 0, 0); reporte.contenido.roundRectangle(170, 520, 410, 0, 0); reporte.contenido.roundRectangle(170, 500, 410, 0, 0); reporte.contenido.roundRectangle(170, 480, 410, 0, 0); reporte.contenido.roundRectangle(170, 460, 410, 0, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ORDEN DE TRABAJO SET.", 605, 540, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, "ORDEN DE SURTIDO", 620, 480, 0); for (int i = 0; i < datos.size(); i++) { java.util.HashMap map = (java.util.HashMap) datos.get(i); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("nombre").toString(), 171, 540, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("tipo_nombre").toString(), 171, 520, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("modelo").toString(), 171, 500, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("no_serie").toString(), 171, 480, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("nombres").toString(), 171, 460, 0); reporte.contenido.showTextAligned(PdfContentByte.ALIGN_LEFT, map.get("id_orden").toString(), 657, 520, 0); } reporte.contenido.roundRectangle(640, 520, 80, 0, 0); reporte.contenido.roundRectangle(640, 460, 80, 0, 0); reporte.finTexto(); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_CENTER); cabecera(reporte, bf, tabla, "", 2); DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); int num_r = t_datos.getRowCount(); for (int i = 0; i < num_r; i++) { for (int j = 0; j < 4; j++) { int renglon = 0; switch (j) { case 0: renglon = 8; break; case 1: renglon = 10; break; case 2: renglon = 11; break; case 3: renglon = 12; break; } if ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0 && t_datos.getValueAt(i, 9).toString().compareTo("N") == 0) || ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0 && renglon >= 10)) || (renglon == 8 && Double.parseDouble(t_datos.getValueAt(i, 10).toString()) <= 0 && Double.parseDouble(t_datos.getValueAt(i, 11).toString()) <= 0 && Double.parseDouble(t_datos.getValueAt(i, 12).toString()) <= 0)) { if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) contenido = BaseColor.WHITE; else contenido = BaseColor.LIGHT_GRAY; if ((boolean) t_datos.getValueAt(i, 3) == true || (boolean) t_datos.getValueAt(i, 4) == true) { //columna0 if (t_datos.getValueAt(i, 5) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 5).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna1 if (t_datos.getValueAt(i, 6) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 6).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna2 tabla.addCell(reporte.celda(t_datos.getValueAt(i, renglon).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); //columna3 if (t_datos.getValueAt(i, 14) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 14).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna4 tabla.addCell(reporte.celda(t_datos.getValueAt(i, 2).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); //columna5 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); else { switch (renglon) { case 8: tabla.addCell(reporte.celda("N", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 10: tabla.addCell(reporte.celda("D", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 11: tabla.addCell(reporte.celda("R", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 12: tabla.addCell(reporte.celda("M", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; } } //columna6 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 15)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna7 $tot aut. double n; n = BigDecimal .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) * Double.parseDouble(t_datos.getValueAt(i, 15).toString())) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna8 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 16)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna9 $tot com n = BigDecimal .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) * Double.parseDouble(t_datos.getValueAt(i, 16).toString())) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna10 11 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { switch (renglon) { case 8: n = BigDecimal.valueOf( Double.parseDouble(t_datos.getValueAt(i, 16).toString()) / 0.9d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 10: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.72d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 11: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.65d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 12: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.65d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; } } //columna12 if (t_datos.getValueAt(i, 18) == null) { tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 18).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } //columna13 if (t_datos.getValueAt(i, 19) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 19).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna14 tabla.addCell( reporte.celda("V", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } } } } font1.setColor(BaseColor.WHITE); tabla.addCell(reporte.celda("Faltante en Vales", font1, contenido1, centro, 15, 1, Rectangle.RECTANGLE)); for (int i = 0; i < num_r; i++) { for (int j = 0; j < 4; j++) { int renglon = 0; switch (j) { case 0: renglon = 8; break; case 1: renglon = 10; break; case 2: renglon = 11; break; case 3: renglon = 12; break; } if ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0 && t_datos.getValueAt(i, 9).toString().compareTo("N") == 0) || ((Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) > 0 && renglon >= 10)) || (renglon == 8 && Double.parseDouble(t_datos.getValueAt(i, 10).toString()) <= 0 && Double.parseDouble(t_datos.getValueAt(i, 11).toString()) <= 0 && Double.parseDouble(t_datos.getValueAt(i, 12).toString()) <= 0)) { if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) contenido = BaseColor.WHITE; else contenido = BaseColor.LIGHT_GRAY; if ((boolean) t_datos.getValueAt(i, 3) == false && (boolean) t_datos.getValueAt(i, 4) == false && t_datos.getValueAt(i, 5) != null) { //columna0 if (t_datos.getValueAt(i, 5) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 5).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna1 if (t_datos.getValueAt(i, 6) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 6).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna2 tabla.addCell(reporte.celda(t_datos.getValueAt(i, renglon).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); //columna3 if (t_datos.getValueAt(i, 14) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 14).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna4 tabla.addCell(reporte.celda(t_datos.getValueAt(i, 2).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); //columna5 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); else { switch (renglon) { case 8: tabla.addCell(reporte.celda("N", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 10: tabla.addCell(reporte.celda("D", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 11: tabla.addCell(reporte.celda("R", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; case 12: tabla.addCell(reporte.celda("M", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); break; } } //columna6 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 15)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna7 $tot aut. double n; n = BigDecimal .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) * Double.parseDouble(t_datos.getValueAt(i, 15).toString())) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna8 tabla.addCell(reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, 16)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna9 $tot com n = BigDecimal .valueOf(Double.parseDouble(t_datos.getValueAt(i, renglon).toString()) * Double.parseDouble(t_datos.getValueAt(i, 16).toString())) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //columna10 11 if (renglon == 8 && t_datos.getValueAt(i, 9).toString().compareTo("-") == 0) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { switch (renglon) { case 8: n = BigDecimal.valueOf( Double.parseDouble(t_datos.getValueAt(i, 16).toString()) / 0.9d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 10: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.72d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 11: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.65d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; case 12: n = BigDecimal .valueOf( Double.parseDouble(t_datos.getValueAt(i, 15).toString()) * 0.65d) .setScale(2, RoundingMode.UP).doubleValue(); tabla.addCell(reporte.celda( formatoPorcentaje.format(n * Double.parseDouble( t_datos.getValueAt(i, renglon).toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(n), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); break; } } //columna12 if (t_datos.getValueAt(i, 18) == null) { tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 18).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } //columna13 if (t_datos.getValueAt(i, 19) == null) { tabla.addCell(reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda(t_datos.getValueAt(i, 19).toString(), font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } //columna14 tabla.addCell( reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } } } } tabla.addCell(reporte.celda("Total", font, contenido, derecha, 11, 1, Rectangle.NO_BORDER)); tabla.addCell( reporte.celda(formatoPorcentaje.format(Double.parseDouble(total.getValue().toString())), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, centro, 3, 1, Rectangle.NO_BORDER)); tabla.setHeaderRows(1); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:Almacen.Reporte2.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);// w w w . ja v a 2 s . com if (t_datos1.getRowCount() > 0) { javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { Session session = HibernateUtil.getSessionFactory().openSession(); try { DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); session.beginTransaction().begin(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); //Orden ord=buscaApertura(); PDF reporte = new PDF(); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); reporte.Abrir2(PageSize.LETTER, "reporte almacen", ruta + ".pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float[] nuevos = new float[] { 20, 150, 20, 100, 70, 20, 60 }; PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_LEFT); cabecera(reporte, bf, tabla, "Reporte de material a " + cb_tipo.getSelectedItem().toString() + " orden: " + t_busca.getText(), 2); for (int ren = 0; ren < t_datos1.getRowCount(); ren++) { for (int col = 0; col < t_datos1.getColumnCount(); col++) { try { tabla.addCell(reporte.celda(t_datos1.getValueAt(ren, col).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } catch (Exception e) { tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } } } tabla.setHeaderRows(1); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto."); } if (session != null) if (session.isOpen()) session.close(); } } } }
From source file:Almacen.Reporte2.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);/*from ww w. j a v a 2 s . co m*/ if (t_datos.getRowCount() > 0) { javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { Session session = HibernateUtil.getSessionFactory().openSession(); try { DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); session.beginTransaction().begin(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); //Orden ord=buscaApertura(); PDF reporte = new PDF(); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); reporte.Abrir2(PageSize.LETTER, "reporte almacen", ruta + ".pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float[] nuevos = new float[] { 36, 140, 86, 36, 40, 45, 37, 50, 42, 60 }; PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_LEFT); cabecera(reporte, bf, tabla, "Reporte de movimientos de pedidos en almacen", 1); for (int ren = 0; ren < t_datos.getRowCount(); ren++) { for (int col = 0; col < t_datos.getColumnCount(); col++) { try { if (col == 7) tabla.addCell(reporte.celda( formatoPorcentaje.format(t_datos.getValueAt(ren, col)), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(t_datos.getValueAt(ren, col).toString(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } catch (Exception e) { tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); } } } tabla.setHeaderRows(1); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto."); } if (session != null) if (session.isOpen()) session.close(); } } } }
From source file:Almacen.Reporte2.java
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);//ww w . ja v a 2 s . com if (t_datos2.getRowCount() > 0) { javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser(); jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" })); String ruta = null; if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) { ruta = jF1.getSelectedFile().getAbsolutePath(); if (ruta != null) { Session session = HibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction().begin(); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); PDF reporte = new PDF(); Date fecha = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS String valor = dateFormat.format(fecha); reporte.Abrir2(PageSize.LETTER, "reporte pedidos", ruta + ".pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float[] nuevos = new float[] { 60, 340, 170, 60, 90, 90, 90 }; PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_CENTER); cabecera1(reporte, bf, tabla, "Reporte de Consultar Pedidos.", 1); for (int ren = 0; ren < t_datos2.getRowCount(); ren++) { for (int col = 0; col < t_datos2.getColumnCount(); col++) { try { tabla.addCell(reporte.celda(t_datos2.getValueAt(ren, col).toString(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } catch (Exception e) { tabla.addCell( reporte.celda("", font, contenido, centro, 0, 1, Rectangle.RECTANGLE)); } } } tabla.setHeaderRows(1); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar2(ruta + ".pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto."); } if (session != null) if (session.isOpen()) session.close(); } } } }
From source file:analizadorventas.controlador.ControladorPdf.java
/** * @param lista /*w ww . ja v a2 s .c o m*/ */ public static void CrearPdf(List<Transaccion> lista) { try { Document documento = new Document(); PdfWriter.getInstance(documento, new FileOutputStream(new File("acercaDe.pdf"))); documento.open(); PdfPTable fila = new PdfPTable(5); fila.setHeaderRows(1); for (String cadena : header) { fila.addCell(cadena); } for (Transaccion transaccion : lista) { fila.setSpacingAfter(10); fila.addCell(transaccion.getNombreCliente()); fila.addCell(transaccion.getProductoComprado()); fila.addCell(transaccion.getPrecio() + ""); fila.addCell(transaccion.getFecha()); fila.addCell(transaccion.getCiudad()); } documento.add(fila); documento.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(ControladorPdf.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:be.thomasmore.service.CreatePDFServiceImp.java
@Override public void createPDF(List<Score> scores) { try {/*from ww w . ja v a 2s . c o m*/ OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); document.add(new Paragraph("Scores")); document.add(new Paragraph(new Date().toString())); document.addAuthor("Projectgroep 4"); document.addCreator("Projectgroep 4"); document.addTitle("ScoreTracker"); //Create Paragraph Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); //New line paragraph.add(new Paragraph(" ")); paragraph.add("Scores"); paragraph.add(new Paragraph(" ")); document.add(paragraph); //Create a table in PDF PdfPTable pdftabel = new PdfPTable(4); PdfPCell cell1 = new PdfPCell(new Phrase("Student")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Vak")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Test")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Score")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); pdftabel.setHeaderRows(1); for (Score score : scores) { pdftabel.addCell(score.getStudent().getNaam()); pdftabel.addCell(score.getTest().getVak().getNaam()); pdftabel.addCell(score.getTest().getNaam()); int resultaat = score.getScore(); pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal()); } document.add(pdftabel); document.addCreationDate(); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:be.thomasmore.service.CreatePDFServiceImp.java
@Override public void createPDFVoorStudent(ArrayList<ArrayList<Score>> puntenlijst, List<Double> gemiddeldelijst, Double totaalGemiddelde) { try {/*from w w w . j av a 2 s. com*/ OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); document.add(new Paragraph("Scores")); document.add(new Paragraph(puntenlijst.get(0).get(0).getStudent().getNaam())); document.add(new Paragraph(new Date().toString())); document.addAuthor("Projectgroep 4"); document.addCreator("Projectgroep 4"); document.addTitle("ScoreTracker"); //Create Paragraph Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); //New line paragraph.add(new Paragraph(" ")); paragraph.add("Scores"); paragraph.add(new Paragraph(" ")); document.add(paragraph); for (int i = 0; i < puntenlijst.size(); i++) { //Create a table in PDF PdfPTable pdftabel = new PdfPTable(2); //vak invullen paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); paragraph.add(new Paragraph(puntenlijst.get(i).get(0).getTest().getVak().getNaam())); document.add(paragraph); PdfPCell cell1 = new PdfPCell(new Phrase("Test")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Score")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); pdftabel.setHeaderRows(1); for (Score score : puntenlijst.get(i)) { pdftabel.addCell(score.getTest().getNaam()); int resultaat = score.getScore(); pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal()); } document.add(pdftabel); //gemmidelde per vak invoeren paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); paragraph.add(new Paragraph("Gemiddelde: " + gemiddeldelijst.get(i).toString())); document.add(paragraph); } paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); paragraph.add(new Paragraph("Algemeen gemiddelde: " + totaalGemiddelde)); document.add(paragraph); document.addCreationDate(); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }