List of usage examples for com.itextpdf.text PageSize LETTER
Rectangle LETTER
To view the source code for com.itextpdf.text PageSize LETTER.
Click Source Link
From source file:Separator.java
License:Apache License
public static void crop(String inFileName, String outFileName, int split, boolean vert) throws Exception { PdfReader reader = new PdfReader(new File(inFileName).getAbsolutePath()); String PDFName = outFileName.substring(outFileName.lastIndexOf("Folder\\") + 7, outFileName.indexOf(".pdf")); File fn = new File(scanFolder + PDFName + "\\" + PDFName + "_split_" + split + ".pdf"); fn.getParentFile().mkdirs();/*from w ww . java2 s.c om*/ int count = reader.getNumberOfPages(); Document doc = new Document(); PdfCopy copy = new PdfCopy(doc, new FileOutputStream(fn.getAbsolutePath())); doc.open(); if (vert) { for (int i = 1; i <= count; i++) { reader.getPageN(i).put(PdfName.CROPBOX, new PdfRectangle(PageSize.LETTER)); copy.addPage(copy.getImportedPage(reader, i)); } } else { if (!doubSided) { for (int j = 1; j <= count; j++) { reader.getPageN(j).put(PdfName.CROPBOX, new PdfRectangle((new Rectangle(0, 180, 792, 792)))); PdfDictionary pageDict; int rot = reader.getPageRotation(j); pageDict = reader.getPageN(j); pageDict.put(PdfName.ROTATE, new PdfNumber(rot + 90)); copy.addPage(copy.getImportedPage(reader, j)); } } else { for (int j = 1; j <= count; j++) { reader.getPageN(j).put(PdfName.CROPBOX, new PdfRectangle(new Rectangle(0, 180, 792, 792))); PdfDictionary pageDict; pageDict = reader.getPageN(j); if (j % 2 == 0) { // even pageDict.put(PdfName.ROTATE, new PdfNumber(270)); } else { // odd pageDict.put(PdfName.ROTATE, new PdfNumber(90)); } copy.addPage(copy.getImportedPage(reader, j)); } } } doc.close(); }
From source file:Almacen.formatosAlmacen.java
void formato() { h = new Herramientas(usr, 0); h.session(sessionPrograma);// ww w. j av a2s . c om Session session = HibernateUtil.getSessionFactory().openSession(); try { miAlmacen = (Almacen) session.get(Almacen.class, miAlmacen.getIdAlmacen()); DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); 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); Movimiento[] mov = (Movimiento[]) session.createCriteria(Movimiento.class) .add(Restrictions.eq("almacen.idAlmacen", miAlmacen.getIdAlmacen())).list() .toArray(new Movimiento[0]); Orden ord = null; if (mov.length > 0) ord = mov[0].getPartida().getOrdenByIdOrden(); //File folder = new File("reportes/"+ord.getIdOrden()); //folder.mkdirs(); reporte.Abrir(PageSize.LETTER, "Almacen", "reportes/" + ord.getIdOrden() + "/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float tam[] = new float[] { 20, 20, 80, 190, 20, 30, 50, 50 }; PdfPTable tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); int ren = 0; double total = 0d; if (mov.length > 0) { for (int i = 0; i < mov.length; i++) { int r = i + 1; //N tabla.addCell(reporte.celda("" + mov[i].getPartida().getIdEvaluacion(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); //# tabla.addCell(reporte.celda("" + mov[i].getPartida().getSubPartida(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (mov[i].getPartida().getEjemplar() != null) { //No de parte tabla.addCell(reporte.celda("" + mov[i].getPartida().getEjemplar().getIdParte(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } else tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //Descripcion tabla.addCell(reporte.celda(mov[i].getPartida().getCatalogo().getNombre(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); //med tabla.addCell(reporte.celda(mov[i].getPartida().getMed(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); //cant tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getPartida().getPcp()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); double sum = mov[i].getCantidad() * mov[i].getPartida().getPcp(); total += sum; tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (ren == 38) { reporte.agregaObjeto(tabla); reporte.writer.newPage(); tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); ren = -1; } ren++; } } tabla.addCell(reporte.celda("Notas:", font, contenido, izquierda, 0, 1, Rectangle.BOTTOM)); tabla.addCell(reporte.celda(miAlmacen.getNotas(), font, contenido, izquierda, 7, 1, Rectangle.BOTTOM)); if (miAlmacen.getTipoMovimiento() == 1) tabla.addCell(reporte.celda("Entrego: " + miAlmacen.getEntrego(), font, contenido, izquierda, 3, 1, Rectangle.NO_BORDER)); else tabla.addCell(reporte.celda("recibi:" + miAlmacen.getEntrego(), font, contenido, izquierda, 3, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda("Sub-total:", font, contenido, derecha, 4, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda(formatoPorcentaje.format(total), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("IVA:", font, contenido, derecha, 7, 1, Rectangle.NO_BORDER)); double iva = total * 0.16d; tabla.addCell(reporte.celda(formatoPorcentaje.format(iva), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("Total:", font, contenido, derecha, 7, 1, Rectangle.NO_BORDER)); total += iva; tabla.addCell(reporte.celda(formatoPorcentaje.format(total), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); session.beginTransaction().rollback(); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar( "reportes/" + ord.getIdOrden() + "/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(null, "No se pudo realizar el reporte si el archivo esta abierto."); } if (session != null) if (session.isOpen()) session.close(); }
From source file:Almacen.formatosOrden.java
void formato() { h = new Herramientas(usr, 0); h.session(sessionPrograma);/*from w w w . j a v a 2 s . c o m*/ Session session = HibernateUtil.getSessionFactory().openSession(); try { miAlmacen = (Almacen) session.get(Almacen.class, miAlmacen.getIdAlmacen()); DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); 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); Movimiento[] mov = (Movimiento[]) session.createCriteria(Movimiento.class) .add(Restrictions.eq("almacen.idAlmacen", miAlmacen.getIdAlmacen())).list() .toArray(new Movimiento[0]); Orden ord = null; if (mov.length > 0) { if (mov[0].getPartida() != null) { ord = mov[0].getPartida().getOrdenByIdOrden(); } else { ord = mov[0].getPartidaExterna().getPedido().getOrden(); //ord=miAlmacen.getPedido().getPartida().getOrdenByIdOrden(); //ord=mov[0].getOrden(); } } File folder = new File("reportes/" + ord.getIdOrden()); folder.mkdirs(); reporte.Abrir(PageSize.LETTER, "Almacen", "reportes/" + ord.getIdOrden() + "/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float tam[] = new float[] { 20, 20, 80, 190, 20, 30 }; PdfPTable tabla = reporte.crearTabla(6, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); int ren = 0; double total = 0d; if (mov.length > 0) { int renglon = 0; for (int i = 0; i < mov.length; i++) { int r = i + 1; renglon++; if (mov[i].getPartida() != null) { tabla.addCell(reporte.celda("" + mov[i].getPartida().getIdEvaluacion(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("" + mov[i].getPartida().getSubPartida(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (mov[i].getPartida().getEjemplar() != null) tabla.addCell(reporte.celda("" + mov[i].getPartida().getEjemplar().getIdParte(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartida().getCatalogo().getNombre(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartida().getMed(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda("-", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (mov[i].getPartidaExterna().getNoParte() != null) tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getNoParte(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getDescripcion(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getUnidad(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } if (ren == 20)//20 { reporte.writer.newPage(); reporte.agregaObjeto(tabla); 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(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); tabla = reporte.crearTabla(6, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); ren = -1; renglon = 0; } ren++; } for (renglon = renglon; renglon < 20; renglon++) { tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } } tabla.addCell(reporte.celda("Notas: ", font, contenido, izquierda, 0, 1, Rectangle.BOTTOM)); tabla.addCell(reporte.celda(miAlmacen.getNotas(), font, contenido, izquierda, 7, 1, Rectangle.BOTTOM)); session.beginTransaction().rollback(); reporte.agregaObjeto(tabla); 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(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar( "reportes/" + ord.getIdOrden() + "/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(null, "No se pudo realizar el reporte si el archivo esta abierto"); } if (session != null) if (session.isOpen()) session.close(); }
From source file:Almacen.formatosPedido.java
void formato() { h = new Herramientas(usr, 0); h.session(sessionPrograma);/*from w w w.ja v a 2 s .c o m*/ Session session = HibernateUtil.getSessionFactory().openSession(); try { miAlmacen = (Almacen) session.get(Almacen.class, miAlmacen.getIdAlmacen()); DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00"); formatoPorcentaje.setMinimumFractionDigits(2); 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); Movimiento[] mov = (Movimiento[]) session.createCriteria(Movimiento.class) .add(Restrictions.eq("almacen.idAlmacen", miAlmacen.getIdAlmacen())).list() .toArray(new Movimiento[0]); Orden ord = null; OrdenExterna ordEx = null; if (mov.length > 0) { if (miAlmacen.getOperacion() == 1) ord = mov[0].getPartida().getOrdenByIdOrden(); /*if(miAlmacen.getOperacion()==2) ordEx=miAlmacen.getPedido().getOrdenExterna();*/ if (miAlmacen.getOperacion() == 3) ord = miAlmacen.getPedido().getOrden(); //ord=miAlmacen.getPedido().getPartida().getOrdenByIdOrden(); } File folder = new File("reportes"); folder.mkdirs(); reporte.Abrir(PageSize.LETTER, "Almacen", "reportes/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf"); Font font = new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD); BaseColor contenido = BaseColor.WHITE; int centro = Element.ALIGN_CENTER; int izquierda = Element.ALIGN_LEFT; int derecha = Element.ALIGN_RIGHT; float tam[]; PdfPTable tabla; if (miAlmacen.getOperacion() != 6) { tam = new float[] { 20, 20, 80, 190, 20, 30, 50, 50 }; tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); } else { tam = new float[] { 20, 20, 80, 190, 20, 30 }; tabla = reporte.crearTabla(6, tam, 100, Element.ALIGN_LEFT); } cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); int ren = 0; double total = 0d; if (mov.length > 0) { int renglon = 0; for (int i = 0; i < mov.length; i++) { if (miAlmacen.getOperacion() == 1) { int r = i + 1; renglon++; tabla.addCell(reporte.celda("" + mov[i].getPartida().getIdEvaluacion(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("" + mov[i].getPartida().getSubPartida(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (mov[i].getPartida().getEjemplar() != null) tabla.addCell(reporte.celda("" + mov[i].getPartida().getEjemplar().getIdParte(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartida().getCatalogo().getNombre(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartida().getMed(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getPartida().getPcp()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); double sum = mov[i].getCantidad() * mov[i].getPartida().getPcp(); total += sum; tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (ren == 20)//20 { reporte.writer.newPage(); reporte.agregaObjeto(tabla); 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(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); ren = -1; renglon = 0; } ren++; } if (miAlmacen.getOperacion() == 2 || miAlmacen.getOperacion() == 6) { int r = i + 1; renglon++; tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (mov[i].getPartidaExterna().getNoParte() != null) tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getNoParte(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getDescripcion(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getUnidad(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (miAlmacen.getOperacion() == 2) { tabla.addCell( reporte.celda(formatoPorcentaje.format(mov[i].getPartidaExterna().getCosto()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); double sum = mov[i].getCantidad() * mov[i].getPartidaExterna().getCosto(); total += sum; tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } if (ren == 20)//20 { reporte.writer.newPage(); reporte.agregaObjeto(tabla); 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(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); ren = -1; renglon = 0; } ren++; } if (miAlmacen.getOperacion() == 3) { int r = i + 1; renglon++; //tabla.addCell(reporte.celda(""+miAlmacen.getPedido().getPartida().getIdEvaluacion(), font, contenido, izquierda, 0,1,Rectangle.RECTANGLE)); //tabla.addCell(reporte.celda(""+miAlmacen.getPedido().getPartida().getSubPartida(), font, contenido, derecha, 0,1,Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (mov[i].getPartidaExterna().getNoParte() != null) tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getNoParte(), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); else tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); //tabla.addCell(reporte.celda(miAlmacen.getPedido().getPartida().getCatalogo().getNombre()+"/"+mov[i].getPartidaExterna().getDescripcion(), font, contenido, izquierda, 0,1,Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getDescripcion(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(mov[i].getPartidaExterna().getUnidad(), font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getCantidad()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(formatoPorcentaje.format(mov[i].getPartidaExterna().getCosto()), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); double sum = mov[i].getCantidad() * mov[i].getPartidaExterna().getCosto(); total += sum; tabla.addCell(reporte.celda(formatoPorcentaje.format(sum), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); if (ren == 20)//20 { reporte.writer.newPage(); reporte.agregaObjeto(tabla); 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(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); tabla = reporte.crearTabla(8, tam, 100, Element.ALIGN_LEFT); cabeceraCompra(reporte, bf, tabla, miAlmacen, ord); ren = -1; renglon = 0; } ren++; } } for (renglon = renglon; renglon < 20; renglon++) { tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda(" ", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } } tabla.addCell(reporte.celda("Notas: ", font, contenido, izquierda, 0, 1, Rectangle.BOTTOM)); tabla.addCell(reporte.celda(miAlmacen.getNotas(), font, contenido, izquierda, tabla.getNumberOfColumns() - 1, 1, Rectangle.BOTTOM)); if (miAlmacen.getOperacion() != 6) { tabla.addCell(reporte.celda("", font, contenido, izquierda, 3, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda("Sub-total:", font, contenido, derecha, 4, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda(formatoPorcentaje.format(total), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("IVA:", font, contenido, derecha, 7, 1, Rectangle.NO_BORDER)); Configuracion con = (Configuracion) session.get(Configuracion.class, 1); double iva = total * con.getIva() / 100; tabla.addCell(reporte.celda(formatoPorcentaje.format(iva), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); tabla.addCell(reporte.celda("Total:", font, contenido, derecha, 7, 1, Rectangle.NO_BORDER)); total += iva; tabla.addCell(reporte.celda(formatoPorcentaje.format(total), font, contenido, derecha, 0, 1, Rectangle.RECTANGLE)); } else { tabla.addCell(reporte.celda("", font, contenido, izquierda, 8, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda("", font, contenido, derecha, 8, 1, Rectangle.NO_BORDER)); tabla.addCell(reporte.celda("", font, contenido, derecha, 8, 1, Rectangle.RECTANGLE)); } session.beginTransaction().rollback(); reporte.agregaObjeto(tabla); 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(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(new Paragraph(" ")); reporte.agregaObjeto(tabla); reporte.cerrar(); reporte.visualizar("reportes/" + valor + "-" + miAlmacen.getIdAlmacen() + "-almacen.pdf"); } catch (Exception e) { System.out.println(e); e.printStackTrace(); JOptionPane.showMessageDialog(null, "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 jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed // TODO add your handling code here: h = new Herramientas(usr, 0); h.session(sessionPrograma);/*from w w w .j a va2 s .c o m*/ 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 w w w. j a v a2 s .c om*/ 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);//from ww w. j a v a 2 s. c o m 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:AppPackage.printPDF.java
public void printNow(String id, String name, String dateRange, String underLate, String workedHours, String totalHours, String dateNow, String fDate, String lDate, String type, String empTypeRate, int lastRId, double salary) { this.id = id; this.name = name; this.dateRange = dateRange; this.underLate = underLate; this.workedHours = workedHours; this.totalHours = totalHours; this.dateNow = dateNow; this.fDate = fDate; this.lDate = lDate; this.type = type; this.empTypeRate = empTypeRate; this.lastRId = lastRId; this.salary = salary; try {/*w w w . j a va 2s . c o m*/ Document document = new Document(); Connection conn = null; Statement st = null; conn = dbC.getConnection(); st = conn.createStatement(); String query = "SELECT * FROM schedule WHERE empId ='" + id + "'"; ResultSet rs = st.executeQuery(query); PdfWriter.getInstance(document, new FileOutputStream("reports/Report-" + reportCount + "." + lastRId + "-" + id + ".pdf")); document.open(); document.setPageSize(PageSize.LETTER); document.setMargins(0f, 0f, 0f, 0f); Image image = Image.getInstance("Resources/DTRHeaderTwo.png"); document.add(image); PdfPTable ICTable = new PdfPTable(5); ICTable.setWidthPercentage(100); ICTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell ICTableCell; Phrase ICBlank = new Phrase(); Phrase ICharge = new Phrase(); Phrase ICBlanko = new Phrase(); Phrase ICBlankx = new Phrase(); Phrase IChargex = new Phrase(); ICBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); ICTable.addCell(ICBlank); ICharge.add(new Chunk("_____________________", new Font(Font.FontFamily.HELVETICA, 8, Font.ITALIC))); ICTable.addCell(ICharge); ICBlanko.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); ICTable.addCell(ICBlanko); ICBlankx.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); ICTable.addCell(ICBlankx); IChargex.add(new Chunk("____________________", new Font(Font.FontFamily.HELVETICA, 8, Font.ITALIC))); ICTable.addCell(IChargex); ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell( new Phrase("In - Charge", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell( new Phrase("In - Charge", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); PdfPTable dateRecTable = new PdfPTable(5); dateRecTable.setWidthPercentage(100); dateRecTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell dateRecTableCell; Phrase dRDate = new Phrase(); Phrase dRNo = new Phrase(); Phrase dRBlank = new Phrase(); Phrase dRDatex = new Phrase(); Phrase dRNox = new Phrase(); dRDate.add( new Chunk("Released #: " + lastRId + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRDate); dRNo.add(new Chunk("" + dateNow + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRNo); dRBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRBlank); dRDatex.add( new Chunk("Released #: " + lastRId + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRDatex); dRNox.add(new Chunk("" + dateNow + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRNox); PdfPTable InfoTable = new PdfPTable(5); InfoTable.setWidthPercentage(100); InfoTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell InfoTableCell; Phrase infoId = new Phrase(); Phrase infoType = new Phrase(); Phrase infoBlank = new Phrase(); Phrase infoIdx = new Phrase(); Phrase infoTypex = new Phrase(); infoId.add(new Chunk("ID: " + id + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoId); infoType.add(new Chunk("Type: " + type + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoType); infoBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoBlank); infoIdx.add(new Chunk("ID: " + id + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoIdx); infoTypex.add(new Chunk("Type: " + type + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoTypex); InfoTableCell = new PdfPCell( new Phrase("Fullname: " + name + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Hourly Rate: " + empTypeRate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell( new Phrase("Fullname: " + name + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Hourly Rate: " + empTypeRate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Date Range: \n" + dateRange + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Total Hours: " + totalHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Date Range: \n" + dateRange + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Total Hours: " + totalHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Late & Under Time: " + underLate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Worked Hours: " + workedHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Late & Under Time: " + underLate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Worked Hours: " + workedHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell( new Phrase("Salary: " + salary + " PHP", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell( new Phrase("Salary: " + salary + " PHP", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); PdfPTable SchedTable = new PdfPTable(17); SchedTable.setWidthPercentage(100); SchedTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell SchedTableCell; Phrase phraseDayS = new Phrase(); Phrase phraseAMTotal = new Phrase(); Phrase phraseAMStart = new Phrase(); Phrase phraseAMEnd = new Phrase(); Phrase phrasePMTotal = new Phrase(); Phrase phrasePMStart = new Phrase(); Phrase phrasePMEnd = new Phrase(); Phrase phraseTotalTime = new Phrase(); Phrase phraseBlankS = new Phrase(); Phrase phraseDaySx = new Phrase(); Phrase phraseAMTotalx = new Phrase(); Phrase phraseAMStartx = new Phrase(); Phrase phraseAMEndx = new Phrase(); Phrase phrasePMTotalx = new Phrase(); Phrase phrasePMStartx = new Phrase(); Phrase phrasePMEndx = new Phrase(); Phrase phraseTotalTimex = new Phrase(); phraseDayS.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseDayS); phraseAMStart.add(new Chunk("AM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMStart); phraseAMEnd.add(new Chunk("AM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMEnd); phraseAMTotal.add(new Chunk("AM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMTotal); phrasePMStart.add(new Chunk("PM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMStart); phrasePMEnd.add(new Chunk("PM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMEnd); phrasePMTotal.add(new Chunk("PM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMTotal); phraseTotalTime.add(new Chunk("Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseTotalTime); phraseBlankS.add(new Chunk(" ", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseBlankS); phraseDaySx.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseDaySx); phraseAMStartx.add(new Chunk("AM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMStartx); phraseAMEndx.add(new Chunk("AM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMEndx); phraseAMTotalx.add(new Chunk("AM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMTotalx); phrasePMStartx.add(new Chunk("PM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMStartx); phrasePMEndx.add(new Chunk("PM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMEndx); phrasePMTotalx.add(new Chunk("PM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMTotalx); phraseTotalTimex.add(new Chunk("Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseTotalTimex); while (rs.next()) { SimpleDateFormat readingFormat = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat outputFormat = new SimpleDateFormat("hh:mm a"); String dayxxx = rs.getString("day"); String amStartxx = rs.getString("amStart"); String amEndxx = rs.getString("amEnd"); String pmStartxx = rs.getString("pmStart"); String pmEndxx = rs.getString("pmEnd"); String amTotalxx = rs.getString("amTotal"); String pmTotalxx = rs.getString("pmTotal"); String totalHoursxx = rs.getString("totalTime"); String blank = " "; String amStart = null; String amEnd = null; String amTotal = null; String pmStart = null; String pmEnd = null; String pmTotal = null; String totalHoursx = null; Date dayx = new SimpleDateFormat("EEEE").parse(dayxxx); SimpleDateFormat sdfxxx = new SimpleDateFormat("EEE"); String day = sdfxxx.format(dayx); System.out.println(day + " day"); try { Date amStartTxx = readingFormat.parse(amStartxx); amStart = outputFormat.format(amStartTxx); if (amStart.equals("12:00 AM")) { amStart = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date amEndTx = readingFormat.parse(amEndxx); amEnd = outputFormat.format(amEndTx); if (amEnd.equals("12:00 AM")) { amEnd = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date amTotalTx = readingFormat.parse(amTotalxx); amTotal = outputFormat.format(amTotalTx); if (amTotal.equals("12:00 AM")) { amTotal = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date pmStartTxx = readingFormat.parse(pmStartxx); pmStart = outputFormat.format(pmStartTxx); if (pmStart.equals("12:00 AM")) { pmStart = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date pmEndTxx = readingFormat.parse(pmEndxx); pmEnd = outputFormat.format(pmEndTxx); if (pmEnd.equals("12:00 AM")) { pmEnd = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date pmTotalTxx = readingFormat.parse(pmTotalxx); pmTotal = outputFormat.format(pmTotalTxx); if (pmTotal.equals("12:00 AM")) { pmTotal = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date totalHoursxT = readingFormat.parse(totalHoursxx); totalHoursx = outputFormat.format(totalHoursxT); if (totalHoursx.equals("12:00 AM")) { totalHoursx = "00:00"; } } catch (Exception e) { e.printStackTrace(); } System.out.println(day); System.out.println(amStart); System.out.println(amEnd); System.out.println(amTotal); System.out.println(pmStart); System.out.println(pmEnd); System.out.println(pmTotal); System.out.println(totalHoursx); SchedTableCell = new PdfPCell(new Phrase(day, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(totalHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell(new Phrase(blank)); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell(new Phrase(day, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(totalHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); } PdfPTable DTRTable = new PdfPTable(17); DTRTable.setWidthPercentage(100); DTRTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell DTRTableCell; Phrase phraseDay = new Phrase(); Phrase phraseDate = new Phrase(); Phrase phraseAMIn = new Phrase(); Phrase phraseAMOut = new Phrase(); Phrase phrasePMIn = new Phrase(); Phrase phrasePMOut = new Phrase(); Phrase phraseHours = new Phrase(); Phrase phraseUTL = new Phrase(); Phrase phraseBlank = new Phrase(); Phrase phraseDayx = new Phrase(); Phrase phraseDatex = new Phrase(); Phrase phraseAMInx = new Phrase(); Phrase phraseAMOutx = new Phrase(); Phrase phrasePMInx = new Phrase(); Phrase phrasePMOutx = new Phrase(); Phrase phraseHoursx = new Phrase(); Phrase phraseUTLx = new Phrase(); phraseDay.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDay); phraseDate.add(new Chunk("Date", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDate); phraseAMIn.add(new Chunk("AM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMIn); phraseAMOut.add(new Chunk("AM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMOut); phrasePMIn.add(new Chunk("PM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMIn); phrasePMOut.add(new Chunk("PM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMOut); phraseHours.add(new Chunk("Hours", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseHours); phraseUTL.add(new Chunk("Late/U.T", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseUTL); phraseBlank.add(new Chunk(" ", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseBlank); phraseDayx.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDayx); phraseDatex.add(new Chunk("Date", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDatex); phraseAMInx.add(new Chunk("AM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMInx); phraseAMOutx.add(new Chunk("AM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMOutx); phrasePMInx.add(new Chunk("PM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMInx); phrasePMOutx.add(new Chunk("PM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMOutx); phraseHoursx.add(new Chunk("Hours", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseHoursx); phraseUTLx.add(new Chunk("Late/U.T", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseUTLx); try { Connection connx = null; Statement stx = null; connx = dbC.getConnection(); stx = connx.createStatement(); String queryx = "SELECT timeinout.day, timeinout.date, schedule.totalTime, schedule.amTotal, " + "schedule.amStart, timeinout.amTimeIn, schedule.amEnd, timeinout.amTimeOut, " + "schedule.pmTotal, schedule.pmStart, timeinout.pmTimeIn, schedule.pmEnd, " + "timeinout.pmTimeOut FROM timeinout LEFT JOIN " + "(schedule) ON (schedule.empId = timeinout.empId AND timeinout.day = schedule.day) WHERE " + "timeinout.empId ='" + id + "' AND schedule.empId = '" + id + "' AND date(`Date`) >= '" + fDate + "' " + "AND date(`Date`) <= '" + lDate + "'"; ResultSet rsx = stx.executeQuery(queryx); while (rsx.next()) { String day = rsx.getString("timeinout.day"); String date = rsx.getString("timeinout.date"); String amStartDB = rsx.getString("schedule.amStart"); String amIn = rsx.getString("timeinout.amTimeIn"); String amEndDB = rsx.getString("schedule.amEnd"); String amOut = rsx.getString("timeinout.amTimeOut"); String pmStartDB = rsx.getString("schedule.pmStart"); String pmIn = rsx.getString("timeinout.pmTimeIn"); String pmEndDB = rsx.getString("schedule.pmEnd"); String pmOut = rsx.getString("timeinout.pmTimeOut"); String totTime = rsx.getString("schedule.totalTime"); String wHours; String blank = " "; String dayx = rsx.getString("timeinout.day"); String datex = rsx.getString("timeinout.date"); // String amStartDBx = rsx.getString("schedule.amStart"); // String amInx = rsx.getString("timeinout.amTimeIn"); // String amEndDBx = rsx.getString("schedule.amEnd"); // String amOutx = rsx.getString("timeinout.amTimeOut"); // String pmStartDBx = rsx.getString("schedule.pmStart"); // String pmInx = rsx.getString("timeinout.pmTimeIn"); // String pmEndDBx = rsx.getString("schedule.pmEnd"); String pmOutx = rsx.getString("timeinout.pmTimeOut"); String totalAM = rsx.getString("schedule.amTotal"); String totalPM = rsx.getString("schedule.pmTotal"); String totTimex = rsx.getString("schedule.totalTime"); String wHoursx; parser.setTimeZone(TimeZone.getTimeZone("UTC")); if (!amEndDB.equals("00:00:00") && !amOut.equals("00:00:00")) { Start = parser.parse(amEndDB); In = parser.parse(amOut); if (Start.after(In)) { amOutDiff = tDiff.timeDiff(amOut, amEndDB); amOutDiffT = parser.parse(amOutDiff); amOutDiffTotal += amOutDiffT.getTime(); } else { amOutDiff = "00:00:00"; } } else { amOutDiff = totalAM; amOutDiffT = parser.parse(amOutDiff); amOutDiffTotal += amOutDiffT.getTime(); } Start = parser.parse(amStartDB); In = parser.parse(amIn); if (Start.after(In)) { amInDiff = "00:00:00"; } else if (amOutDiff.equals(totalAM)) { amInDiff = "00:00:00"; } else { amInDiff = tDiff.timeDiff(amStartDB, amIn); amInDiffT = parser.parse(amInDiff); amInDiffTotal += amInDiffT.getTime(); } if (!pmEndDB.equals("00:00:00") && !pmOut.equals("00:00:00")) { Start = parser.parse(pmEndDB); In = parser.parse(pmOut); if (Start.after(In)) { pmOutDiff = tDiff.timeDiff(pmOut, pmEndDB); pmOutDiffT = parser.parse(pmOutDiff); pmOutDiffTotal += pmOutDiffT.getTime(); } else { pmOutDiff = "00:00:00"; } } else { pmOutDiff = totalPM; pmOutDiffT = parser.parse(pmOutDiff); pmOutDiffTotal += pmOutDiffT.getTime(); } Start = parser.parse(pmStartDB); In = parser.parse(pmIn); if (Start.after(In)) { pmInDiff = "00:00:00"; } else if (pmOutDiff.equals(totalPM)) { pmInDiff = "00:00:00"; } else { pmInDiff = tDiff.timeDiff(pmStartDB, pmIn); pmInDiffT = parser.parse(pmInDiff); pmInDiffTotal += pmInDiffT.getTime(); } Date totH = parser.parse(totTimex); long totHTotal = 0; totHTotal += totH.getTime(); Date amInDiffx = parser.parse(amInDiff); Date amOutDiffx = parser.parse(amOutDiff); Date pmInDiffx = parser.parse(pmInDiff); Date pmOutDiffx = parser.parse(pmOutDiff); long workedHoursxxx = amInDiffx.getTime() + amOutDiffx.getTime() + pmInDiffx.getTime() + pmOutDiffx.getTime(); long hoursx = workedHoursxxx / 3600000; long minutesx = (workedHoursxxx % 3600000) / 60000; wHours = String.format("%02d:%02d", hoursx, minutesx); wHoursx = String.format("%02d:%02d", hoursx, minutesx); Date dayxxx = new SimpleDateFormat("EEEE").parse(day); SimpleDateFormat sdfxxx = new SimpleDateFormat("EEE"); String newDayxx = sdfxxx.format(dayxxx); System.out.println(newDayxx); DTRTableCell = new PdfPCell( new Phrase(newDayxx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); Date datexx = new SimpleDateFormat("yyyy-MM-dd").parse(date); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy"); String newDate = sdf.format(datexx); System.out.println(newDate); DTRTableCell = new PdfPCell( new Phrase(newDate, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amIn); DTRTableCell = new PdfPCell( new Phrase(amIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amOut); DTRTableCell = new PdfPCell( new Phrase(amOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmIn); DTRTableCell = new PdfPCell( new Phrase(pmIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmOut); DTRTableCell = new PdfPCell( new Phrase(pmOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(totTime); DTRTableCell = new PdfPCell( new Phrase(totTime, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(wHours); DTRTableCell = new PdfPCell( new Phrase(wHours, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(blank); DTRTableCell = new PdfPCell(new Phrase(blank)); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); Date dayxx = new SimpleDateFormat("EEEE").parse(dayx); SimpleDateFormat sdfxx = new SimpleDateFormat("EEE"); String newDayx = sdfxx.format(dayxx); System.out.println(newDayx); DTRTableCell = new PdfPCell( new Phrase(newDayx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); Date datexxx = new SimpleDateFormat("yyyy-MM-dd").parse(datex); SimpleDateFormat sdfx = new SimpleDateFormat("dd-MM-yy"); String newDatex = sdfx.format(datexxx); System.out.println(newDatex); DTRTableCell = new PdfPCell( new Phrase(newDatex, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amIn); DTRTableCell = new PdfPCell( new Phrase(amIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amOut); DTRTableCell = new PdfPCell( new Phrase(amOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmIn); DTRTableCell = new PdfPCell( new Phrase(pmIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmOutx); DTRTableCell = new PdfPCell( new Phrase(pmOutx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(totTimex); DTRTableCell = new PdfPCell( new Phrase(totTimex, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(wHoursx); DTRTableCell = new PdfPCell( new Phrase(wHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } document.add(dateRecTable); document.add(InfoTable); document.add(new Paragraph( "----------------------------------------------------------------------- ----------------------------------------------------------------------", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.BLACK))); document.add(new Paragraph( " Schedule Schedule\n", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK))); document.add(SchedTable); document.add(new Paragraph( "----------------------------------------------------------------------- ----------------------------------------------------------------------", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.BLACK))); document.add(new Paragraph( " Dailty Time Record Dailty Time Record\n", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK))); document.add(DTRTable); document.add(ICTable); try { conn = dbC.getConnection(); PreparedStatement stmtx = conn.prepareStatement("INSERT INTO released" + "(empId, firstDate, lastDate, totalHours, lateUnderTime, workedHours, fileName, salary) VALUES (?,?,?,?,?,?,?,?)"); stmtx.setString(1, id); stmtx.setString(2, fDate); stmtx.setString(3, lDate); stmtx.setString(4, totalHours); stmtx.setString(5, workedHours); stmtx.setString(6, totalHours); stmtx.setString(7, "Report-" + reportCount + "." + lastRId + "-" + id + ".pdf"); stmtx.setString(8, salary + ""); stmtx.executeUpdate(); } catch (SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { //finally block used to close resources try { if (stmt != null) conn.close(); } catch (SQLException se) { } // do nothing try { if (conn != null) conn.close(); } catch (SQLException se) { se.printStackTrace(); } //end finally try } //end try document.close(); } catch (DocumentException | IOException | SQLException e) { JOptionPane.showMessageDialog(null, e); } catch (ParseException ex) { Logger.getLogger(printPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:avalonscrollmaker20.AnothakScribe.java
License:Open Source License
private void initializeDoc() { // Create a Document doc_scrolls = new Document(PageSize.LETTER, 18f, 18f, 18f, 18f); // Get a DocWriter instance try {//from w ww . j a v a 2 s .c o m doc_writer = PdfWriter.getInstance(doc_scrolls, new FileOutputStream(doc_name)); doc_writer.setPdfVersion(PdfWriter.VERSION_1_6); } catch (Exception ex) { System.err.println(ex + "\nProgram closing."); System.exit(3); } // Open the Document doc_scrolls.addTitle(doc_name.substring(0, doc_name.length() - 3)); doc_scrolls.addSubject("A collection of Avalon-legal Anothak Scrolls"); doc_scrolls.addAuthor("Michael Weigle"); doc_scrolls.addCreator("Avalon Scrollmaker 2.0, powered by iText"); doc_scrolls.open(); }
From source file:cis_690_report.DynamicReporter.java
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed JFileChooser chooser = new JFileChooser(); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { if (chooser.getSelectedFile() != null) { File3 = chooser.getSelectedFile().getAbsolutePath(); }//from w ww. jav a 2s. c om try { br1 = new BufferedReader(new FileReader(f)); BufferedReader b1 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } String line = ""; bull1 = new String[number_of_rows - 1][]; int k = 0; BufferedReader br3 = null; try { br3 = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException ex) { } try { while ((line = br3.readLine()) != null) { // use comma as separator String Bull[] = line.split(","); if (k != 0) { System.out.println(Bull.length); bull1[k - 1] = new String[Bull.length]; for (int j = 0; j < Bull.length; j++) { bull1[k - 1][j] = Bull[j]; } } k++; } } catch (IOException ex) { } Document doc = new Document(); PdfWriter docWriter = null; DecimalFormat df = new DecimalFormat("0.00"); try { //special font sizes Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0)); Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6); Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); Font bfBold25 = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD); //file path docWriter = PdfWriter.getInstance(doc, new FileOutputStream(File3)); //document header attributes doc.addAuthor("Shubh Chopra"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Shubh Chopra"); doc.addTitle("BES"); doc.setPageSize(PageSize.LETTER.rotate()); //open document doc.open(); //create a paragraph Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n"); paragraph.setFont(bfBold25); paragraph.setAlignment(Element.ALIGN_CENTER); Image img = Image.getInstance("VETMED.png"); img.scaleToFit(300f, 150f); doc.add(paragraph); PdfPTable table1 = new PdfPTable(2); table1.setWidthPercentage(100); PdfPCell cell = new PdfPCell(img); cell.setBorder(PdfPCell.NO_BORDER); table1.addCell(cell); String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64] + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: " + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n"; table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT)); doc.add(table1); //specify column widths int temp = dlm2.size(); float[] columnWidths = new float[temp]; for (int x = 0; x < columnWidths.length; x++) { columnWidths[x] = 2f; } //create PDF table with the given widths PdfPTable table = new PdfPTable(columnWidths); // set table width a percentage of the page width table.setWidthPercentage(90f); DynamicReporter re; re = new DynamicReporter(); for (int i = 0; i < dlm2.size(); i++) { String[] parts = dlm2.get(i).toString().split(": "); String part2 = parts[1]; re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12); } table.setHeaderRows(1); //insert an empty row //create section heading by cell merging //just some random data to fill for (int x = 0; x < dlm3.size(); x++) { String str = dlm3.get(x).toString(); System.out.println(str); String[] parts = str.split(":"); String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; for (int i = 0; i < dlm2.getSize(); i++) for (int j = 0; j < header.length && j < bull1[row].length; j++) { String str1 = dlm2.get(i).toString(); String[] p1 = str1.split(": "); String p2 = p1[0]; if (p2.equals(header[j])) { re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12); } } // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12); } doc.add(table); if (jCheckBox2.isSelected()) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (int i = 0; i < dlm3.size(); i++) { String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1); } else { dataSet.setValue(0, "Percent", header[j]); } } } JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false); if (dlm3.size() > 12) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); } if (jCheckBox1.isSelected()) { for (int i = 0; i < dlm3.size(); i++) { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); String str = dlm3.get(i).toString(); System.out.println(str); String[] parts = str.split(":"); String part1 = parts[0]; String part2 = parts[1]; System.out.println(part2); int row = Integer.parseInt(part2) - 1; float total = (float) 0.0; for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (bull1[row][j].equals("")) { continue; } else { total += Integer.parseInt(bull1[row][j]); } } System.out.println(total); for (int j = 77; j < header.length && j < bull1[row].length; j++) { if (!bull1[row][j].equals("")) { String[] Parts = header[j].split("_"); String Part2 = Parts[1]; dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2); } else { dataSet.setValue(0, "Percent", header[j]); } } JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1, "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false); if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) { doc.newPage(); } PdfContentByte contentByte = docWriter.getDirectContent(); PdfTemplate template = contentByte.createTemplate(325, 250); PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250); Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250); chart.draw(graphics2d, rectangle2d); graphics2d.dispose(); contentByte.addTemplate(template, 0, 0); doc.newPage(); } } } catch (DocumentException dex) { dex.printStackTrace(); } catch (FileNotFoundException ex) { Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex); } finally { if (doc != null) { //close the document doc.close(); } if (docWriter != null) { //close the writer docWriter.close(); } } } // TODO add your handling code here: }