List of usage examples for com.itextpdf.text Font Font
public Font(final BaseFont bf, final float size, final int style, final BaseColor color)
From source file:com.sapito.pdf.PDFView.PDFGeneratorDireccion.java
public void reporteinventario(Map<String, Object> model, HttpServletResponse hsr1, List<Inventario> inventario) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();//ww w.j av a2s . c o m document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30); font1.setColor(BaseColor.BLACK); Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24); font2.setColor(BaseColor.BLACK); document.add(new Paragraph("TAILS 2015", font1)); document.add(new Paragraph("Reportes Direccin\n", font2)); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Reporte de Inventarios"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF TextoPdf x = (TextoPdf) model.get("todoTexto"); document.add(new Paragraph(x.getTodoTexto())); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 2.0f }); table.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.COURIER_BOLD); font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(BaseColor.BLUE); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Total de Inventarios", font)); table.addCell(cell); for (int i = 0; i < inventario.size(); i++) { a = inventario.get(i).getPrecioUnitario(); b = a + b; } String bla = b + " "; table.addCell(bla); document.add(table); //-------------------------- FIN CONTENIDO ----------------- document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorDireccion.java
public void reporteRH(Map<String, Object> model, HttpServletResponse hsr1, int detalle) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();//from w w w . j a v a2 s . c o m document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30); font1.setColor(BaseColor.BLACK); Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24); font2.setColor(BaseColor.BLACK); document.add(new Paragraph("TAILS 2015", font1)); document.add(new Paragraph("Reportes Direccin\n", font2)); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Reporte de Recursos Humanos"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF TextoPdf x = (TextoPdf) model.get("todoTexto"); document.add(new Paragraph(x.getTodoTexto())); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 2.0f }); table.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.COURIER_BOLD); font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(BaseColor.BLUE); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Total de de Empleados en Vacaciones", font)); table.addCell(cell); String bla = detalle + " "; table.addCell(bla); document.add(table); //-------------------------- FIN CONTENIDO ----------------- document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorDireccion.java
public void reportefinanzas(Map<String, Object> model, HttpServletResponse hsr1, List<CuentaBancaria> cuenta) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();//from w w w . j a va 2s . com document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); Font font1 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 30); font1.setColor(BaseColor.BLACK); Font font2 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24); font2.setColor(BaseColor.BLACK); document.add(new Paragraph("TAILS 2015", font1)); document.add(new Paragraph("Reportes Direccin\n", font2)); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Reporte de Finanzas"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF TextoPdf x = (TextoPdf) model.get("todoTexto"); document.add(new Paragraph(x.getTodoTexto())); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); table.setWidths(new float[] { 2.0f }); table.setSpacingBefore(10); // define font for table header row Font font = FontFactory.getFont(FontFactory.COURIER_BOLD); font.setColor(BaseColor.WHITE); // define table header cell PdfPCell cell = new PdfPCell(); cell.setBackgroundColor(BaseColor.BLUE); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Total de dinero que se tiene en CUENTAS BANCARIAS", font)); table.addCell(cell); for (int i = 0; i < cuenta.size(); i++) { a = cuenta.get(i).getHaber(); b = b + a; } String bla = b + " "; table.addCell(bla); document.add(table); //-------------------------- FIN CONTENIDO ----------------- document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.sapito.pdf.PDFView.PDFGeneratorVentas.java
public void crearPDFFactura(HttpServletResponse hsr1) throws Exception { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open();/* w w w .j a v a2 s .c om*/ document.addTitle("Sapito PDFs"); document.addSubject("Pdf de sapito"); //------------------------ TAIS ______________________________ Image tais = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/tais-banner.jpg")); document.add(tais); //--------------------- BODY --------------------------------------------------------- Image body = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/body.png")); body.setAlignment(Image.UNDERLYING); body.setTransparency(new int[] { 0x00, 0x10 }); body.setAbsolutePosition(50, 250); document.add(body); //------------------------------------------------------------------------------------------- Image footer = Image.getInstance(new URL("http://localhost:8080/SAPITO/resources/img/footer.jpg")); footer.setAbsolutePosition(50, 20); document.add(footer); //---------------------- TITLE --------------------------- String titulo = "Facturas"; //Cambiar el titulo del PDF aqui Font f = new Font(FontFamily.HELVETICA, 25.0f, Font.BOLD, BaseColor.BLACK); Chunk c = new Chunk(titulo + " \n ", f); c.setBackground(BaseColor.WHITE); Paragraph title = new Paragraph(c); title.setAlignment(Element.ALIGN_CENTER); //------------------------- CONTENIDO ------------------------------------------------------- document.add(title); //Titulo del PDF PdfPTable table = new PdfPTable(1); table.addCell("Hola"); table.addCell("Soy"); table.addCell("el"); table.addCell("pdf"); table.addCell("del"); table.addCell("sapito"); document.add(table); document.close(); byte[] bytes = baos.toByteArray(); hsr1.setContentType("application/pdf"); hsr1.setContentLength(bytes.length); hsr1.getOutputStream().write(bytes); }
From source file:com.skatettoo.reportes.Generador.java
public String generarPDF() throws Exception { try {/* w ww.j av a 2 s .c o m*/ String path = FacesContext.getCurrentInstance().getExternalContext().getRealPath("img"); path = path.substring(0, path.indexOf("\\build")); path = path + "\\web\\img\\"; Document doc = new Document(PageSize.A4, 36, 36, 10, 10); PdfPTable tabla = new PdfPTable(4); PdfWriter.getInstance(doc, new FileOutputStream(path + "\\archivo\\reporte.pdf\\")); doc.open(); Image img = Image.getInstance(path + "Skatetoo4.png"); img.scaleAbsolute(40, 40); img.setAlignment(Element.ALIGN_LEFT); doc.add(img); doc.addTitle(this.titulo); doc.addAuthor("\n "); doc.addAuthor("\n "); doc.addAuthor("\n "); doc.addAuthor("\n "); tabla.setWidthPercentage(100); tabla.setWidths(new float[] { 1.4f, 0.8f, 0.8f, 0.8f }); Object font = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD, BaseColor.WHITE); PdfPCell cell = new PdfPCell(new Phrase("Reporte de tatuadores", (Font) font)); cell.setColspan(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingTop(0f); cell.setPaddingBottom(7f); cell.setBackgroundColor(new BaseColor(0, 0, 0)); cell.setBorder(0); cell.setBorderWidthBottom(2f); tabla.addCell(cell); tabla.addCell("Tatuador"); tabla.addCell("Cantidad de diseos"); tabla.addCell("Citas realizadas"); tabla.addCell("Noticias publicadas"); for (Usuario u : this.getUsu()) { tabla.addCell(u.getNombre() + " " + u.getApellido()); tabla.addCell(String.valueOf(u.getDisenioList().size())); tabla.addCell(String.valueOf(u.getCitaList1().size())); tabla.addCell(String.valueOf(u.getNoticiaList().size())); } doc.add(tabla); doc.bottomMargin(); /* doc.add(new Paragraph("Tatuador mas solicitado")); for(Usuario u : this.getUs()){ doc.add(new Paragraph(u.getNombre() + " " + u.getApellido())); }*/ doc.close(); FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); externalContext.responseReset(); externalContext.setResponseContentType("application/pdf"); externalContext.setResponseHeader("Content-Disposition", "attachment;filename=\"reporte.pdf\""); FileInputStream inputStream = new FileInputStream(new File(path + "\\archivo\\reporte.pdf\\")); OutputStream outputStream = externalContext.getResponseOutputStream(); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } inputStream.close(); context.responseComplete(); } catch (Exception e) { throw e; } return ""; }
From source file:com.vectorprint.report.itext.debug.DebugHelper.java
License:Open Source License
public static Font debugFontLink(PdfContentByte canvas, EnhancedMap settings) { BaseFont bf = debugFont(canvas, settings); return new Font(bf, 8, Font.UNDERLINE, itextHelper.fromColor(settings.getColorProperty(Color.MAGENTA, ReportConstants.DEBUGCOLOR))); }
From source file:com.zentrix.minutas.SMinuta.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//from w w w. ja v a 2s .c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //obtenemos los datos de la forma String titulo = request.getParameter("titulo"); String cuerpo = request.getParameter("cuerpominuta"); ServletOutputStream sos = response.getOutputStream(); response.setContentType("application/pdf"); //creamos un nuevo documento Document doc = new Document(); //creamos los estilos y las fuentes Font bfBold20 = new Font(FontFamily.TIMES_ROMAN, 20, Font.BOLD, new BaseColor(0, 0, 0)); Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLDITALIC, new BaseColor(0, 0, 0)); Font bf12 = new Font(FontFamily.TIMES_ROMAN, 12); try { //creamos un instancio de PdfWriter usando el OutputStream PdfWriter.getInstance(doc, sos); doc.addAuthor("Sistema Gestor de Academias"); doc.addCreationDate(); doc.addProducer(); doc.addCreator("Sistema de Academias"); doc.addTitle(titulo); doc.setPageSize(PageSize.LETTER); doc.open(); doc.add(new Paragraph(titulo, bfBold20)); doc.add(new Paragraph(cuerpo, bf12)); doc.close(); // PrintWriter out = response.getWriter(); // out.println("titulo "+ titulo); // out.println("cuerpo "+ cuerpo); } catch (DocumentException ex) { ex.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:Controller.app.ConsultaController.java
private File createPDF(TblServicioFactura factura) throws IOException { String data = factura.getTesPagoResponse(); JSONObject obj = new JSONObject(data); JSONArray content = obj.getJSONArray("lineaFactura"); String temp = ""; File _file = null;/* w w w . ja v a 2s . com*/ Document doc = null; OutputStream file = null; int page = 0; try { _file = File.createTempFile("temp_file", ".pdf"); TblServicioServicio servicio = servicios.search(factura.getTesCodigoSintesisBi().toString()); file = new FileOutputStream(_file); doc = new Document(PageSize.LETTER); doc.setMargins(servicio.getMarginLeft().floatValue(), servicio.getMarginRight().floatValue(), servicio.getMarginTop().floatValue(), servicio.getMarginBottom().floatValue()); PdfWriter.getInstance(doc, file); doc.open(); // ClassLoader classloader = Thread.currentThread().getContextClassLoader(); ClassLoader classloader = getClass().getClassLoader(); URL url = classloader.getResource("cour.ttf"); BaseFont base = null; if (url == null) { base = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } else { String path = url.getPath(); if ("/".equals(path.substring(0, 1))) { path = path.substring(1); } Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, path); base = BaseFont.createFont(path, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); } Font f = new Font(base, servicio.getFontSize(), Font.NORMAL, BaseColor.BLACK); String qr = ""; float line = 0; for (Object item : content) { Paragraph paragraph = new Paragraph(item.toString(), f); if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL")) { if (item.toString().contains("P X#X&$#&K##")) { paragraph = new Paragraph(" ", f); doc.add(paragraph); doc.add(paragraph); paragraph = new Paragraph(item.toString(), f); } } if (item.toString().contains("<b>")) { Font bold = new Font(base, 7.0f, Font.BOLD, BaseColor.BLACK); paragraph = new Paragraph(item.toString().replace("<b>", ""), bold); } if (item.toString().contains("<QR>") || item.toString().contains("<QR_ENT_G>")) { qr = item.toString().replaceAll("<QR>", ""); qr = item.toString().replaceAll("<QR_ENT_G>", ""); Image image = QR.create(qr); image.scaleAbsolute(servicio.getQrScale().floatValue(), servicio.getQrScale().floatValue()); if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL") || servicio.getTesDetalleVc().trim().equals("PAGO TELECEL") || servicio.getTesDetalleVc().trim().equals("PAGO NUEVATEL") || servicio.getTesDetalleVc().trim().equals("PAGO TIGOSTAR (MULTIVISION)")) { float y = (doc.getPageSize().getHeight() - (paragraph.getLeading() * (line + 1))); float x = 0; if (servicio.getTesDetalleVc().trim().equals("PAGO ENTEL")) { image.setAlignment(Image.ALIGN_RIGHT); x = doc.getPageSize().getWidth() - (110 - servicio.getMarginLeft().floatValue()); } if (servicio.getTesDetalleVc().trim().equals("PAGO TELECEL")) { image.setAlignment(Image.ALIGN_LEFT); x = 30; y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading() * 2)); } if (servicio.getTesDetalleVc().trim().equals("PAGO NUEVATEL")) { image.setAlignment(Image.ALIGN_LEFT); x = doc.getPageSize().getWidth() - (120 - servicio.getMarginLeft().floatValue()); y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading())); } if (servicio.getTesDetalleVc().trim().equals("PAGO TIGOSTAR (MULTIVISION)")) { image.setAlignment(Image.ALIGN_LEFT); x = doc.getPageSize().getWidth() - (120 - servicio.getMarginLeft().floatValue()); y -= (servicio.getQrScale().floatValue() - (paragraph.getLeading())); } image.setAbsolutePosition(x, y); } doc.add(image); } if (servicio.getDelimitador().equals(item.toString().trim())) { line = 0; page++; doc.newPage(); } else { line += 1f; if (!(item.toString().contains("<QR>") || item.toString().contains("<QR_ENT_G>"))) { doc.add(paragraph); } } temp += item.toString(); } } catch (FileNotFoundException ex) { Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, null, ex); } catch (DocumentException | IOException ex) { Logger.getLogger(ConsultaController.class.getName()).log(Level.INFO, null, ex); } doc.close(); file.close(); return _file; }
From source file:controller.pdf.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w. j av a 2 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 a2 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(); 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); }