List of usage examples for com.itextpdf.text.pdf PdfPCell setVerticalAlignment
public void setVerticalAlignment(int verticalAlignment)
From source file:beans.ManagedBeanReportes.java
public PdfPTable traerSubtabla(Tienda t) throws DocumentException { PdfPTable tabla_PesajeDetalle = new PdfPTable(4); tabla_PesajeDetalle.setWidthPercentage(100); tabla_PesajeDetalle.setTotalWidth(450f); tabla_PesajeDetalle.setLockedWidth(true); tabla_PesajeDetalle.setWidths(anchocol03); tabla_PesajeDetalle.getDefaultCell(); PdfPCell Cell_Headers = new PdfPCell(new Paragraph("PRODUCTO", titulopequeFont)); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); tabla_PesajeDetalle.addCell(Cell_Headers); Cell_Headers = new PdfPCell(new Paragraph("UBICACIONES", titulopequeFont)); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); tabla_PesajeDetalle.addCell(Cell_Headers); Cell_Headers = new PdfPCell(new Paragraph("MINIMO", titulopequeFont)); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); tabla_PesajeDetalle.addCell(Cell_Headers); Cell_Headers = new PdfPCell(new Paragraph("STOCK TOTAL", titulopequeFont)); Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY); Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER); tabla_PesajeDetalle.addCell(Cell_Headers); for (StockProductoTiendaOrigen det : stockProductoTiendaOrigenFacade.lista_stock_tienda(t)) { tabla_PesajeDetalle.addCell(traerCelda(det.getProducto().getNombreProducto())); String ubicaciones_ = ""; for (DetalleAlmacenProductos p : detalleAlmacenProductosFacade.lista_para_stock_tienda(t, det.getProducto())) {//from w w w . j a v a 2s . c o m if (p.getUbicacionFisica().getIdUbicacionFisica() > 1) { ubicaciones_ = p.getUbicacionFisica().getNombreUbicacionFisica() + ";" + ubicaciones_; } } tabla_PesajeDetalle.addCell(traerCelda(ubicaciones_)); tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidadMinimaStock()))); tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidad()))); } return tabla_PesajeDetalle; }
From source file:beans.ManagedBeanReportes.java
public PdfPCell traerCelda(String data) { PdfPCell resultado = new PdfPCell(new Paragraph(data, titulopequeFont)); resultado.setHorizontalAlignment(Paragraph.ALIGN_CENTER); resultado.setVerticalAlignment(Paragraph.ALIGN_MIDDLE); return resultado; }
From source file:bouttime.report.award.AwardReport.java
License:Open Source License
/** * Generate an award report.// ww w . ja v a 2 s . c om * @param dao Dao object to use to retrieve data. * @param session Session to generate the report for. * @param group Group to generate report for. This takes precedence, so * if not null, then the report will be generated for this group. * @return True if the report was generated. */ private static boolean doReport(Dao dao, String session, Group group) { if (!dao.isOpen()) { return false; } // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header Paragraph p1 = new Paragraph(new Paragraph( String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()), FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); Paragraph p2 = new Paragraph( new Paragraph("Award Report", FontFactory.getFont(FontFactory.HELVETICA, 14))); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); PdfPCell headerCell = new PdfPCell(); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setPadding(3); headerCell.setBorderWidth(2); List<Group> groups; if (group != null) { groups = new ArrayList<Group>(); groups.add(group); } else if (session != null) { groups = dao.getGroupsBySession(session); } else { groups = dao.getAllGroups(); } for (Group g : groups) { // create and add the table PdfPTable datatable = new PdfPTable(4); int colWidths[] = { 30, 30, 30, 10 }; // percentage datatable.setWidths(colWidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // The header has the group name headerCell.setPhrase(new Phrase(g.toString(), headerFont)); headerCell.setColspan(4); datatable.addCell(headerCell); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); List<Wrestler> wList = getSortedAwardList(g); int i = 0; for (Wrestler w : wList) { if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(w.getFirstName(), detailFont)); datatable.addCell(new Phrase(w.getLastName(), detailFont)); datatable.addCell(new Phrase(w.getTeamName(), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); Integer place = w.getPlace(); String placeStr = (place == null) ? "" : place.toString(); datatable.addCell(new Phrase(placeStr, detailFont)); } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); document.add(datatable); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.boutsequence.BoutSequenceReport.java
License:Open Source License
private static PdfPTable addBoutSequences(List<Wrestler> wList, String session) throws DocumentException { // create and add the table Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); PdfPCell headerCell = new PdfPCell(); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setPadding(3);/*from w w w. j a v a2 s . co m*/ headerCell.setBorderWidth(2); PdfPTable datatable = new PdfPTable(3); int colWidths[] = { 5, 25, 70 }; // percentage datatable.setWidths(colWidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); headerCell.setPhrase(new Phrase("Mat", headerFont)); datatable.addCell(headerCell); headerCell.setPhrase(new Phrase("Name", headerFont)); datatable.addCell(headerCell); headerCell.setPhrase(new Phrase("Bout Sequence", headerFont)); datatable.addCell(headerCell); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); Collections.sort(wList, new WrestlerMatNameSort()); int i = 0; for (Wrestler w : wList) { if (w.getGroup() == null) { logger.debug(String.format("Wrestler [%s] is not in a group, skipping.", w.getShortName())); continue; } if ((session != null) && !session.equalsIgnoreCase(w.getGroup().getSession())) { logger.debug(String.format("Wrestler [%s] is in a group but not in session %s, skipping.", w.getShortName(), session)); continue; } if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } List<Bout> bList = BoutSequence.calculate(w); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(new Phrase(w.getGroup().getMat(), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(String.format("%s %s", w.getFirstName(), w.getLastName()), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); String boutSequenceString = getBoutSequenceString(bList); datatable.addCell(new Phrase(boutSequenceString, detailFont)); } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); return (i > 0 ? datatable : null); }
From source file:bouttime.report.team.TeamReport.java
License:Open Source License
/** * Generate a detail report of the teams in the tournament. * This report includes the teams and all of the wrestlers on the team. * @param dao Dao object to use to retrieve data. * @return True if the report was generated. */// w w w. jav a 2 s . c om public static boolean doDetail(Dao dao) { if (!dao.isOpen()) { return false; } // step 1: creation of a document-object Document document = new Document(); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter.getInstance(document, fos); // step 3: we open the document document.open(); // step 4: create and add content // create and add the header Paragraph p1 = new Paragraph(new Paragraph( String.format("%s %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()), FontFactory.getFont(FontFactory.HELVETICA, 10))); document.add(p1); Paragraph p2 = new Paragraph( new Paragraph("Team Detail Report", FontFactory.getFont(FontFactory.HELVETICA, 14))); p2.setAlignment(Paragraph.ALIGN_CENTER); document.add(p2); Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10); PdfPCell headerCell = new PdfPCell(); headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); headerCell.setPadding(3); headerCell.setBorderWidth(2); List<String> teams = dao.getTeams(); for (String t : teams) { List<Wrestler> wrestlers = dao.getWrestlersByTeam(t); int count = wrestlers.size(); // create and add the table PdfPTable datatable = new PdfPTable(5); int colWidths[] = { 30, 30, 20, 10, 10 }; // percentage datatable.setWidths(colWidths); datatable.setWidthPercentage(100); datatable.getDefaultCell().setPadding(3); datatable.getDefaultCell().setBorderWidth(2); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); // The header has the team name and the number of entries headerCell.setPhrase(new Phrase(t, headerFont)); headerCell.setColspan(3); datatable.addCell(headerCell); headerCell.setPhrase(new Phrase(String.format("Entries : %d", count), headerFont)); headerCell.setColspan(2); datatable.addCell(headerCell); datatable.setHeaderRows(1); // this is the end of the table header datatable.getDefaultCell().setBorderWidth(1); datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); int i = 0; for (Wrestler w : wrestlers) { if ((i++ % 2) == 0) { datatable.getDefaultCell().setGrayFill(0.9f); } else { datatable.getDefaultCell().setGrayFill(1); } datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); datatable.addCell(new Phrase(w.getFirstName(), detailFont)); datatable.addCell(new Phrase(w.getLastName(), detailFont)); datatable.addCell(new Phrase(w.getClassification(), detailFont)); datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); datatable.addCell(new Phrase(w.getAgeDivision(), detailFont)); datatable.addCell(new Phrase(w.getWeightClass(), detailFont)); } datatable.setSpacingBefore(5f); datatable.setSpacingAfter(15f); document.add(datatable); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } // step 5: we close the document document.close(); return true; }
From source file:cimav.restrh.services.JustificacionREST.java
private Response tablaMercado(Integer id_param) { Justificacion justif = (Justificacion) JustificacionREST.this.find(id_param); StreamingOutput streamingOutput = new StreamingOutput() { public void write(OutputStream outputStream) throws IOException, WebApplicationException { try { //Create Document instance. Document document = new Document(); PdfWriter.getInstance(document, outputStream); document.addAuthor("Generador adquisiciones | " + justif.getEmpleado().getCuentaCimav()); String fileName1 = (justif.getRequisicion() + "-" + justif.getEmpleado().getCuentaCimav()) .replace(" ", "").replace(",", ""); document.addTitle("Justificacin: " + fileName1); document.addSubject("Justificacin de Requisicin"); document.open();//from w ww. ja va2s . co m //Titulo del documento Paragraph parrafo = new Paragraph("Centro de Investigacin en Materiales Avanzados S. C.", new Font(Font.FontFamily.TIMES_ROMAN, 17, Font.BOLD)); parrafo.setAlignment(Element.ALIGN_CENTER); parrafo.setSpacingAfter(20); document.add(parrafo); PdfPTable table = new PdfPTable(3); // 3 columns. table.setWidths(new int[] { 30, 50, 100 }); PdfPCell cell0 = new PdfPCell( new Paragraph("Fecha:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); PdfPCell cell1 = new PdfPCell(new Paragraph( justif.getFechaInicio().getDayOfMonth() + " de " + justif.getFechaInicio().getMonth().getDisplayName(TextStyle.FULL, new Locale("es", "ES")) + " de " + justif.getFechaInicio().getYear(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); PdfPCell cell2 = new PdfPCell( new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); cell0 = new PdfPCell(new Paragraph("No. de Requisicin:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell1 = new PdfPCell(new Paragraph(justif.getRequisicion(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); cell0 = new PdfPCell(new Paragraph("Procedimiento:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell1 = new PdfPCell(new Paragraph("Adjudicacin Directa", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); cell0 = new PdfPCell(new Paragraph("Origen de los bienes:", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell1 = new PdfPCell(new Paragraph(justif.esNacional(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell2 = new PdfPCell(new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); document.add(table); parrafo = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)); parrafo.setSpacingAfter(20); parrafo.setIndentationLeft(30); parrafo.setLeading(15); parrafo.setSpacingBefore(20); parrafo.setAlignment(Element.ALIGN_JUSTIFIED); document.add(parrafo); table = new PdfPTable(5);// 5 columns. table.setWidthPercentage(90); //table size % table.setWidths(new int[] { 'a', 'a', 'a', 'a', 'a' }); cell0 = new PdfPCell( new Paragraph("PARTIDA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); cell1 = new PdfPCell( new Paragraph("DESCIPCIMAV", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); cell2 = new PdfPCell( new Paragraph("PROVEEDOR No. 1", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); PdfPCell cell3 = new PdfPCell( new Paragraph("PROVEEDOR No.2", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); PdfPCell cell4 = new PdfPCell( new Paragraph("PROVEEDOR No.3", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell2.setBorder(PdfPCell.BOX); cell3.setBorder(PdfPCell.BOX); cell4.setBorder(PdfPCell.BOX); cell0.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell0); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); cell0 = new PdfPCell( new Paragraph("Partida #1", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); cell1 = new PdfPCell(new Paragraph(justif.getDescripcion(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell0.setBorder(PdfPCell.BOX); cell1.setBorder(PdfPCell.BOX); cell0.setHorizontalAlignment(Element.ALIGN_CENTER); cell0.setVerticalAlignment(Element.ALIGN_MIDDLE); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); cell0.setRowspan(2); cell1.setRowspan(2); table.addCell(cell0); table.addCell(cell1); cell2 = new PdfPCell(new Paragraph(justif.getProveedorUno(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(justif.getProveedorDos(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(justif.getProveedorTres(), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell2.setBorder(PdfPCell.BOX); cell3.setBorder(PdfPCell.BOX); cell4.setBorder(PdfPCell.BOX); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); if (justif.getMontoUno() <= 1 && justif.getMontoDos() <= 1 && justif.getMontoTres() <= 1) { cell2 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoUno() <= 1 && justif.getMontoDos() <= 1) { cell2 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoUno() <= 1 && justif.getMontoTres() <= 1) { cell2 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoDos() <= 1 && justif.getMontoTres() <= 1) { cell2 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoUno(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoUno() <= 1) { cell2 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoDos() <= 1) { cell2 = new PdfPCell(new Paragraph( "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n" + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else if (justif.getMontoTres() <= 1) { cell2 = new PdfPCell(new Paragraph( "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n" + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell( new Paragraph("NO APLICA", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } else { cell2 = new PdfPCell(new Paragraph( "Subtotal: " + justif.getSubTotal() + "\n" + "IVA: " + justif.getIva() + "\n" + "Total:" + "\n" + montoFormatComas(justif.getImporte(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell3 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoDos(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); cell4 = new PdfPCell(new Paragraph(montoFormatComas(justif.getMontoTres(), justif), new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.NORMAL))); } cell2.setBorder(PdfPCell.BOX); cell3.setBorder(PdfPCell.BOX); cell4.setBorder(PdfPCell.BOX); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); cell4.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); document.add(table); parrafo = new Paragraph( "Tal como lo establece el artculo 29 " + "del Reglamento de la Ley de Adquisiciones, " + "Arrendamientos y Servicios del Sector Pblico," + " la investigacin de mercado arrojo los siguientes resultados:\n", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)); parrafo.setSpacingAfter(20); parrafo.setIndentationLeft(30); parrafo.setLeading(15); parrafo.setSpacingBefore(10); parrafo.setAlignment(Element.ALIGN_JUSTIFIED); document.add(parrafo); parrafo = new Paragraph( "Fraccin I, determinamos la existencia de oferta de los bienes requeridos.\n" + "Fraccin II, verificamos existencias de los mismos con los proveedores que nos proporcionaron cotizacin formal.\n" + "Fraccin III, conocimos los precios que prevalecan en el mercado nacional.\n", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)); parrafo.setIndentationLeft(50); parrafo.setLeading(15); parrafo.setAlignment(Element.ALIGN_JUSTIFIED); document.add(parrafo); parrafo = new Paragraph( "A travs de la investigacin de mercado realizada, " + "concluimos que la mejor opcin de compra es la oferta del proveedor" + " " + justif.getProveedorUno(), new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL)); parrafo.setSpacingAfter(10); parrafo.setIndentationLeft(30); parrafo.setLeading(15); parrafo.setSpacingBefore(20); parrafo.setAlignment(Element.ALIGN_JUSTIFIED); document.add(parrafo); document.close(); outputStream.close(); } catch (DocumentException ex) { Logger.getLogger(JustificacionREST.class.getName()).log(Level.SEVERE, null, ex); } } }; ResponseBuilder response = Response.ok(streamingOutput); String fileName = ("inline; filename=" + justif.getRequisicion() + "-" + justif.getEmpleado().getCuentaCimav() + ".pdf").replace(" ", "").replace(",", "-"); response.header("Content-Disposition", fileName); return response.build(); }
From source file:clases.Funciones.java
public boolean GenerateReporte_Service(JTable t_client, JTable t_vehiculos, int open, String S_solicitad, String S_realizado, JTable t_productos, String Total, String Prioridad, JComboBox client, JComboBox vehiculos, Double km) { boolean r = false; int Folio = GenerateFolioService(); if (AddService(client, vehiculos, S_solicitad, S_realizado, t_productos, Double.parseDouble(Total), "URGENTE".equals(Prioridad)) && vehiculos.getSelectedIndex() > 0) { UpdateKilometraje((String) ListVehiculos.get(vehiculos.getSelectedIndex()), km); Table_LoadClient(t_client, client); Table_LoadCar(t_vehiculos, vehiculos); Document documento = new Document(PageSize.LETTER, 10, 10, 10, 10); FileOutputStream ficheroPdf; File ruta = null;//from w w w . ja va 2s.c om com.itextpdf.text.Image imagen = null; try { imagen = com.itextpdf.text.Image.getInstance(p.ReturnPropiedad(p.Ruta_logo)); char rt = p.ReturnPropiedad(p.Ruta_SaveReports) .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1); if ("/".equalsIgnoreCase(String.valueOf(rt))) { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } else { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + "/" + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } ficheroPdf = new FileOutputStream(ruta); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); } catch (DocumentException | IOException ex) { Alert("Verifique las rutas de guardado de reportes y logo."); } try { documento.open(); imagen.setAlignment(Element.ALIGN_CENTER); imagen.scaleToFit(200, 100); String membrete = "REPORTE DE SERVICIO NO: " + Folio + "\n\n"; membrete += ReturnDatosFisicos(this.Datos_Nombre) + "\n"; membrete += "DIRECCION: " + ReturnDatosFisicos(this.Datos_Direccion) + "\n"; membrete += "RFC: " + ReturnDatosFisicos(this.Datos_Rfc) + "\n"; membrete += "TELEFONO: " + ReturnDatosFisicos(this.Datos_Telefono) + "\n"; membrete += "GENERO DOCUMENTO: " + ReturnNombreUsuario() + "\n"; membrete += "GENERADO: " + GetFechaAndHourActual() + "\n"; PdfPTable HeaderDatos = new PdfPTable(2); HeaderDatos.setWidthPercentage(100); documento.add(new Paragraph("\n")); PdfPCell cell = new PdfPCell(new Phrase(membrete)); cell.setBorder(0); HeaderDatos.addCell(cell); cell = new PdfPCell(imagen); cell.setBorder(0); cell.setHorizontalAlignment(1); cell.setVerticalAlignment(1); HeaderDatos.addCell(cell); documento.add(HeaderDatos); documento.add(new Paragraph("\n")); ///////// //Tabla_Clientes String Client_header = "CLIENTE"; Paragraph Title = new Paragraph(Client_header.toUpperCase()); Title.setAlignment(1); documento.add(Title); documento.add(new Paragraph(" ")); PdfPTable tabla = new PdfPTable(t_client.getColumnCount()); tabla.setWidthPercentage(100); for (int i = 0; i < t_client.getColumnCount(); i++) { Paragraph header = new Paragraph(t_client.getColumnName(i)); header.setAlignment(1); tabla.addCell(header); } for (int i = 0; i < t_client.getRowCount(); i++) { for (int a = 0; a < t_client.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_client.getValueAt(i, a))); campo.setAlignment(1); tabla.addCell(campo); } } documento.add(tabla); documento.add(new Paragraph(" ")); //Tabla_Vehiculos String Vehiculos_header = "VEHICULO"; Paragraph Title1 = new Paragraph(Vehiculos_header.toUpperCase()); Title1.setAlignment(1); documento.add(Title1); documento.add(new Paragraph(" ")); PdfPTable tabla_vehiculos = new PdfPTable(t_vehiculos.getColumnCount()); tabla_vehiculos.setWidthPercentage(100); for (int i = 0; i < t_vehiculos.getColumnCount(); i++) { Paragraph header = new Paragraph(t_vehiculos.getColumnName(i)); header.setAlignment(1); tabla_vehiculos.addCell(header); } for (int i = 0; i < t_vehiculos.getRowCount(); i++) { for (int a = 0; a < t_vehiculos.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_vehiculos.getValueAt(i, a))); campo.setAlignment(1); tabla_vehiculos.addCell(campo); } } documento.add(tabla_vehiculos); documento.add(new Paragraph("SERVICIO SOLICITADO: " + S_solicitad.toUpperCase())); documento.add(new Paragraph("SERVICIO REALIZADO: " + S_realizado.toUpperCase())); documento.add(new Paragraph("PRIORIDAD: " + Prioridad)); //Tabla de servicios y productos String Service_header = "\nSERVICIOS Y PRODUCTOS UTILIZADOS"; Paragraph Title2 = new Paragraph(Service_header.toUpperCase()); Title2.setAlignment(1); documento.add(Title2); documento.add(new Paragraph(" ")); PdfPTable tabla_PRODUCTS = new PdfPTable(t_productos.getColumnCount()); tabla_PRODUCTS.setWidthPercentage(100); for (int i = 0; i < t_productos.getColumnCount(); i++) { Paragraph header = new Paragraph(t_productos.getColumnName(i)); header.setAlignment(1); tabla_PRODUCTS.addCell(header); } for (int i = 0; i < t_productos.getRowCount(); i++) { for (int a = 0; a < t_productos.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_productos.getValueAt(i, a))); campo.setAlignment(1); tabla_PRODUCTS.addCell(campo); } } documento.add(tabla_PRODUCTS); documento.add(new Paragraph("")); // documento.add(new Paragraph("COSTO TOTAL DE SERVICIO $ " + Total)); documento.add(new Paragraph( "FECHA Y HORA DE ENTREGA: ____________________________________________________")); documento.add(new Paragraph( "NOMBRE Y FIRMA DEL QUE REALIZA: _____________________________________________")); documento.add(new Paragraph( "CONFORMIDAD, NOMBRE Y FIRMA DE QUIEN RECIBE: _______________________________")); documento.add(new Paragraph( "PROXIMO SERVICIO: ___________________________________________________________")); Paragraph footer = new Paragraph("SOFTWARE Y MAS ! - WWW.CYBERCHOAPAS.COM"); footer.setAlignment(1); documento.add(footer); documento.close(); r = true; if (open > 0) { Desktop.getDesktop().open(ruta); } } catch (IOException | DocumentException ex) { Alert(ex.getMessage()); } } else { Alert("VERIFIQUE SU INFORMACION"); } return r; }
From source file:clases.Funciones.java
public void ReGenerateReporte_Service(JTable t) { int id = 0, id_cliente = 0; double total = 0; String id_vehiculo = "", s_solicitado = "", s_realizado = "", productos = ""; boolean p_urgente = false; try {/*from w w w .ja v a 2s. c o m*/ coneccion = new Conexion(); try (ResultSet rs = coneccion.Consulta( "SELECT id, id_cliente, id_vehiculo, s_solicitado, s_realizado, productos, total, p_urgente FROM services where id = " + Integer.parseInt((String) t.getValueAt(t.getSelectedRow(), 0)) + " ")) { if (rs.next()) { id = rs.getInt(1); id_cliente = rs.getInt(2); id_vehiculo = rs.getString(3); s_solicitado = rs.getString(4); s_realizado = rs.getString(5); productos = rs.getString(6); total = rs.getDouble(7); p_urgente = rs.getBoolean(8); } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException ex) { Alert(ex.getMessage()); } int Folio = id; JTable t_client = new JTable(); JTable t_vehiculos = new JTable(); Table_LoadClient(t_client, id_cliente); Table_LoadCar(t_vehiculos, id_vehiculo); Document documento = new Document(PageSize.LETTER, 10, 10, 10, 10); FileOutputStream ficheroPdf; File ruta = null; com.itextpdf.text.Image imagen = null; try { imagen = com.itextpdf.text.Image.getInstance(p.ReturnPropiedad(p.Ruta_logo)); char rt = p.ReturnPropiedad(p.Ruta_SaveReports) .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1); if ("/".equalsIgnoreCase(String.valueOf(rt))) { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } else { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + "/" + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } ficheroPdf = new FileOutputStream(ruta); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); } catch (DocumentException | IOException ex) { Alert("Verifique las rutas de guardado de reportes y logo."); } try { documento.open(); imagen.setAlignment(Element.ALIGN_CENTER); imagen.scaleToFit(200, 100); String membrete = "REPORTE DE SERVICIO NO: " + Folio + "\n\n"; membrete += ReturnDatosFisicos(this.Datos_Nombre) + "\n"; membrete += "DIRECCION: " + ReturnDatosFisicos(this.Datos_Direccion) + "\n"; membrete += "RFC: " + ReturnDatosFisicos(this.Datos_Rfc) + "\n"; membrete += "TELEFONO: " + ReturnDatosFisicos(this.Datos_Telefono) + "\n"; membrete += "GENERO DOCUMENTO: " + ReturnNombreUsuario() + "\n"; membrete += "GENERADO: " + GetFechaAndHourActual() + "\n"; PdfPTable HeaderDatos = new PdfPTable(2); HeaderDatos.setWidthPercentage(100); documento.add(new Paragraph("\n")); PdfPCell cell = new PdfPCell(new Phrase(membrete)); cell.setBorder(0); HeaderDatos.addCell(cell); cell = new PdfPCell(imagen); cell.setBorder(0); cell.setHorizontalAlignment(1); cell.setVerticalAlignment(1); HeaderDatos.addCell(cell); documento.add(HeaderDatos); documento.add(new Paragraph("\n")); ///////// //Tabla_Clientes String Client_header = "CLIENTE"; Paragraph Title = new Paragraph(Client_header.toUpperCase()); Title.setAlignment(1); documento.add(Title); documento.add(new Paragraph(" ")); PdfPTable tabla = new PdfPTable(t_client.getColumnCount()); tabla.setWidthPercentage(100); for (int i = 0; i < t_client.getColumnCount(); i++) { Paragraph header = new Paragraph(t_client.getColumnName(i)); header.setAlignment(1); tabla.addCell(header); } for (int i = 0; i < t_client.getRowCount(); i++) { for (int a = 0; a < t_client.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_client.getValueAt(i, a))); campo.setAlignment(1); tabla.addCell(campo); } } documento.add(tabla); documento.add(new Paragraph(" ")); //Tabla_Vehiculos String Vehiculos_header = "VEHICULO"; Paragraph Title1 = new Paragraph(Vehiculos_header.toUpperCase()); Title1.setAlignment(1); documento.add(Title1); documento.add(new Paragraph(" ")); PdfPTable tabla_vehiculos = new PdfPTable(t_vehiculos.getColumnCount()); tabla_vehiculos.setWidthPercentage(100); for (int i = 0; i < t_vehiculos.getColumnCount(); i++) { Paragraph header = new Paragraph(t_vehiculos.getColumnName(i)); header.setAlignment(1); tabla_vehiculos.addCell(header); } for (int i = 0; i < t_vehiculos.getRowCount(); i++) { for (int a = 0; a < t_vehiculos.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_vehiculos.getValueAt(i, a))); campo.setAlignment(1); tabla_vehiculos.addCell(campo); } } documento.add(tabla_vehiculos); documento.add(new Paragraph("SERVICIO SOLICITADO: " + s_solicitado.toUpperCase())); documento.add(new Paragraph("SERVICIO REALIZADO: " + s_realizado.toUpperCase())); String var = ""; if (p_urgente) { var = "URGENTE"; } else { var = "PROGRAMAR"; } documento.add(new Paragraph("PRIORIDAD: " + var)); //Tabla de servicios y productos String Service_header = "\nSERVICIOS Y PRODUCTOS UTILIZADOS"; Paragraph Title2 = new Paragraph(Service_header.toUpperCase()); Title2.setAlignment(1); documento.add(Title2); documento.add(new Paragraph(" ")); JTable t_productos = new JTable(); Table_LoadProductsServicio(t_productos); String[] result = productos.replace("+", ",").split(","); if (result.length >= 1) { for (String r : result) { if (!r.equalsIgnoreCase("") || !r.isEmpty()) { if (ExistProduct(r)) { Table_AddProductsServicio(t_productos, r); } } } } PdfPTable tabla_PRODUCTS = new PdfPTable(t_productos.getColumnCount()); tabla_PRODUCTS.setWidthPercentage(100); for (int i = 0; i < t_productos.getColumnCount(); i++) { Paragraph header = new Paragraph(t_productos.getColumnName(i)); header.setAlignment(1); tabla_PRODUCTS.addCell(header); } for (int i = 0; i < t_productos.getRowCount(); i++) { for (int a = 0; a < t_productos.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_productos.getValueAt(i, a))); campo.setAlignment(1); tabla_PRODUCTS.addCell(campo); } } documento.add(tabla_PRODUCTS); documento.add(new Paragraph("")); // documento.add(new Paragraph("COSTO TOTAL DE SERVICIO $ " + total)); documento.add( new Paragraph("FECHA Y HORA DE ENTREGA: ____________________________________________________")); documento.add( new Paragraph("NOMBRE Y FIRMA DEL QUE REALIZA: _____________________________________________")); documento.add( new Paragraph("CONFORMIDAD, NOMBRE Y FIRMA DE QUIEN RECIBE: _______________________________")); documento.add( new Paragraph("PROXIMO SERVICIO: ___________________________________________________________")); Paragraph footer = new Paragraph("SOFTWARE Y MAS ! - WWW.CYBERCHOAPAS.COM"); footer.setAlignment(1); documento.add(footer); documento.close(); Desktop.getDesktop().open(ruta); } catch (IOException | DocumentException ex) { Alert(ex.getMessage()); } catch (ClassNotFoundException | SQLException | InstantiationException | IllegalAccessException ex) { Alert(ex.getMessage()); } }
From source file:clases.Funciones.java
public void ReGenerateReporte_Service(int id_service) { int id = 0, id_cliente = 0; double total = 0; String id_vehiculo = "", s_solicitado = "", s_realizado = "", productos = ""; boolean p_urgente = false; try {//from w w w. ja va 2 s .com coneccion = new Conexion(); try (ResultSet rs = coneccion.Consulta( "SELECT id, id_cliente, id_vehiculo, s_solicitado, s_realizado, productos, total, p_urgente FROM services where id = " + id_service + " ")) { if (rs.next()) { id = rs.getInt(1); id_cliente = rs.getInt(2); id_vehiculo = rs.getString(3); s_solicitado = rs.getString(4); s_realizado = rs.getString(5); productos = rs.getString(6); total = rs.getDouble(7); p_urgente = rs.getBoolean(8); } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException ex) { Alert(ex.getMessage()); } int Folio = id; JTable t_client = new JTable(); JTable t_vehiculos = new JTable(); Table_LoadClient(t_client, id_cliente); Table_LoadCar(t_vehiculos, id_vehiculo); Document documento = new Document(PageSize.LETTER, 10, 10, 10, 10); FileOutputStream ficheroPdf; File ruta = null; com.itextpdf.text.Image imagen = null; try { imagen = com.itextpdf.text.Image.getInstance(p.ReturnPropiedad(p.Ruta_logo)); char rt = p.ReturnPropiedad(p.Ruta_SaveReports) .charAt(p.ReturnPropiedad(p.Ruta_SaveReports).length() - 1); if ("/".equalsIgnoreCase(String.valueOf(rt))) { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } else { ruta = new File(p.ReturnPropiedad(p.Ruta_SaveReports) + "/" + ReturnNombreUsuario().replace(" ", "_") + "_" + GetFechaAndHourActual().replace(" ", "_").replace(":", "_").replace("-", "_") + ".pdf"); } ficheroPdf = new FileOutputStream(ruta); PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20); } catch (DocumentException | IOException ex) { Alert("Verifique las rutas de guardado de reportes y logo."); } try { documento.open(); imagen.setAlignment(Element.ALIGN_CENTER); imagen.scaleToFit(200, 100); String membrete = "REPORTE DE SERVICIO NO: " + Folio + "\n\n"; membrete += ReturnDatosFisicos(this.Datos_Nombre) + "\n"; membrete += "DIRECCION: " + ReturnDatosFisicos(this.Datos_Direccion) + "\n"; membrete += "RFC: " + ReturnDatosFisicos(this.Datos_Rfc) + "\n"; membrete += "TELEFONO: " + ReturnDatosFisicos(this.Datos_Telefono) + "\n"; membrete += "GENERO DOCUMENTO: " + ReturnNombreUsuario() + "\n"; membrete += "GENERADO: " + GetFechaAndHourActual() + "\n"; PdfPTable HeaderDatos = new PdfPTable(2); HeaderDatos.setWidthPercentage(100); documento.add(new Paragraph("\n")); PdfPCell cell = new PdfPCell(new Phrase(membrete)); cell.setBorder(0); HeaderDatos.addCell(cell); cell = new PdfPCell(imagen); cell.setBorder(0); cell.setHorizontalAlignment(1); cell.setVerticalAlignment(1); HeaderDatos.addCell(cell); documento.add(HeaderDatos); documento.add(new Paragraph("\n")); ///////// //Tabla_Clientes String Client_header = "CLIENTE"; Paragraph Title = new Paragraph(Client_header.toUpperCase()); Title.setAlignment(1); documento.add(Title); documento.add(new Paragraph(" ")); PdfPTable tabla = new PdfPTable(t_client.getColumnCount()); tabla.setWidthPercentage(100); for (int i = 0; i < t_client.getColumnCount(); i++) { Paragraph header = new Paragraph(t_client.getColumnName(i)); header.setAlignment(1); tabla.addCell(header); } for (int i = 0; i < t_client.getRowCount(); i++) { for (int a = 0; a < t_client.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_client.getValueAt(i, a))); campo.setAlignment(1); tabla.addCell(campo); } } documento.add(tabla); documento.add(new Paragraph(" ")); //Tabla_Vehiculos String Vehiculos_header = "VEHICULO"; Paragraph Title1 = new Paragraph(Vehiculos_header.toUpperCase()); Title1.setAlignment(1); documento.add(Title1); documento.add(new Paragraph(" ")); PdfPTable tabla_vehiculos = new PdfPTable(t_vehiculos.getColumnCount()); tabla_vehiculos.setWidthPercentage(100); for (int i = 0; i < t_vehiculos.getColumnCount(); i++) { Paragraph header = new Paragraph(t_vehiculos.getColumnName(i)); header.setAlignment(1); tabla_vehiculos.addCell(header); } for (int i = 0; i < t_vehiculos.getRowCount(); i++) { for (int a = 0; a < t_vehiculos.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_vehiculos.getValueAt(i, a))); campo.setAlignment(1); tabla_vehiculos.addCell(campo); } } documento.add(tabla_vehiculos); documento.add(new Paragraph("SERVICIO SOLICITADO: " + s_solicitado.toUpperCase())); documento.add(new Paragraph("SERVICIO REALIZADO: " + s_realizado.toUpperCase())); String var = ""; if (p_urgente) { var = "URGENTE"; } else { var = "PROGRAMAR"; } documento.add(new Paragraph("PRIORIDAD: " + var)); //Tabla de servicios y productos String Service_header = "\nSERVICIOS Y PRODUCTOS UTILIZADOS"; Paragraph Title2 = new Paragraph(Service_header.toUpperCase()); Title2.setAlignment(1); documento.add(Title2); documento.add(new Paragraph(" ")); JTable t_productos = new JTable(); Table_LoadProductsServicio(t_productos); String[] result = productos.replace("+", ",").split(","); if (result.length >= 1) { for (String r : result) { if (!r.equalsIgnoreCase("") || !r.isEmpty()) { if (ExistProduct(r)) { Table_AddProductsServicio(t_productos, r); } } } } PdfPTable tabla_PRODUCTS = new PdfPTable(t_productos.getColumnCount()); tabla_PRODUCTS.setWidthPercentage(100); for (int i = 0; i < t_productos.getColumnCount(); i++) { Paragraph header = new Paragraph(t_productos.getColumnName(i)); header.setAlignment(1); tabla_PRODUCTS.addCell(header); } for (int i = 0; i < t_productos.getRowCount(); i++) { for (int a = 0; a < t_productos.getColumnCount(); a++) { Paragraph campo = new Paragraph(String.valueOf(t_productos.getValueAt(i, a))); campo.setAlignment(1); tabla_PRODUCTS.addCell(campo); } } documento.add(tabla_PRODUCTS); documento.add(new Paragraph("")); // documento.add(new Paragraph("COSTO TOTAL DE SERVICIO $ " + total)); documento.add( new Paragraph("FECHA Y HORA DE ENTREGA: ____________________________________________________")); documento.add( new Paragraph("NOMBRE Y FIRMA DEL QUE REALIZA: _____________________________________________")); documento.add( new Paragraph("CONFORMIDAD, NOMBRE Y FIRMA DE QUIEN RECIBE: _______________________________")); documento.add( new Paragraph("PROXIMO SERVICIO: ___________________________________________________________")); Paragraph footer = new Paragraph("SOFTWARE Y MAS ! - WWW.CYBERCHOAPAS.COM"); footer.setAlignment(1); documento.add(footer); documento.close(); Desktop.getDesktop().open(ruta); } catch (IOException | DocumentException ex) { Alert(ex.getMessage()); } catch (ClassNotFoundException | SQLException | InstantiationException | IllegalAccessException ex) { Alert(ex.getMessage()); } }
From source file:climbingcompranking.model.ranking.RankingGenerator.java
License:Open Source License
public void createRankingPDF(String competitionName, CompetitionType compType) { doTheRanking(compType);/*from ww w .j a v a 2s. co m*/ try { Document document = new Document(PageSize.A4.rotate()); // Landscape Date date = new Date(); String dateStr = ""; if (Locale.getDefault().equals(Locale.FRANCE)) { dateStr = new SimpleDateFormat("dd-MM-yyyy").format(date); } else { dateStr = new SimpleDateFormat("yyyy-MM-dd").format(date); } PdfWriter.getInstance(document, new FileOutputStream("data/pdf/" + competitionName + '-' + dateStr + ".pdf")); document.open(); // Meta data document.addTitle(competitionName); document.addSubject(competitionName + " ranking."); document.addKeywords(competitionName + ", ranking, climbingcompetition, climbcompranking"); document.addAuthor("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking"); document.addCreator("ClimbingCompRanking - https://github.com/Yaty/ClimbingCompRanking"); document.addCreationDate(); document.setMargins(0, 0, 0, 0); PdfPCell club = new PdfPCell(new Phrase(I18n.MODEL.getString("Club"))); PdfPCell climberName = new PdfPCell(new Phrase(I18n.MODEL.getString("ClimberName"))); PdfPCell ranking = new PdfPCell(new Phrase(I18n.MODEL.getString("Ranking"))); for (Map.Entry<Category, ArrayList<Climber>> climbersCategory : climbersMap.entrySet()) { if (climbersCategory.getValue().isEmpty()) continue; document.newPage(); // Title Paragraph title = new Paragraph( competitionName + " : " + climbersCategory.getKey().getCategoryName()); title.setAlignment(Element.ALIGN_CENTER); title.setFont(new Font(Font.FontFamily.HELVETICA, 36)); title.setSpacingAfter(20); // Table PdfPTable table = null; switch (compType) { case BOULDERING: case LEAD: case SPEED: table = new PdfPTable(3); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case LEAD_AND_BOULDERING: table = new PdfPTable(6); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank())))); table.addCell( new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case SPEED_AND_BOULDERING: table = new PdfPTable(6); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank())))); table.addCell( new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case SPEED_AND_LEAD: table = new PdfPTable(6); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank())))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; case COMBINED: table = new PdfPTable(7); // Club | Full name | Ranking table.addCell(club); table.addCell(climberName); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("LeadRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("BoulderingRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("SpeedRanking")))); table.addCell(new PdfPCell(new Phrase(I18n.MODEL.getString("Sum")))); table.addCell(ranking); for (Climber climber : climbersCategory.getValue()) { table.addCell(new PdfPCell(new Phrase(climber.getClubName()))); table.addCell(new PdfPCell(new Phrase(climber.getFullName()))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getLeadRank())))); table.addCell( new PdfPCell(new Phrase(String.valueOf(climber.getRank().getBoulderingRank())))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getSpeedRank())))); table.addCell(new PdfPCell( new Phrase(String.valueOf(climber.getRank().getTotalPoints(compType))))); table.addCell(new PdfPCell(new Phrase(String.valueOf(climber.getRank().getOverallRank())))); } break; } // Alignment for (PdfPRow row : table.getRows()) { PdfPCell[] cells = row.getCells(); for (PdfPCell cellToAlign : cells) { cellToAlign.setHorizontalAlignment(Element.ALIGN_CENTER); cellToAlign.setVerticalAlignment(Element.ALIGN_CENTER); } } table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setHeaderRows(1); document.add(title); document.add(table); } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(RankingGenerator.class.getName()).log(Level.SEVERE, null, ex); } }