![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
![]() |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#1
|
|||
|
|||
|
generar un archivo pdf
hola como estan....
ya he averiguado sobre este tema en esta pagina http://itextdocs.lowagie.com ofrecen una libreria itext-1.4.5.jar en esa misma pagina hay ejemplos pero no he podido hacerla funcianar.... si alguien tiene un war o un ejemplo con jsp se lo agredeceria.... |
|
#2
|
||||
|
||||
|
Ahí va:
Este código genera una tabla java con los resultados de una sentencia SQL: Código:
privatevoid generarPDF2(ConsultasPortletSessionBean b, String nombre, String path) {
try {
GestorPropiedades gp = GestorPropiedades.getInstance("sql");
Connection conexion = gp.obtenerConexion("sql");
Statement mandato = conexion.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = mandato.executeQuery(b.getSentencia());
Document doc = new Document(PageSize.A4.rotate());
PdfWriter.getInstance(doc, new FileOutputStream(path + nombre));
int total = 0;
for(int i = 1;i<=rs.getMetaData().getColumnCount();i++)
total += rs.getMetaData().getColumnDisplaySize(i);
float[] widths = newfloat[rs.getMetaData().getColumnCount()];
for(int i = 1;i<=rs.getMetaData().getColumnCount();i++) {
widths[i-1] = 100*rs.getMetaData().getColumnDisplaySize(i) / total;
}
doc.open();
Font f = new Font(Font.HELVETICA, 18);
Paragraph par = new Paragraph(b.getConsultaCargada().getTitulo()+"\r\n\r\n", f);
doc.add(par);
PdfPTable table = new PdfPTable(rs.getMetaData().getColumnCount());
table.setWidths(widths);
for(short i = 1;i<=rs.getMetaData().getColumnCount();i++) {
table.addCell(rs.getMetaData().getColumnLabel(i));
}
while (rs.next()) {
for(short i = 1;i<=rs.getMetaData().getColumnCount();i++) {
table.addCell(rs.getString(i));
}
}
table.setWidthPercentage(100);
doc.add(table);
doc.close();
}
catch(Exception e) {
System.err.println(e.getMessage());
}
}
Un saludo Edu |
|
#3
|
|||
|
|||
|
Gracias voy a Probar
Gracias por tu atencion... Voy a probar el codigo.....
|
|
#4
|
|||
|
|||
|
Hola, yo tambien estoy probando itext para mis reportes, yo me guie por el ejemplo que esta en el apartado que dice iText in a Web Application y el ejemplo que dice SilentPrintServlet , solo genere el html ó jsp que llama este servlet y ya. Saludos.
|
![]() |
|
|
Temas Similares
|
||||
| Tema | Autor | Foro | Respuestas | Último mensaje |
| Como Generar Un Archivo Txt Desde Delphi | AdIIX | Varios | 10 | 27-09-2007 20:48:04 |
| Generar SQL | jevo19100 | Firebird e Interbase | 5 | 07-10-2006 22:17:21 |
| generar un archivo de texto | raudelink | Varios | 2 | 28-01-2005 22:45:51 |
| Generar archivo de Word (.doc) | santiago14 | Servers | 3 | 11-04-2004 09:36:16 |
| generar un archivo plano en delphis | cahosoft | Impresión | 1 | 19-11-2003 17:31:52 |
|