List of usage examples for com.lowagie.text Document setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
From source file:gov.utah.health.uper.reports.Registration.java
/** * Set up spacing on page/*from ww w . j ava 2 s . c o m*/ * @param document */ private void setUpPage(Document document) { document.setPageSize(PageSize.NOTE); //left, right, top, bottom document.setMargins(100, 100, 100, 100); document.open(); }
From source file:ilarkesto.integration.itext.PdfBuilder.java
License:Open Source License
public void write(OutputStream out) { Document document = new Document(); try {// ww w. java2s . c om PdfWriter.getInstance(document, out); } catch (DocumentException ex) { throw new RuntimeException(ex); } document.setMargins(mmToPoints(marginLeft), mmToPoints(marginRight), mmToPoints(marginTop), mmToPoints(marginBottom)); document.open(); for (ItextElement element : elements) { try { if (element instanceof PageBreak) { document.newPage(); } else { Element iTextElement = element.getITextElement(); if (iTextElement != null) document.add(iTextElement); } } catch (DocumentException ex) { throw new RuntimeException(ex); } } document.close(); }
From source file:jdbreport.model.io.pdf.itext2.PdfWriter.java
License:Apache License
private int saveSheet(Document document, int listCount, ReportModel model) throws DocumentException, IOException, SaveReportException { model.updatePages(0);// w w w . j a v a 2 s . c o m ReportPage pageFormat = model.getReportPage(); Paper paper = pageFormat.getPaper(); Rectangle pageSize = new Rectangle(Math.round((float) paper.getWidth()), Math.round((float) paper.getHeight())); if (pageFormat.getOrientation() == ReportPage.LANDSCAPE) { pageSize = pageSize.rotate(); } document.setPageSize(pageSize); document.setMargins(Math.round((float) pageFormat.getLeftMargin(Units.PT)), Math.round((float) pageFormat.getRightMargin(Units.PT)), Math.round((float) pageFormat.getTopMargin(Units.PT)), Math.round((float) pageFormat.getBottomMargin(Units.PT))); Rectangle viewPageSize = new Rectangle( document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(), document.getPageSize().getHeight() - document.topMargin() - document.bottomMargin()); if (listCount > 0) { document.newPage(); } listCount++; //float columnMargin = (float) Units.PT.setXPixels(model.getColumnModel().getColumnMargin()); ReportPrintable printable = new ReportPrintable(model); int pageCount = printable.calcCountPage(model.getReportPage()); Map<Integer, PageClip> clips = printable.getPageClips(); int leftCol; int topRow; int rightCol; int bottomRow; for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) { PageClip pageClip = clips.get(pageIndex); if (pageClip == null) break; leftCol = pageClip.getLeftCol(); rightCol = pageClip.getRightCol(); topRow = pageClip.getTopRow(); bottomRow = pageClip.getBottomRow(); int columnCount = rightCol - leftCol; float[] widths = new float[columnCount + 1]; widths[0] = 1; for (int c = 0; c < columnCount; c++) { ReportColumn column = (ReportColumn) model.getColumnModel().getColumn(leftCol + c); widths[c + 1] = (float) Math.round(column.getNativeWidth()); } PdfPTable table = createPdfTable(columnCount + 1, widths, viewPageSize); fillTable(model, leftCol, topRow, rightCol, bottomRow, table); document.add(table); if (pageIndex < clips.size()) { document.newPage(); } } return listCount; }
From source file:jm.nom.clas.Carnet.java
public void imprimir(HttpServletResponse response, ResultSet rsCarnets, String path) { response.setContentType("application/pdf"); response.setHeader("Pragma", "no-cache"); response.setHeader("Expires", "Mon, 01 Jan 2001 00:00:01 GMT"); response.setHeader("Cache-Control", "no-store"); response.setHeader("Cache-Control", "must-revalidate"); response.setHeader("Cache-Control", "no-cache"); /*try{// w w w . ja va2s .com rsCarnets = objEmpleado.getCarnets(id); if(rsCarnets.next()){ id_sucursal = ((rsCarnets.getString("id_sucursal")!=null) ? rsCarnets.getString("id_sucursal") : ""); id_instalacion = ((rsCarnets.getString("id_instalacion")!=null) ? rsCarnets.getString("id_instalacion") : ""); serie_factura = ((rsCarnets.getString("serie_factura")!=null) ? rsCarnets.getString("serie_factura") : ""); num_factura = ((rsCarnets.getString("num_factura")!=null) ? rsCarnets.getString("num_factura") : ""); razon_social = ((rsCarnets.getString("razon_social")!=null) ? rsCarnets.getString("razon_social") : "CONSUMIDOR FINAL"); fecha_emision = ((rsCarnets.getString("fecha_emision")!=null) ? Fecha.ISOaSQL(rsCarnets.getString("fecha_emision")) : ""); direccion = ((rsCarnets.getString("direccion")!=null) ? rsCarnets.getString("direccion") : ""); vendedor = ((rsCarnets.getString("vendedor")!=null) ? rsCarnets.getString("vendedor") : ""); total = ((rsCarnets.getString("total")!=null) ? rsCarnets.getString("total") : "0.00"); de_activo = ((rsCarnets.getString("de_activo")!=null) ? rsCarnets.getBoolean("de_activo") : false); rsCarnets.close(); } }catch(Exception ie){ ie.printStackTrace(); }*/ try { /* inicio PDF */ Document document = new Document(PageSize.A4.rotate());// paso 1 document.setMargins(-47, 0, 38, 0); /*Izquierda, derecha, tope, pie */ PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Carnet(this._dir)); document.open(); // paso 3 //writer.addJavaScript("this.print(false);", false); // Para enviar a la impresora automticamente. /* todo el cuerpo del doc es el paso 4 */ //PdfPTable tbl = new PdfPTable(new float[]{40f,60f}); PdfPTable tbl = new PdfPTable(4); int i = 0; try { //rsCarnets = objEmpleado.getCarnets(id); while (rsCarnets.next()) { PdfPTable tbl1 = new PdfPTable(1); PdfPTable tbl2 = new PdfPTable(new float[] { 90f, 5f, 5f }); String foto = ((rsCarnets.getString("padre_nombre") != null) ? rsCarnets.getString("padre_nombre") : ""); //_dir="C:\\Users\\SoulGael\\Documents\\NetBeansProjects\\trunk\\saitel\\build\\web\\img\\luis.jpg"; tbl1.addCell(Addons.setCeldaPDFBottom(" ", Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 0, 26, 0)); tbl1.addCell(Addons.setLogoCarnet(_dir + foto, 79, 103)); //tbl1.addCell(Addons.setLogoCarnet(_dir,79,103)); String nombre = ((rsCarnets.getString("nombre") != null) ? rsCarnets.getString("nombre") : ""); String apellidos = ((rsCarnets.getString("apellido") != null) ? rsCarnets.getString("apellido") : ""); String cargo = ((rsCarnets.getString("cargo") != null) ? rsCarnets.getString("cargo") : ""); ; String[] nombresArray = nombre.split(" "); String[] apellidosArray = apellidos.split(" "); String n_completos = nombresArray[0] + " " + apellidosArray[0]; String CI = ((rsCarnets.getString("dni") != null) ? rsCarnets.getString("dni") : ""); ; String sangre = ((rsCarnets.getString("tipo_sangre") != null) ? rsCarnets.getString("tipo_sangre") : ""); ; String carnet = ((rsCarnets.getString("carnet") != null) ? rsCarnets.getString("carnet") : ""); //String carnet="A,B,C,D,E,F,G"; Color A = Color.WHITE; Color B = Color.WHITE; Color C = Color.WHITE; Color D = Color.WHITE; Color E = Color.WHITE; Color F = Color.WHITE; Color G = Color.WHITE; String[] carnetArray = carnet.split(","); for (int j = 0; j < carnetArray.length; j++) { if (carnetArray[j].equals("A")) { A = Color.ORANGE; j++; if (j > carnetArray.length - 1) j = carnetArray.length - 1; } if (carnetArray[j].equals("B")) { B = Color.ORANGE; j++; if (j > carnetArray.length - 1) j = carnetArray.length - 1; } if (carnetArray[j].equals("C")) { C = Color.ORANGE; ; j++; if (j > carnetArray.length - 1) j = carnetArray.length - 1; } if (carnetArray[j].equals("D")) { D = Color.ORANGE; ; j++; if (j > carnetArray.length - 1) j = carnetArray.length - 1; } if (carnetArray[j].equals("E")) { E = Color.ORANGE; ; j++; if (j > carnetArray.length - 1) j = carnetArray.length - 1; } if (carnetArray[j].equals("F")) { F = Color.ORANGE; ; j++; if (j > carnetArray.length - 1) j = carnetArray.length - 1; } if (carnetArray[j].equals("G")) { G = Color.ORANGE; ; j++; if (j > carnetArray.length - 1) j = carnetArray.length - 1; } break; } tbl1.addCell(Addons.setCeldaPDFBottom(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 0)); tbl1.addCell(Addons.setCeldaPDFBottom(n_completos, Font.ITALIC, 13, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 0)); tbl1.addCell(Addons.setCeldaPDFBottom(cargo, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 0)); tbl1.addCell(Addons.setCeldaPDFBottom(CI, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 0)); tbl1.addCell(Addons.setCeldaPDFBottom(sangre, Font.ITALIC, 12, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 0)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 7, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3)); tbl2.addCell(Addons.setCeldaPDFCarnet(" LICENCIA INTERNA DE ", Font.ITALIC, 9, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3)); tbl2.addCell(Addons.setCeldaPDFCarnet(" PREVENCION DE RIESGOS", Font.ITALIC, 9, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3)); tbl2.addCell(Addons.setCeldaPDFCarnet(" Con la induccin recibida y aprobada usted", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3)); tbl2.addCell(Addons.setCeldaPDFCarnet(" est autorizado para:", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3)); tbl2.addCell(Addons.setCeldaPDFCarnet(" a. Trabajo de Oficina.", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 1, 2, 0, A)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" b. Trabajo de Marketing y propaganda", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 1, 2, 0, B)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" c. Trabajo de mantenimiento y limpieza", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 1, 2, 0, C)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" d. Trabajo de instalaciones menores a los ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 2)); tbl2.addCell(Addons.setCeldaPDFCarnet(" ocho metros sobre el nivel.", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0)); tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 1, 0, 0, D)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" (Domicilios, postes, cableado)", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0, 2, 2)); tbl2.addCell(Addons.setCeldaPDFCarnet(" e. Trabajo de instalaciones, antenas,", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 2)); tbl2.addCell(Addons.setCeldaPDFCarnet(" infraestructura mayores a los ocho", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 0)); tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 1, 0, 0, E)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" metros sobre el nivel", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0, 2, 2)); tbl2.addCell(Addons.setCeldaPDFCarnet(" f. Planes de emergencia y contingencia", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 1, 2, 0, F)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnet(" g. Planes de rescate", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell(Addons.setCeldaPDFCarnetOpciones(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 1, 2, 0, G)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 2, 0)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3)); tbl2.addCell( Addons.setCeldaPDFCarnet(" ", Font.ITALIC, 10, Font.BOLD, Element.ALIGN_LEFT, 0, 0, 3)); tbl2.addCell(Addons.setCeldaPDFCarnet("Ing. FREDDY ROSERO", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE)); tbl2.addCell(Addons.setCeldaPDFCarnet("GERENTE", Font.ITALIC, 8, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE)); tbl2.addCell(Addons.setCeldaPDFCarnet("Fecha de Expedicin: Mayo 2015", Font.ITALIC, 5, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE)); tbl2.addCell(Addons.setCeldaPDFCarnet("Fecha de Caducidad: Mayo 2016", Font.ITALIC, 5, Font.BOLD, Element.ALIGN_CENTER, 0, 0, 3, Color.BLUE)); /* tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("nombres")!=null) ? rsCarnets.getString("nombres") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1)); tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("rol")!=null) ? rsCarnets.getString("rol") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1)); tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("dni")!=null) ? rsCarnets.getString("dni") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1)); tbl1.addCell(Addons.setCeldaPDF(((rsCarnets.getString("tipo_sangre")!=null) ? rsCarnets.getString("tipo_sangre") : ""), Font.HELVETICA, 10, Font.NORMAL, Element.ALIGN_LEFT, 1)); String idcarnet=(rsCarnets.getString("id_empleado")!=null) ? rsCarnets.getString("id_empleado") : "";*/ tbl.addCell(Addons.setCeldaPDF(tbl1, 0, 0)); tbl.addCell(Addons.setCeldaPDF(tbl2, 0, 0)); if (i % 2 != 0) { tbl1.addCell( Addons.setCeldaPDF(" ", Font.ITALIC, 10, Font.BOLD, Element.ALIGN_LEFT, 0, 16, 3)); } i++; } if (i % 2 != 0) { tbl.addCell(" "); tbl.addCell(" "); } /*Archivo archivo = new Archivo(_ip, _puerto, _db, _usuario, _clave); //path = path.substring(0, path.lastIndexOf("/")); String carnet = path + "/img/" + archivo.getArchivo(_dir, "vta_empleado", idcarnet, "padre_nombre", "foto"); archivo.cerrar(); Image imagen = null; try{ imagen = Image.getInstance(carnet); imagen.scaleAbsolute(50, 70); PdfPCell celdaImg = new PdfPCell(imagen); celdaImg.setBorderWidth(0); celdaImg.setPadding(0); tbl.addCell(celdaImg); document.add(tbl1); }catch(Exception e){ tbl.addCell(" "); }*/ } catch (Exception e) { e.printStackTrace(); } document.add(tbl); document.close(); // paso 5 /* fin PDF */ } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:jm.Reporte.java
License:GNU General Public License
public void lista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros) { /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {//from w ww . j a va2s . c om PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); ResultSetMetaData mdata = registros.getMetaData(); int numCols = mdata.getColumnCount(); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; try { while (registros.next()) { tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 1; i <= numCols; i++) { tbl_det.addCell( Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); } num++; } registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void lista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros, int lim) { /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {/* w w w . j a v a 2s . com*/ PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; int alineacion = Element.ALIGN_LEFT; try { while (registros.next()) { tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 1; i <= lim; i++) { //alineacion = (i==lim) ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT; tbl_det.addCell( Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, alineacion, 1)); } num++; } registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void lista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros, char sumDesde) { int sumarDesde = Integer.parseInt("" + sumDesde); int num_sumas = cabTabla.length - sumarDesde; float sumas[] = new float[num_sumas]; float valor = 0; int pos = 0;/*from w ww . ja v a2s. com*/ /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try { PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); ResultSetMetaData mdata = registros.getMetaData(); int numCols = mdata.getColumnCount(); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; try { while (registros.next()) { tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); pos = 0; for (int i = 1; i <= numCols; i++) { if (i < sumarDesde) { tbl_det.addCell(Addons.setCeldaPDF( ((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); } else { valor = (registros.getString(i) != null) ? registros.getFloat(i) : 0; tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 1)); sumas[pos] = Float.parseFloat(this.formatoNumero.format(sumas[pos])) + valor; pos++; } } num++; } tbl_det.addCell(Addons.setCeldaPDF("TOTALES: ", Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0, 4, sumarDesde)); for (int j = 0; j < sumas.length; j++) { tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(sumas[j]), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0)); } registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void sumLista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros) { /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {/*ww w . j a va2 s. co m*/ PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); ResultSetMetaData mdata = registros.getMetaData(); int numCols = mdata.getColumnCount(); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; //int num2 = 1; float suma_total = 0; float consumo = 0; int alineacion = Element.ALIGN_LEFT; try { while (registros.next()) { tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); //tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 1; i <= numCols; i++) { alineacion = (i == numCols) ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT; tbl_det.addCell( Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, alineacion, 1)); } consumo = (registros.getString(numCols) != null) ? registros.getFloat(numCols) : 0; suma_total = Float.parseFloat(this.formatoNumero.format(suma_total)) + consumo; num++; //num2++; } tbl_det.addCell(Addons.setCeldaPDF("TOTAL: " + Addons.truncar(suma_total), Font.TIMES_ROMAN, 10, Font.NORMAL, Element.ALIGN_RIGHT, 0, 5, numCols + 2)); registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void listaAgrupada(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros) {// w ww .ja v a 2 s . c o m /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try { PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); ResultSetMetaData mdata = registros.getMetaData(); int numCols = mdata.getColumnCount(); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; int num2 = 1; String aux = ""; String columna1 = ""; try { while (registros.next()) { columna1 = (registros.getString(1) != null) ? registros.getString(1) : ""; if (aux.compareTo(columna1) != 0) { tbl_det.addCell(Addons.setCeldaPDF(columna1, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1, 3, numCols + 1)); aux = columna1; num2 = 1; } tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 2; i <= numCols; i++) { tbl_det.addCell( Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); } num++; num2++; } registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }
From source file:jm.Reporte.java
License:GNU General Public License
public void activosCustorios(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros, DataBase objDB) { /* inicio PDF */ Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate(); Document document = new Document(orientacion);// paso 1 document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */ try {//w ww . j a va2s .c o m PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2 writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal, this.rep_pie)); document.open(); // paso 3 /* todo el cuerpo del doc es el paso 4 */ document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion, this.sucursal)); document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla)); ResultSetMetaData mdata = registros.getMetaData(); int numCols = mdata.getColumnCount(); PdfPTable tbl_det = new PdfPTable(anchoTabla); int num = 1; int num2 = 1; String aux = ""; String columna1 = ""; String persona_recibe = ""; String fecha = ""; String id_activo = ""; try { while (registros.next()) { columna1 = (registros.getString(1) != null) ? registros.getString(1) : ""; if (aux.compareTo(columna1) != 0) { tbl_det.addCell(Addons.setCeldaPDF(columna1, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1, 3, numCols + 2)); aux = columna1; num2 = 1; } tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1)); for (int i = 2; i < numCols; i++) { tbl_det.addCell( Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); } id_activo = (registros.getString("id_activo") != null) ? registros.getString("id_activo") : ""; try { ResultSet rsCustodio = objDB.consulta( "select persona_recibe, toDateSQL(max(fecha)) as fecha from tbl_activo_custodio as AC inner join tbl_activo_personalizacion as AP " + "on AC.id_activo_personalizacion=AP.id_activo_personalizacion where AC.eliminado=false and AC.id_activo=" + id_activo + " group by persona_recibe,AP.id_activo_personalizacion order by AP.id_activo_personalizacion desc"); if (rsCustodio.next()) { persona_recibe = (rsCustodio.getString("persona_recibe") != null) ? rsCustodio.getString("persona_recibe") : ""; fecha = (rsCustodio.getString("fecha") != null) ? rsCustodio.getString("fecha") : ""; rsCustodio.close(); } } catch (Exception ex) { ex.printStackTrace(); } tbl_det.addCell(Addons.setCeldaPDF(persona_recibe, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); tbl_det.addCell( Addons.setCeldaPDF(fecha, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1)); num++; num2++; } registros.close(); } catch (Exception e) { e.printStackTrace(); } document.add(tbl_det); } catch (IllegalStateException ie) { ie.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } document.close(); // paso 5 /* fin PDF */ }