List of usage examples for com.itextpdf.text Paragraph add
@Override public boolean add(Element o)
Element
to the Paragraph
. From source file:containers.Report.java
public void generateOrderByPayment(String type, ArrayList<String> entry, String from, String to) { try {/*from www .jav a 2s. c o m*/ String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\PayTypeReport.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); body3 = String.format("%5s - %5s - %5s\n", "Order No.", "Order Total", "Order Date"); double counter = 0; for (int i = 0; i < entry.size(); i += 3) { body3 += String.format("%-10s %8s %25s\n", entry.get(i), entry.get(i + 1), entry.get(i + 2).substring(0, 19)); counter += Double.parseDouble(entry.get(i + 1)); } body3 += "\n\nTotal for all orders: $" + counter; from = from.substring(0, 10); to = to.substring(0, 10); p.add(new Date().toString()); p.add("\n\nOrder by Payment Report\n"); p.add("Payment Type: " + type + "\n"); p.add("Reporting Date: \n" + from + " - " + to + "\n\n"); p.add(body3); document.add(p); document.close(); file.close(); body3 = ""; } catch (Exception e) { e.printStackTrace(); } }
From source file:containers.Report.java
public void generateOrderItem(String ordernum, ArrayList<String> entry) { try {//from ww w. j a va 2 s .c om String path = System.getProperty("user.home") + File.separator + "Documents"; OutputStream file = new FileOutputStream(new File(path + "\\OrderReport.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); Paragraph p = new Paragraph("", FontFactory.getFont(FontFactory.COURIER)); Image img = Image.getInstance(new URL(link)); img.scalePercent(56f); p.add(img); body4 = String.format("%5s %27s %10s\n", "Item Name", "Base Price", "Log Total"); double counter = 0; for (int i = 0; i < entry.size(); i += 3) { body4 += String.format("%-10s %15s %12s\n", entry.get(i), entry.get(i + 1), entry.get(i + 2)); counter += Double.parseDouble(entry.get(i + 2)); } body4 += "\n\nTotal for all orders: $" + counter; p.add(new Date().toString()); p.add("\n\nItems on Order Report\n"); p.add("Order Number: " + ordernum + "\n\n"); p.add(body4); document.add(p); document.close(); file.close(); body4 = ""; } catch (Exception e) { e.printStackTrace(); } }
From source file:control.ModificaPrestamo.java
public boolean generapdf(String path) throws DocumentException, FileNotFoundException { boolean estado = false; Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(path)); document.open();/*w w w. j ava 2 s .c o m*/ Image img = null; try { img = Image.getInstance("src/img/imgen.jpg"); img.scaleAbsolute(80f, 50f); img.setAbsolutePosition(470f, 750f); document.add(img); } catch (BadElementException ex) { Logger.getLogger(nuevoReporte.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(nuevoReporte.class.getName()).log(Level.SEVERE, null, ex); } Paragraph paragraph1 = new Paragraph("Solicitante: " + Solicitante.getText()); Paragraph paragraph2 = new Paragraph("Proyecto: " + Proyecto.getText()); Paragraph paragraph3 = new Paragraph( "Fecha y hora del prestamo: " + fecha.getText() + " " + hora.getText()); Paragraph paragraph4 = new Paragraph("Fecha de entrega: " + fecha1.getText()); document.add(paragraph1); document.add(paragraph2); document.add(paragraph3); document.add(paragraph4); Paragraph tmp = new Paragraph(""); tmp.setSpacingBefore(10); document.add(tmp); PdfPTable table = new PdfPTable(4); table.addCell("Id Equipo"); table.addCell("Equipo"); table.addCell("Accesorios"); table.addCell("Descripcion"); Object[][] tabla = this.getTableData(tabReporte); for (Object[] o : tabla) for (Object e : o) { table.addCell((String) e); } document.add(table); System.out.println(clausula1.getText() + " " + clausula2.getText()); Paragraph paragraph5 = new Paragraph("Clausula 1: " + clausula1.getText()); Paragraph paragraph6 = new Paragraph("Clausula 2: " + clausula2.getText()); document.add(paragraph5); document.add(paragraph6); tmp = new Paragraph(""); tmp.setSpacingBefore(10); document.add(tmp); Paragraph p = new Paragraph("Firma del solicitante: "); p.add(new Chunk(new DottedLineSeparator())); p.add(" Firma del prestador: "); p.add(new Chunk(new DottedLineSeparator())); document.add(p); //PdfPTable firma = new PdfPTable(1); //firma.addCell("Firma"); //document.add(new Paragraph("")); //document.add(firma); document.close(); return true; }
From source file:Control.PdfBiglietto.java
/** * Funzione che costruisce il file PDF// w w w.jav a2 s . c o m * @param nomeFile Nome del file PDF * @param stream Stream sul quale verr scritto il pdf * @throws DocumentException * @throws BadElementException * @throws IOException */ public void costruisciPdf(String nomeFile, OutputStream stream) throws DocumentException, BadElementException, IOException { SimpleDateFormat dataNormale = new SimpleDateFormat("dd/MM/YYYY"); Document biglietto = new Document(); //PdfWriter.getInstance(biglietto, new FileOutputStream(nomeFile)); PdfWriter.getInstance(biglietto, stream); biglietto.open(); biglietto.addAuthor(autore); biglietto.addCreationDate(); biglietto.addCreator(autore); biglietto.addTitle(titolo); //dati inseriti nel QRCode int contatorePrenotazioni = 1; //usato per avere due prenotazioni per ogni pagina for (Prenotazione p : prenotazioni) { contatorePrenotazioni++; StringBuilder sb = new StringBuilder(); sb.append(p.getId()); sb.append("|"); sb.append(p.getUtente().getNome()); sb.append("|"); sb.append(p.getPrezzo()); sb.append("|"); sb.append(p.getSala().getId()); sb.append("|"); sb.append(p.getPosto().getRiga()); sb.append("|"); sb.append(p.getPosto().getColonna()); sb.append("|"); sb.append(p.getSpettacolo().getFilm().getTitolo()); sb.append("|"); sb.append(dataNormale.format(p.getSpettacolo().getData_ora().getTime())); Paragraph completo = new Paragraph(); completo.setSpacingAfter(80.0f); //in caso di problemi al QRcode (dimensioni eccessive, aspetti strani, etc), controllare la stringa in ingresso. QRCode qrBiglietto = new QRCode(sb.toString()); Paragraph titolo = new Paragraph(p.getSpettacolo().getFilm().getTitolo()); titolo.add("\nPrenotazione a nome dell'utente: " + p.getUtente().getNome()); titolo.add(" Id Spettacolo: " + Integer.toString(p.getSpettacolo().getId())); Paragraph info = new Paragraph(); info.add("Lo spettacolo si terr il giorno: "); info.add(dataNormale.format(p.getSpettacolo().getData_ora().getTime())); info.add("\nID Prenotazione: " + Integer.toString(p.getId())); Paragraph sala = new Paragraph(); sala.add("Sala: " + p.getSala().getNome()); sala.add(" Il tuo posto nella riga: " + p.getPosto().getRiga() + " e colonna: " + p.getPosto().getColonna()); Paragraph prezzo = new Paragraph("Pagamento:" + Double.toString(p.getPrezzo())); prezzo.add(" Euro"); Paragraph fondo = new Paragraph("Biglietto emesso in data: " + dataNormale.format(new Date())); fondo.add("\n Mostra questo qrCode all'addetto del cinema: "); Image qrCode = Image.getInstance(qrBiglietto.getQrcode().toByteArray()); qrCode.setAlignment(Image.TOP); if (contatorePrenotazioni % 2 == 0) biglietto.newPage(); completo.add(titolo); completo.add(info); completo.add(sala); completo.add(prezzo); completo.add(fondo); completo.add(qrCode); biglietto.add(completo); } biglietto.close(); }
From source file:ControleurClients.ControleurClients.java
private void pageCommandes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, DocumentException { request.setAttribute("attente", commandef.getAttente(clientConnect)); request.setAttribute("cours", commandef.getCours(clientConnect)); request.setAttribute("effectuee", commandef.getEffectuee(clientConnect)); List<Commande> attente = commandef.getAttente(); List<Commande> cours = commandef.getCours(); List<Commande> effectue = commandef.getEffectuee(); if (!attente.isEmpty()) { for (Commande c : attente) { Document document1 = new Document(); PdfWriter.getInstance(document1, new FileOutputStream("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/attente" + c.getId().toString() + ".pdf")); document1.open();// w w w . j av a2 s . c o m Paragraph text = new Paragraph(); text.add(new Paragraph("Grenoble Dvd", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("Facture", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("En attente : Commande n" + c.getId().toString(), new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); document1.add(text); Paragraph p = new Paragraph(c.getDate(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)); p.setAlignment(Element.ALIGN_RIGHT); p.add(new Paragraph(" ")); p.add(new Paragraph(" ")); document1.add(p); Paragraph text1 = new Paragraph(); text1.add(new Paragraph( "Mr " + c.getClient().getNom().substring(0, 1).toUpperCase() + c.getClient().getNom().substring(1) + " " + c.getClient().getPrenom().substring(0, 1).toUpperCase() + c.getClient().getPrenom().substring(1), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph("Email: " + c.getClient().getEmail(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); document1.add(text1); PdfPTable table = new PdfPTable(3); //On crer l'objet cellule. PdfPCell cell; cell = new PdfPCell(new Phrase("Facture")); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("Nom du Dvd")); cell.setRowspan(1); table.addCell(cell); //contenu du tableau. table.addCell("Quantit"); table.addCell("Prix"); for (Entry<Dvd, Integer> entry : c.getDvds().entrySet()) { Dvd dvd = (Dvd) entry.getKey(); Object value = entry.getValue(); //Image dvdimage = Image.getInstance(dvd.getImage()); //On crer un objet table dans lequel on intialise a taille. cell = new PdfPCell(new Phrase(dvd.getTitre())); cell.setRowspan(1); table.addCell(cell); table.addCell(String.valueOf(value)); table.addCell(String.valueOf(dvd.getPrix())); } cell = new PdfPCell(new Phrase("Total: " + String.valueOf(c.getMontant()) + " ")); cell.setColspan(3); table.addCell(cell); document1.add(table); Paragraph p1 = new Paragraph(); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" Grenoble Dvd: 12 avenue des ensimag 38000 Grenoble", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); p1.setAlignment(Element.ALIGN_RIGHT); document1.add(p1); document1.close(); } } if (!cours.isEmpty()) { for (Commande c : cours) { Document document1 = new Document(); PdfWriter.getInstance(document1, new FileOutputStream("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/cours" + c.getId().toString() + ".pdf")); document1.open(); Paragraph text = new Paragraph(); text.add(new Paragraph("Grenoble Dvd", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("Facture", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("En cours : Commande n" + c.getId().toString(), new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); document1.add(text); Paragraph p = new Paragraph(c.getDate(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)); p.setAlignment(Element.ALIGN_RIGHT); p.add(new Paragraph(" ")); p.add(new Paragraph(" ")); document1.add(p); Paragraph text1 = new Paragraph(); text1.add(new Paragraph( "Mr " + c.getClient().getNom().substring(0, 1).toUpperCase() + c.getClient().getNom().substring(1) + " " + c.getClient().getPrenom().substring(0, 1).toUpperCase() + c.getClient().getPrenom().substring(1), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph("Email: " + c.getClient().getEmail(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); document1.add(text1); PdfPTable table = new PdfPTable(3); //On crer l'objet cellule. PdfPCell cell; cell = new PdfPCell(new Phrase("Facture")); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("Nom du Dvd")); cell.setRowspan(1); table.addCell(cell); //contenu du tableau. table.addCell("Quantit"); table.addCell("Prix"); for (Entry<Dvd, Integer> entry : c.getDvds().entrySet()) { Dvd dvd = (Dvd) entry.getKey(); Object value = entry.getValue(); //Image dvdimage = Image.getInstance(dvd.getImage()); //On crer un objet table dans lequel on intialise a taille. cell = new PdfPCell(new Phrase(dvd.getTitre())); cell.setRowspan(1); table.addCell(cell); table.addCell(String.valueOf(value)); table.addCell(String.valueOf(dvd.getPrix())); } cell = new PdfPCell(new Phrase("Total : " + String.valueOf(c.getMontant()) + " ")); cell.setColspan(3); table.addCell(cell); document1.add(table); Paragraph p1 = new Paragraph(); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" Grenoble Dvd: 12 avenue des ensimag 38000 Grenoble", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); p1.setAlignment(Element.ALIGN_RIGHT); document1.add(p1); document1.close(); } } if (!effectue.isEmpty()) { for (Commande c : effectue) { new File("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/attente" + c.getId().toString() + ".pdf").delete(); new File("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/cours" + c.getId().toString() + ".pdf").delete(); Document document1 = new Document(); PdfWriter.getInstance(document1, new FileOutputStream("/home/aymeric/Commerce/Commerce/Commerce-war/web/pdf/effectue" + c.getId().toString() + ".pdf")); document1.open(); Paragraph text = new Paragraph(); text.add(new Paragraph("Grenoble Dvd", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("Facture", new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); text.add(new Paragraph("Effectue : Commande n" + c.getId().toString(), new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD))); text.add(new Paragraph(" ")); text.add(new Paragraph(" ")); document1.add(text); Paragraph p = new Paragraph(c.getDate(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC)); p.setAlignment(Element.ALIGN_RIGHT); p.add(new Paragraph(" ")); p.add(new Paragraph(" ")); document1.add(p); Paragraph text1 = new Paragraph(); text1.add(new Paragraph( "Mr " + c.getClient().getNom().substring(0, 1).toUpperCase() + c.getClient().getNom().substring(1) + " " + c.getClient().getPrenom().substring(0, 1).toUpperCase() + c.getClient().getPrenom().substring(1), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph("Email: " + c.getClient().getEmail(), new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); text1.add(new Paragraph(" ")); document1.add(text1); PdfPTable table = new PdfPTable(3); //On crer l'objet cellule. PdfPCell cell; cell = new PdfPCell(new Phrase("Facture")); cell.setColspan(3); table.addCell(cell); cell = new PdfPCell(new Phrase("Nom du Dvd")); cell.setRowspan(1); table.addCell(cell); //contenu du tableau. table.addCell("Quantit"); table.addCell("Prix"); for (Entry<Dvd, Integer> entry : c.getDvds().entrySet()) { Dvd dvd = (Dvd) entry.getKey(); Object value = entry.getValue(); //Image dvdimage = Image.getInstance(dvd.getImage()); //On crer un objet table dans lequel on intialise a taille. cell = new PdfPCell(new Phrase(dvd.getTitre())); cell.setRowspan(1); table.addCell(cell); table.addCell(String.valueOf(value)); table.addCell(String.valueOf(dvd.getPrix())); } cell = new PdfPCell(new Phrase("Total : " + String.valueOf(c.getMontant()) + " ")); cell.setColspan(3); table.addCell(cell); document1.add(table); Paragraph p1 = new Paragraph(); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" ")); p1.add(new Paragraph(" Grenoble Dvd: 12 avenue des ensimag 38000 Grenoble", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.ITALIC))); p1.setAlignment(Element.ALIGN_RIGHT); document1.add(p1); document1.close(); } } getServletContext().getRequestDispatcher("/WEB-INF/Commande.jsp").forward(request, response); }
From source file:Controller.ControllerCompra.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . jav a 2 s . com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); if (request.getParameter("action") != null) { //int estado = 0; String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); String action = request.getParameter("action"); switch (action) { case "Registrar": { String documentoUsuario = (request.getParameter("documentoUsuario")); String facturaProveedor = (request.getParameter("txtNumeroFactura")); String nombreProveedor = (request.getParameter("txtNombre")); int lenght = Integer.parseInt(request.getParameter("size")); int totalCompra = Integer.parseInt(request.getParameter("txtTotalCompra")); listObjDetalleMovimientos = new ArrayList<>(); for (int i = 0; i < lenght; i++) { _objDetalleMovimiento = new ObjDetalleMovimiento(); _objDetalleMovimiento .setIdArticulo(Integer.parseInt(request.getParameter("lista[" + i + "][idArticulo]"))); _objDetalleMovimiento .setCantidad(Integer.parseInt(request.getParameter("lista[" + i + "][cantidad]"))); _objDetalleMovimiento.setPrecioArticulo( Integer.parseInt(request.getParameter("lista[" + i + "][precioArticulo]"))); _objDetalleMovimiento.setTotalDetalleMovimiento( _objDetalleMovimiento.getCantidad() * _objDetalleMovimiento.getPrecioArticulo()); _objDetalleMovimiento.setDescuento(lenght); listObjDetalleMovimientos.add(_objDetalleMovimiento); } _objUsuario.setDocumentoUsuario(documentoUsuario); _objCompra.setFacturaProveedor(facturaProveedor); _objCompra.setNombreProveedor(nombreProveedor); _objCompra.setTotalCompra(totalCompra); daoModelCompra = new ModelCompra(); String salida = Mensaje(daoModelCompra.Add(_objCompra, _objUsuario, listObjDetalleMovimientos), "La compra ha sido registrada", "Ha ocurrido un error"); daoModelCompra.Signout(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(salida); break; } case "Consultar": { int id = Integer.parseInt(request.getParameter("id")); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(consultarDetalle(id)); break; } case "Enlistar": { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(getTableCompra()); break; } //<editor-fold defaultstate="collapsed" desc="PDF mediante iText"> case "Imprimir": { response.setContentType("application/pdf"); try { Locale loc = Locale.getDefault(); NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(loc); //Primero obtengo el id del Movimiento int id = Integer.parseInt(request.getParameter("id")); //Obtengo el reporte a manera de Map Map material = reporte(id); //Topo ese reporte y lo divido, primero en la compra y luego el detalle Map<String, String> compra = (Map) material.get("Compra"); List<Map> detalle = (List) material.get("Detalle"); //Creo el documento y obtengo el canal de comunicacion con el servidor, para luego enviar el documento. Document document = new Document(); OutputStream os = response.getOutputStream(); //Creo una instancia a partir del documento y del canal PdfWriter.getInstance(document, os); //Abro el documento document.open(); Image logo = Image.getInstance(url + "/public/images/logo.png"); logo.scaleAbsolute(new Rectangle(logo.getPlainWidth() / 4, logo.getPlainHeight() / 4)); document.add(logo); //Creo una fuente para la letra en negrilla final Font helveticaBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); //Escribo y agrego un primer parrafo con los datos basicos de la compra Paragraph headerDerecha = new Paragraph(); headerDerecha.add(new Chunk("Nombre del Proveedor: ", helveticaBold)); headerDerecha.add(new Chunk(compra.get("nombreProveedor") + "\n")); headerDerecha.add(new Chunk("Factura del Proveedor: ", helveticaBold)); headerDerecha.add(new Chunk(compra.get("facturaProveedor") + "\n")); headerDerecha.add(new Chunk("Fecha Compra: ", helveticaBold)); headerDerecha.add(new Chunk(compra.get("fechaCompra") + "\n")); //Escribo y agrego un segundo parrafo con los datos basicos de Stelarte Paragraph headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Stelarte.Decoracion \n", helveticaBold)); headerIzquierda.add(new Chunk("Direccin: ", helveticaBold)); headerIzquierda.add(new Chunk("Calle Falsa 123 # 12a34\n")); headerIzquierda.add(new Chunk("Telfono: ", helveticaBold)); headerIzquierda.add(new Chunk("2583697 \n")); //Agrego los dos anteriores parrafos al Header PdfPTable header = new PdfPTable(2); header.getDefaultCell().setBorder(0); header.addCell(headerIzquierda); header.addCell(headerDerecha); header.setWidthPercentage(100f); header.setSpacingAfter(20); document.add(header); //Creo la tabla del detalle PdfPTable tablaDetalle = new PdfPTable(new float[] { 1, 3, 2, 2 }); tablaDetalle.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); //Creo el titulo, le quito el borde, le digo que ocupara cuatro columnas y que ser centrado PdfPCell tituloCell = new PdfPCell(new Phrase("Detalle de Compra", helveticaBold)); tituloCell.setBorder(0); tituloCell.setColspan(4); tituloCell.setHorizontalAlignment(Element.ALIGN_CENTER); tablaDetalle.addCell(tituloCell); //Aqui creo cada cabecera tablaDetalle.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); tablaDetalle.addCell(new Phrase("ID", helveticaBold)); tablaDetalle.addCell(new Phrase("Nombre", helveticaBold)); tablaDetalle.addCell(new Phrase("Cantidad", helveticaBold)); tablaDetalle.addCell(new Phrase("Valor", helveticaBold)); tablaDetalle.getDefaultCell().setBackgroundColor(null); //Aqui agrego la tabla cada articulo. for (Map<String, String> next : detalle) { tablaDetalle.addCell(next.get("idArticulo")); tablaDetalle.addCell(next.get("descripcionArticulo")); tablaDetalle.addCell(next.get("cantidad")); tablaDetalle .addCell(currencyFormatter.format(Integer.parseInt(next.get("precioArticulo")))); } //Creo el Footer headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Total: ", helveticaBold)); headerIzquierda .add(new Chunk(currencyFormatter.format(Integer.parseInt(compra.get("totalCompra"))))); PdfPCell footerCell = new PdfPCell(headerIzquierda); footerCell.setBorder(0); footerCell.setColspan(4); footerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tablaDetalle.addCell(footerCell); //Establesco el tamao y posicion de la tabla, luego la agrego al documento tablaDetalle.setWidthPercentage(100f); tablaDetalle.setHorizontalAlignment(Element.ALIGN_RIGHT); document.add(tablaDetalle); //Cierro el documento y lo envio con flush. document.close(); response.setHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\""); os.flush(); os.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } break; } //</editor-fold> //<editor-fold defaultstate="collapsed" desc="PDF mediante iReports"> case "Imprimir2": { try { int id = Integer.parseInt(request.getParameter("id")); String source = url + "/reports/newReport1.jrxml"; JasperPrint jasperPrint = null; JasperReport jasperReport = null; JasperDesign jasperDesign = null; System.out.println(source); String reportPath = request.getServletContext().getRealPath("reports") + "\\newReport1.jrxml"; jasperDesign = JRXmlLoader.load(reportPath); jasperReport = JasperCompileManager.compileReport(jasperDesign); jasperPrint = JasperFillManager.fillReport(jasperReport, reporte(id), daoModelCompra.getConnection()); JasperExportManager.exportReportToPdfStream(jasperPrint, response.getOutputStream()); } catch (Exception ex) { for (StackTraceElement ruta : ex.getStackTrace()) { System.err.println(ruta); } } } break; //</editor-fold> } } }
From source file:Controller.ControllerVenta.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* www . java 2s .c om*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); if (request.getParameter("action") != null) { String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); String action = request.getParameter("action"); switch (action) { case "Registrar": { String documentoUsuario = (request.getParameter("documentoUsuario")); String documentoCliente = null; String nombreCliente = null; int numeroVenta = 0; if (Validador.validarDocumento(request.getParameter("documentoCliente")) & Validador.validarNombresCompletos(request.getParameter("txtNombreCliente")) & Validador.validarNumero(request.getParameter("txtNumeroVenta"))) { documentoCliente = (request.getParameter("documentoCliente")); nombreCliente = (request.getParameter("txtNombreCliente")); numeroVenta = Integer.parseInt(request.getParameter("txtNumeroVenta")); } else { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(Mensaje(false, null, "Ha ingresado datos incorrectos")); break; } int lenght = Integer.parseInt(request.getParameter("size")); int totalCompra = Integer.parseInt(request.getParameter("txtTotalVenta")); listOjbDetalleMovimientos = new ArrayList<>(); for (int i = 0; i < lenght; i++) { _objDetalleMovimiento = new ObjDetalleMovimiento(); _objDetalleMovimiento .setIdArticulo(Integer.parseInt(request.getParameter("lista[" + i + "][idArticulo]"))); _objDetalleMovimiento .setCantidad(Integer.parseInt(request.getParameter("lista[" + i + "][cantidad]"))); _objDetalleMovimiento.setPrecioArticulo( Integer.parseInt(request.getParameter("lista[" + i + "][precioArticulo]"))); _objDetalleMovimiento.setTotalDetalleMovimiento( _objDetalleMovimiento.getCantidad() * _objDetalleMovimiento.getPrecioArticulo()); _objDetalleMovimiento.setDescuento(lenght); listOjbDetalleMovimientos.add(_objDetalleMovimiento); } _objUsuario.setDocumentoUsuario(documentoUsuario); _objVenta.setIdVenta(numeroVenta); _objVenta.setDocumentoCliente(documentoCliente); _objVenta.setNombreCliente(nombreCliente); _objVenta.setTotalVenta(totalCompra); daoModelVenta = new ModelVenta(); String salida = Mensaje(daoModelVenta.Add(_objVenta, _objUsuario, listOjbDetalleMovimientos), "La venta ha sido registrada", "Ha ocurrido un error"); daoModelVenta.Signout(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(salida); break; } case "Consultar": { int id = Integer.parseInt(request.getParameter("id")); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(consultarDetalle(id)); break; } case "Enlistar": { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(getTableVenta()); break; } case "Contador": { response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(getContador()); break; } case "Imprimir": { response.setContentType("application/pdf"); try { Locale loc = Locale.getDefault(); NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(loc); //Primero obtengo el id del Movimiento int id = Integer.parseInt(request.getParameter("id")); //Obtengo el reporte a manera de Map Map material = reporte(id); //Topo ese reporte y lo divido, primero en la compra y luego el detalle Map<String, String> venta = (Map) material.get("Venta"); List<Map> detalle = (List) material.get("Detalle"); //Creo el documento y obtengo el canal de comunicacion con el servidor, para luego enviar el documento. Document document = new Document(); OutputStream os = response.getOutputStream(); //Creo una instancia a partir del documento y del canal PdfWriter.getInstance(document, os); //Abro el documento document.open(); Image logo = Image.getInstance(url + "/public/images/logo.png"); logo.scaleAbsolute(new Rectangle(logo.getPlainWidth() / 4, logo.getPlainHeight() / 4)); document.add(logo); //Creo una fuente para la letra en negrilla final Font helveticaBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); //Escribo y agrego un primer parrafo con los datos basicos de la compra Paragraph headerDerecha = new Paragraph(); headerDerecha.add(new Chunk("Id. de la Venta: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("numeroVenta") + "\n")); headerDerecha.add(new Chunk("Nombre del Cliente: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("nombreCliente") + "\n")); headerDerecha.add(new Chunk("Documento del Cliente: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("documentoCliente") + "\n")); headerDerecha.add(new Chunk("Fecha Venta: ", helveticaBold)); headerDerecha.add(new Chunk(venta.get("fechaVenta") + "\n")); //Escribo y agrego un segundo parrafo con los datos basicos de Stelarte Paragraph headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Stelarte.Decoracion \n", helveticaBold)); headerIzquierda.add(new Chunk("Direccin: ", helveticaBold)); headerIzquierda.add(new Chunk("Calle Falsa 123 # 12a34\n")); headerIzquierda.add(new Chunk("Telfono: ", helveticaBold)); headerIzquierda.add(new Chunk("2583697 \n")); //Agrego los dos anteriores parrafos al Header PdfPTable header = new PdfPTable(2); header.getDefaultCell().setBorder(0); header.addCell(headerIzquierda); header.addCell(headerDerecha); header.setWidthPercentage(100f); header.setSpacingAfter(20); document.add(header); //Creo la tabla del detalle PdfPTable tablaDetalle = new PdfPTable(new float[] { 1, 3, 2, 2 }); tablaDetalle.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); //Creo el titulo, le quito el borde, le digo que ocupara cuatro columnas y que ser centrado PdfPCell tituloCell = new PdfPCell(new Phrase("Detalle de Venta", helveticaBold)); tituloCell.setBorder(0); tituloCell.setColspan(4); tituloCell.setHorizontalAlignment(Element.ALIGN_CENTER); tablaDetalle.addCell(tituloCell); //Aqui creo cada cabecera tablaDetalle.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY); tablaDetalle.addCell(new Phrase("ID", helveticaBold)); tablaDetalle.addCell(new Phrase("Nombre", helveticaBold)); tablaDetalle.addCell(new Phrase("Cantidad", helveticaBold)); tablaDetalle.addCell(new Phrase("Valor", helveticaBold)); tablaDetalle.getDefaultCell().setBackgroundColor(null); //Aqui agrego la tabla cada articulo. for (Map<String, String> next : detalle) { tablaDetalle.addCell(next.get("idArticulo")); tablaDetalle.addCell(next.get("descripcionArticulo")); tablaDetalle.addCell(next.get("cantidad")); tablaDetalle .addCell(currencyFormatter.format(Integer.parseInt(next.get("precioArticulo")))); } //Creo el Footer headerIzquierda = new Paragraph(); headerIzquierda.add(new Chunk("Total: ", helveticaBold)); headerIzquierda .add(new Chunk(currencyFormatter.format(Integer.parseInt(venta.get("totalVenta"))))); PdfPCell footerCell = new PdfPCell(headerIzquierda); footerCell.setBorder(0); footerCell.setColspan(4); footerCell.setHorizontalAlignment(Element.ALIGN_RIGHT); tablaDetalle.addCell(footerCell); //Establesco el tamao y posicion de la tabla, luego la agrego al documento tablaDetalle.setWidthPercentage(100f); tablaDetalle.setHorizontalAlignment(Element.ALIGN_RIGHT); document.add(tablaDetalle); //Cierro el documento y lo envio con flush. document.close(); response.setHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\""); os.flush(); os.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } break; } } } }
From source file:controller.pdf.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w ww. ja va2 s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); OutputStream out = response.getOutputStream(); try { String especialidad = request.getParameter("especialidad"); String turno = request.getParameter("turno"); String dia = request.getParameter("dia"); Document documento = new Document(); documento.setPageSize(PageSize.A4); documento.setPageSize(PageSize.A4.rotate()); // Rectangle one = new Rectangle(70,140); // documento.setPageSize(one); // documento.setMargins(2, 2, 2, 2); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fonttitulo = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD, BaseColor.BLACK); if (turno.equalsIgnoreCase("M")) { par1.add(new Phrase("Citas del dia: " + dia + " Turno Maana", fonttitulo)); } else { par1.add(new Phrase("Citas del dia: " + dia + " Turno Tarde", fonttitulo)); } par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); PdfPTable tabla = new PdfPTable(9); PdfPCell celda1 = new PdfPCell( new Paragraph("Codigo Cita", FontFactory.getFont("Arial", 12, Font.BOLD))); PdfPCell celda2 = new PdfPCell( new Paragraph("Especialidad", FontFactory.getFont("Arial", 12, Font.BOLD))); PdfPCell celda3 = new PdfPCell( new Paragraph("Codigo Paciente", FontFactory.getFont("Arial", 12, Font.BOLD))); PdfPCell celda4 = new PdfPCell(new Paragraph("Nombre", FontFactory.getFont("Arial", 12, Font.BOLD))); PdfPCell celda5 = new PdfPCell( new Paragraph("Apellido Paterno", FontFactory.getFont("Arial", 12, Font.BOLD))); PdfPCell celda6 = new PdfPCell( new Paragraph("Apellido Materno", FontFactory.getFont("Arial", 12, Font.BOLD))); PdfPCell celda7 = new PdfPCell(new Paragraph("Hora", FontFactory.getFont("Arial", 12, Font.BOLD))); PdfPCell celda8 = new PdfPCell(new Paragraph("Doctor", FontFactory.getFont("Arial", 12, Font.BOLD))); PdfPCell celda9 = new PdfPCell(new Paragraph("Da", FontFactory.getFont("Arial", 12, Font.BOLD))); tabla.addCell(celda1); tabla.addCell(celda2); tabla.addCell(celda3); tabla.addCell(celda4); tabla.addCell(celda5); tabla.addCell(celda6); tabla.addCell(celda7); tabla.addCell(celda8); tabla.addCell(celda9); try { Connection conex = conexion.obtener(); PreparedStatement consulta2 = conex.prepareStatement("call pacientegeneral_select();"); ResultSet resultado2 = consulta2.executeQuery(); while (resultado2.next()) { PreparedStatement consulta = conex.prepareStatement("call cita_select();"); ResultSet resultado = consulta.executeQuery(); while (resultado.next()) { if (turno.equalsIgnoreCase("M") && resultado.getString(4).charAt(6) == 'A' && resultado.getInt(3) == resultado2.getInt(1) && resultado.getString(7).equalsIgnoreCase(dia) && resultado.getString(2).equalsIgnoreCase(especialidad)) { tabla.addCell(resultado.getString(1)); tabla.addCell(resultado.getString(2)); tabla.addCell(resultado2.getString(1)); tabla.addCell(resultado2.getString(2)); tabla.addCell(resultado2.getString(3)); tabla.addCell(resultado2.getString(4)); tabla.addCell(resultado.getString(4)); tabla.addCell(resultado.getString(5)); tabla.addCell(resultado.getString(7)); } } } conexion.cerrar(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.toString()); } try { Connection conex = conexion.obtener(); PreparedStatement consulta2 = conex.prepareStatement("call pacientegeneral_select();"); ResultSet resultado2 = consulta2.executeQuery(); while (resultado2.next()) { PreparedStatement consulta = conex.prepareStatement("call cita_select();"); ResultSet resultado = consulta.executeQuery(); while (resultado.next()) { if (turno.equalsIgnoreCase("T") && resultado.getString(4).charAt(6) == 'P' && resultado.getInt(3) == resultado2.getInt(1) && resultado.getString(7).equalsIgnoreCase(dia) && resultado.getString(2).equalsIgnoreCase(especialidad)) { tabla.addCell(resultado.getString(1)); tabla.addCell(resultado.getString(2)); tabla.addCell(resultado2.getString(1)); tabla.addCell(resultado2.getString(2)); tabla.addCell(resultado2.getString(3)); tabla.addCell(resultado2.getString(4)); tabla.addCell(resultado.getString(4)); tabla.addCell(resultado.getString(5)); tabla.addCell(resultado.getString(7)); } } } conexion.cerrar(); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.toString()); } float[] columnWidths = new float[] { 15f, 30f, 18f, 23f, 23f, 23f, 20f, 25f, 18f }; tabla.setWidths(columnWidths); documento.add(tabla); documento.close(); } catch (Exception ex) { ex.getMessage(); } String redirectURL = "citasemana.jsp"; response.sendRedirect(redirectURL); }
From source file:controller.pdfcita.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww .j a v a 2s. com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/pdf"); OutputStream out = response.getOutputStream(); String codigocita = request.getParameter("codigocita"); String nombre = request.getParameter("nombre"); String especialidad = request.getParameter("especialidad"); String fecha = request.getParameter("fecha"); String hora = request.getParameter("hora"); String doctor = request.getParameter("doctor"); try { try { Document documento = new Document(); Rectangle one = new Rectangle(400, 280); documento.setPageSize(one); PdfWriter.getInstance(documento, out); documento.open(); Paragraph par1 = new Paragraph(); Font fontitulo = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK); par1.add(new Phrase("Cita", fontitulo)); par1.setAlignment(Element.ALIGN_CENTER); par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); documento.add(par1); Paragraph par2 = new Paragraph(); Font fontescrip = new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.NORMAL, BaseColor.BLACK); par2.add( new Phrase("LUGAR DE CONSULTA : POLICL?NICO NUESTRA SEORA DE LOS ANGELES", fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase("CODIGO DE CITA : " + codigocita, fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase("PACIENTE : " + nombre, fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase("ESPECIALIDAD : " + especialidad, fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase("FECHA : " + fecha, fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase("HORA DE CITA : " + hora, fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase("DOCTOR(A) : " + doctor, fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase("COSTO DE CITA : 10.00 SOLES", fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase( "El paciente tendr que imprimir esta cita y acercarse a caja para cancelar el monto de la cita para posteriormente acudir a su cita en el consultorio establecido en el recibo.", fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); //par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase( " - Administracin", fontescrip)); par2.add(new Phrase(Chunk.NEWLINE)); par2.setAlignment(Element.ALIGN_JUSTIFIED); documento.add(par2); documento.close(); } catch (Exception ex) { ex.getMessage(); } } finally { out.close(); } //// try{ // // // // Document document = new Document(); // Rectangle one = new Rectangle(70,140); // document.setPageSize(one); // // document.open(); // Paragraph par1=new Paragraph(); // Font fonttitulo=new Font(Font.FontFamily.HELVETICA,25,Font.BOLD,BaseColor.BLACK); // // par1.add(new Phrase("Citas del dia: Turno Maana",fonttitulo)); // document.add(par1); // // // // //// Paragraph p = new Paragraph("Hi"); //// document.add(p); //// document.setPageSize(two); //// document.setMargins(20, 20, 20, 20); //// document.newPage(); //// document.add(p); // document.close(); // // // //// String especialidad=request.getParameter("especialidad"); //// String turno=request.getParameter("turno"); //// String dia=request.getParameter("dia"); // //// Document documento=new Document(); //// documento.setPageSize(PageSize.A4); //// documento.setPageSize(PageSize.A4.rotate()); //// PdfWriter.getInstance(documento, out); //// //// documento.open(); // //// Paragraph par1=new Paragraph(); //// Font fonttitulo=new Font(Font.FontFamily.HELVETICA,25,Font.BOLD,BaseColor.BLACK); //// if (turno.equalsIgnoreCase("M")) { //// par1.add(new Phrase("Citas del dia: "+dia+" Turno Maana",fonttitulo)); //// } //// else{par1.add(new Phrase("Citas del dia: "+dia+" Turno Tarde",fonttitulo));} //// //// //// par1.setAlignment(Element.ALIGN_CENTER); //// par1.add(new Phrase(Chunk.NEWLINE)); //// par1.add(new Phrase(Chunk.NEWLINE)); //// documento.add(par1); //// //// PdfPTable tabla=new PdfPTable(9); //// PdfPCell celda1=new PdfPCell(new Paragraph("Codigo Cita",FontFactory.getFont("Arial", 12, Font.BOLD))); //// PdfPCell celda2=new PdfPCell(new Paragraph("Especialidad",FontFactory.getFont("Arial", 12, Font.BOLD))); //// PdfPCell celda3=new PdfPCell(new Paragraph("Codigo Paciente",FontFactory.getFont("Arial", 12, Font.BOLD))); //// PdfPCell celda4=new PdfPCell(new Paragraph("Nombre",FontFactory.getFont("Arial", 12, Font.BOLD))); //// PdfPCell celda5=new PdfPCell(new Paragraph("Apellido Paterno",FontFactory.getFont("Arial", 12, Font.BOLD))); //// PdfPCell celda6=new PdfPCell(new Paragraph("Apellido Materno",FontFactory.getFont("Arial", 12, Font.BOLD))); //// PdfPCell celda7=new PdfPCell(new Paragraph("Hora",FontFactory.getFont("Arial", 12, Font.BOLD))); //// PdfPCell celda8=new PdfPCell(new Paragraph("Doctor",FontFactory.getFont("Arial", 12, Font.BOLD))); //// PdfPCell celda9=new PdfPCell(new Paragraph("Da",FontFactory.getFont("Arial", 12, Font.BOLD))); // //// tabla.addCell(celda1); //// tabla.addCell(celda2); //// tabla.addCell(celda3); //// tabla.addCell(celda4); //// tabla.addCell(celda5); //// tabla.addCell(celda6); //// tabla.addCell(celda7); //// tabla.addCell(celda8); //// tabla.addCell(celda9); //// //// try{ //// //// Connection conex=conexion.obtener(); //// //// PreparedStatement consulta2=conex.prepareStatement("call pacientegeneral_select();"); //// ResultSet resultado2=consulta2.executeQuery(); //// //// while(resultado2.next()){ //// //// PreparedStatement consulta=conex.prepareStatement("call cita_select();"); //// ResultSet resultado=consulta.executeQuery(); //// //// while(resultado.next()){ //// //// if (turno.equalsIgnoreCase("M") && resultado.getString(4).charAt(6)=='A' && resultado.getInt(3)==resultado2.getInt(1) && resultado.getString(7).equalsIgnoreCase(dia) && resultado.getString(2).equalsIgnoreCase(especialidad)) { //// //// tabla.addCell(resultado.getString(1)); //// tabla.addCell(resultado.getString(2)); //// tabla.addCell(resultado2.getString(1)); //// tabla.addCell(resultado2.getString(2)); //// tabla.addCell(resultado2.getString(3)); //// tabla.addCell(resultado2.getString(4)); //// tabla.addCell(resultado.getString(4)); //// tabla.addCell(resultado.getString(5)); //// tabla.addCell(resultado.getString(7)); //// //// } //// //// } //// } //// //// conexion.cerrar(); //// }catch(Exception ex){JOptionPane.showMessageDialog(null, ex.toString());} // // // // //// try{ //// //// Connection conex=conexion.obtener(); //// //// PreparedStatement consulta2=conex.prepareStatement("call pacientegeneral_select();"); //// ResultSet resultado2=consulta2.executeQuery(); //// //// while(resultado2.next()){ //// //// PreparedStatement consulta=conex.prepareStatement("call cita_select();"); //// ResultSet resultado=consulta.executeQuery(); //// //// while(resultado.next()){ //// //// if (turno.equalsIgnoreCase("T") && resultado.getString(4).charAt(6)=='P' && resultado.getInt(3)==resultado2.getInt(1) && resultado.getString(7).equalsIgnoreCase(dia) && resultado.getString(2).equalsIgnoreCase(especialidad)) { //// //// tabla.addCell(resultado.getString(1)); //// tabla.addCell(resultado.getString(2)); //// tabla.addCell(resultado2.getString(1)); //// tabla.addCell(resultado2.getString(2)); //// tabla.addCell(resultado2.getString(3)); //// tabla.addCell(resultado2.getString(4)); //// tabla.addCell(resultado.getString(4)); //// tabla.addCell(resultado.getString(5)); //// tabla.addCell(resultado.getString(7)); //// //// } //// //// } //// } //// //// conexion.cerrar(); //// }catch(Exception ex){JOptionPane.showMessageDialog(null, ex.toString());} // // // // // // //// float[] columnWidths = new float[]{15f, 30f, 18f, 23f, 23f, 23f, 20f, 25f, 18f}; //// tabla.setWidths(columnWidths); //// //// documento.add(tabla); // document.close(); // // }catch(Exception ex){ex.getMessage();} // // String redirectURL="principal.jsp"; //// response.sendRedirect(redirectURL); }
From source file:controller.PDFGenerator.java
@Override public void GenerateDocument(Resolution doc) { String resId = "RES-IC-" + format(doc.getId()) + "-" + Calendar.getInstance().get(Calendar.YEAR); Document pdf = createDocument(resId + ".pdf"); if (pdf == null) return;//from ww w . j a v a2s .c om try { pdf.open(); Font boldFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); Font parFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); Chunk chunk = new Chunk(doc.getTitle() + "\n\n", boldFont); Paragraph par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_CENTER); pdf.add(par); chunk = new Chunk(resId + "\n\n", boldFont); par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_CENTER); pdf.add(par); chunk = new Chunk("Atencin: ", boldFont); par = new Paragraph(chunk); chunk = new Chunk(doc.getAttention() + "\n\n", parFont); par.add(chunk); par.setAlignment(Paragraph.ALIGN_LEFT); par.setIndentationLeft((float) 3.0); pdf.add(par); chunk = new Chunk(doc.getIntro() + "\n\n", parFont); par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_JUSTIFIED); pdf.add(par); chunk = new Chunk((doc.isOneresult() == true ? "RESULTANDO NICO:\n" : "RESULTANDO:\n"), boldFont); par = new Paragraph(chunk); chunk = new Chunk(doc.getResult() + "\n\n", parFont); par.add(chunk); par.setAlignment(Paragraph.ALIGN_JUSTIFIED); pdf.add(par); chunk = new Chunk((doc.isOneconsideration() == true ? "CONSIDERANDO NICO:\n" : "CONSIDERANDOS:\n"), boldFont); par = new Paragraph(chunk); chunk = new Chunk(doc.getConsider() + "\n\n", parFont); par.add(chunk); par.setAlignment(Paragraph.ALIGN_JUSTIFIED); pdf.add(par); chunk = new Chunk("RESUELVO:\n", boldFont); par = new Paragraph(chunk); chunk = new Chunk(doc.getResolve() + "\n\n", parFont); par.add(chunk); par.setAlignment(Paragraph.ALIGN_JUSTIFIED); pdf.add(par); chunk = new Chunk("NOTIFIQUESE:\n", boldFont); par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_LEFT); pdf.add(par); chunk = new Chunk(doc.getNotify(), parFont); par = new Paragraph(chunk); par.setAlignment(Paragraph.ALIGN_LEFT); par.setIndentationLeft(250); pdf.add(par); pdf.close(); } catch (Exception ex) { System.out.println("Error writirn pdf."); } }