Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   JAVA (https://www.clubdelphi.com/foros/forumdisplay.php?f=16)
-   -   generar un archivo pdf (https://www.clubdelphi.com/foros/showthread.php?t=36376)

cahosoft 10-10-2006 16:27:52

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....

epuigdef 10-10-2006 17:26:22

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

cahosoft 12-10-2006 16:50:15

Gracias voy a Probar
 
Gracias por tu atencion... Voy a probar el codigo.....

LucianoRey 17-10-2006 02:07:50

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.


La franja horaria es GMT +2. Ahora son las 07:59:07.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi