You are on page 1of 3

import import import import import import import import import import import import import import import

import import import import import import import import import import

java.awt.Color; java.awt.Desktop; java.awt.Graphics; java.awt.Rectangle; java.io.File; java.io.FileOutputStream; java.io.OutputStream; java.sql.SQLException; com.itextpdf.text.BaseColor; com.itextpdf.text.Chunk; com.itextpdf.text.Document; com.itextpdf.text.Element; com.itextpdf.text.Font; com.itextpdf.text.Font.FontFamily; com.itextpdf.text.Image; com.itextpdf.text.PageSize; com.itextpdf.text.Paragraph; com.itextpdf.text.Phrase; com.itextpdf.text.WritableDirectElement; com.itextpdf.text.pdf.ColumnText; com.itextpdf.text.pdf.PdfContentByte; com.itextpdf.text.pdf.PdfPCell; com.itextpdf.text.pdf.PdfPTable; com.itextpdf.text.pdf.PdfPageEventHelper; com.itextpdf.text.pdf.PdfWriter;

import java.text.SimpleDateFormat; import java.util.Date; import controlador.Conexion; public class Reporte extends PdfPageEventHelper { Document document = new Document(); Date fecha = new Date(); SimpleDateFormat formato = new SimpleDateFormat("EEEE_dd_MMMM_yyyy"); String resultado = formato.format(fecha); private static Font fuenteCourierNew20 = new Font(FontFamily.COURIER, 22,Font.BOLD); private static Font fuenteCourierNew12 = new Font(FontFamily.COURIER, 18,Font.BOLD); public void Clientes_reporte() throws ClassNotFoundException, SQLExce ption { Conexion cdb=new Conexion(); cdb.un_sql="select idcliente, concat(nombre,' ',apellidopater no) as cliente, ruta, telefonolocal, telefonocelular, concat(calle,' ',noexterio r,' ',colonia,' ',ciudad,' ',estado) as calle from cliente order by apellidopat erno;"; cdb.resultado=cdb.un_st.executeQuery(cdb.un_sql); try { OutputStream file = new FileOutputStream(new File("Re portes_Creditos\\Reporte_Credito"+resultado+".PDF")); PdfWriter writer=PdfWriter.getInstance(document, file ); document.open(); document.setPageSize(PageSize.LETTER.rotate());

document.setMargins(72, 72, 72, 72); document.newPage(); PdfContentByte cb = writer.getDirectContent(); cb.fillStroke(); cb.setLineWidth(1); cb.moveTo(30,430); cb.lineTo(770,430); //cb.lineTo(10,10); try { Image foto = Image.getInstance("logo.jpg"); foto.scaleToFit(100, 100); foto.setAlignment(Chunk.ALIGN_RIGHT); document.add(foto); } catch ( Exception e ) { e.printStackTrace(); } Paragraph ParrafoHoja = new Paragraph(); document.add(new Paragraph("Reporte Cobranza\n",fuenteCourie rNew20)); document.add(new Paragraph(resultado)); document.add(new Paragraph(" \n")); PdfPCell cell = new PdfPCell(); PdfPCell cell2 = new PdfPCell(); PdfPCell cell3 = new PdfPCell(); PdfPCell cell4 = new PdfPCell(); PdfPCell cell5 = new PdfPCell(); PdfPCell cell6 = new PdfPCell(); cell.addElement(new Paragraph("Clave")); cell2.addElement(new Paragraph("Nombre")); cell3.addElement(new Paragraph("Ruta")); cell4.addElement(new Paragraph("Telfono")); cell5.addElement(new Paragraph("Celular")); cell6.addElement(new Paragraph("Dieccin")); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); cell3.setBackgroundColor(BaseColor.LIGHT_GRAY); cell4.setBackgroundColor(BaseColor.LIGHT_GRAY); cell5.setBackgroundColor(BaseColor.LIGHT_GRAY); cell6.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setBorder(Rectangle.OUT_TOP); cell2.setBorder(Rectangle.OUT_TOP); cell3.setBorder(Rectangle.OUT_TOP); cell4.setBorder(Rectangle.OUT_TOP); cell5.setBorder(Rectangle.OUT_TOP); cell6.setBorder(Rectangle.OUT_TOP);

PdfPTable tabla = new PdfPTable(6); float[]medidasCeldas = {2.5f,14.0f,6.0f,4.0f,3.5f,16.0f}; tabla.setWidths(medidasCeldas); tabla.setWidthPercentage(120f); tabla.getDefaultCell().setBorder(Rectangle.OUT_TOP); tabla.addCell(cell); tabla.addCell(cell2);

tabla.addCell(cell3); tabla.addCell(cell4); tabla.addCell(cell5); tabla.addCell(cell6);

while(cdb.resultado.next()){ tabla.addCell((cdb.resultado.getString("idcliente"))); tabla.addCell((cdb.resultado.getString("cliente"))); tabla.addCell((cdb.resultado.getString("ruta"))); tabla.addCell((cdb.resultado.getString("telefonolocal")) ); tabla.addCell((cdb.resultado.getString("telefonocelular" ))); tabla.addCell((cdb.resultado.getString("calle"))); //document.newPage(); } document.add(tabla); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } } private static void agregarLineasEnBlanco(Paragraph parrafo, int nLin eas) { for (int i = 0; i < nLineas; i++) parrafo.add(new Paragraph(" ")); } }

You might also like