Java - Imprimir en Java

 
Vista:

Imprimir en Java

Publicado por mayito (2 intervenciones) el 28/06/2009 01:17:15
Hola amigos estoy con un proyecto, y necesito que me ayuden como puedo imprimir los datos ke ingreso en los textos o en una tabla, es decir que me salgan en formato pdf, o cualkier formato de texto. porfa ayudenme..!!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Imprimir en Java

Publicado por James (207 intervenciones) el 28/06/2009 07:15:31
Lo mejor seria que hagas un reporte de tus datos, usa iReport si usas Netbeans se agrega completamente como un plugin y puedes diseñar tu reporte desde el mismo Netbeans, en todo caso hacer un reporte no es nada dificil, y luego lo puedes exportar a .pdf, .doc, .xls, etc..

Otra opcion seria usar algun tipo de libreria como JExcel(de Sun Excel) o POI(de Apache para documentos Microsoft), existe una para PDF's (pero no recuerdo su nombre), o JDOM(de Apache XML) y mandar a generar el archivo por tu cuenta, pero siempre le veo mas facil hacer un reporte, Suerte
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Imprimir en Java/

Publicado por adicson (2 intervenciones) el 01/07/2009 12:01:57
saludos,

Tengo una pluing de java para imprimir informacion geografica, bajado de internet ahora bien el problema es que al mandar a imprimir se tarda en imprimir la consulta realizada, lo que necesito es que reviso y como indago el codigo fuente del .jar para realizar la mejora en el momento de la impresion
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Imprimir en Java

Publicado por rasof (35 intervenciones) el 29/06/2009 12:02:34
mira este es el motodo ke yo uso para hacer un pdf con los datos de muchas tablas ke tengo en la base de datos, intenta adaptarla para tu caso, tendrias ke añadir a tu proyexto el .jar de ireport,

private void printPropio() {
Document document = new Document(PageSize.A4);
PdfWriter writer;

try {
writer =
PdfWriter.getInstance(document, new FileOutputStream(textRuta.getText() +
"\" +
textNombrePDF.getText() +
".pdf"));
System.out.println(textRuta.getText() + "\" + textNombrePDF.getText() +
".pdf");
document.open();
Object o[] = recogerValoresLista();
int luz = o.length;
for (int i = 0; i < luz; i++) {
float[] widths1 = { 1f, 2f, 1.1f, 1f };
PdfPTable table = new PdfPTable(widths1);
PdfPCell cell = new PdfPCell(new Paragraph("GRAFICO " + o[i]));
cell.setColspan(4);
cell.setBorder(0);
table.addCell(cell);
DescripcionGraficosDAO cdao = new DescripcionGraficosDAO();
//este es el rs que necesitamos para llenar la tabla
ResultSet rs =
(ResultSet)cdao.getDescripcionGraficosByIdGraf(Integer.parseInt(o[i].toString()));
cell = new PdfPCell(new Paragraph("HORA SALIDA"));
cell.setBackgroundColor(new Color(193, 205, 205));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("DESCRIPCION"));
cell.setBackgroundColor(new Color(193, 205, 205));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TIPO RUTA"));
cell.setBackgroundColor(new Color(193, 205, 205));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("S.A.E"));
cell.setBackgroundColor(new Color(193, 205, 205));
table.addCell(cell);
while (rs.next()) {
table.addCell(rs.getObject(1).toString());
table.addCell(rs.getObject(2).toString());
table.addCell(rs.getObject(3).toString());
table.addCell(rs.getObject(4).toString());
}

//PARA LA FILA EN BLANCO ANTES DEL RESUMEN DE TIEMPOS
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(4);
cell.setBorder(0);
table.addCell(cell);
table.addCell(cell);
//aki los tiempos de cada grafico!!!!! (falta da!!!)
//aki las cabezeras
GraficosDAO gdao = new GraficosDAO();
ResultSet rs2 =
(ResultSet)gdao.getTiemposById(Integer.parseInt(o[i].toString()));
rs2.next();
cell = new PdfPCell(new Paragraph("TIEMPO TOTAL"));
cell.setBackgroundColor(new Color(230, 230, 250));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TIEMPO PARADO"));
cell.setBackgroundColor(new Color(230, 230, 250));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TIEMPO VACIO"));
cell.setBackgroundColor(new Color(230, 230, 250));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TIEMPO EXTRA"));
cell.setBackgroundColor(new Color(230, 230, 250));
table.addCell(cell);
//aki los tiempos
table.addCell(rs2.getObject(1).toString());
table.addCell(rs2.getObject(2).toString());
table.addCell(rs2.getObject(3).toString());
table.addCell(rs2.getObject(4).toString());
//PARA LA FILA EN BLANCO ANTES DEL SIGUIENTE GRAFICO
cell = new PdfPCell(new Paragraph(""));
cell.setColspan(4);
cell.setBorder(0);
table.addCell(cell);
table.addCell(cell);
//AÑADIR TABLA AL GRAFICO
document.add(table);
}
//despues de todos los graficos un resumen con los tiempos totales de la seleccion de graficos
float[] widths1 = { 1f, 1f, 1f, 1f };
PdfPTable table = new PdfPTable(widths1);
PdfPCell cell = new PdfPCell(new Paragraph("RESUMEN:"));
cell.setColspan(4);
cell.setBorder(0);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TIEMPO TOTAL"));
cell.setBackgroundColor(new Color(0, 191, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TIEMPO PARADO"));
cell.setBackgroundColor(new Color(0, 191, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TIEMPO VACIO"));
cell.setBackgroundColor(new Color(0, 191, 255));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("TIEMPO EXTRA"));
cell.setBackgroundColor(new Color(0, 191, 255));
table.addCell(cell);
//aki los valores totales del documento
GraficosDAO gdao = new GraficosDAO();
ResultSet rs3 = (ResultSet)gdao.getTiemposResumen(o);
rs3.next();
table.addCell(rs3.getObject(1).toString());
table.addCell(rs3.getObject(2).toString());
table.addCell(rs3.getObject(3).toString());
table.addCell(rs3.getObject(4).toString());

document.add(table);
//cerrar documento
document.close();
} catch (Exception e) {
System.out.println(e);
}

}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar