Ver Mensaje Individual
  #5 (permalink)  
Antiguo 27/04/2011, 08:19
Avatar de valdo_kof
valdo_kof
 
Fecha de Ingreso: noviembre-2009
Ubicación: San Juan del Rio, Qro
Mensajes: 192
Antigüedad: 14 años, 6 meses
Puntos: 16
Respuesta: Imprimir factura desde una aplicacion JAVA

Cita:
Iniciado por tronco020 Ver Mensaje
¿Y hay alguna forma de hacerlo sin iReport? O mejor aún ¿Hay alguna forma de usar iReport sin conexion a BD, simplemente pasándole los parámetros de una estructura que ya tengo cargada en memoria?
si, si hay forma, ireports no presisamente te agarra los valores de un base de datos tu le puedes mandar los valores fijos al reporte, ahora si lo que quieres es puro codigo prueba con esto

Código Java:
Ver original
  1. public class imprimir {
  2.    
  3. public String RFC;
  4. public String Nombre;
  5. public String Direccion;
  6. public String Telefono;
  7. public String C_post;
  8. public String Col;
  9. public String Edo;
  10. public String Mun;
  11. public String Salida;
  12.  
  13.  
  14. public void impresion(String item){
  15. PrinterJob printJob = PrinterJob.getPrinterJob();
  16.   Book book = new Book();
  17.   book.append(new IntroPage(), printJob.defaultPage());
  18.     printJob.setPageable(book);
  19.     if (printJob.printDialog()) {
  20.       try {
  21.         printJob.print();
  22.       } catch (Exception PrintException) {
  23.         PrintException.printStackTrace();
  24.       }
  25.     }
  26.  
  27. }
  28. private class IntroPage implements Printable {
  29.          public int print() {
  30.             try {
  31.                
  32.                 Font rfcFont = new Font("Arial", Font.BOLD, 8);
  33.                 Font nombreFont = new Font("Arial", Font.BOLD, 6);
  34.                 Font direccioFont = new Font("Arial", Font.BOLD, 6);
  35.                 FontMetrics rfcfontMetrics = g2d.getFontMetrics();
  36. FontMetrics nombrefontMetrics = g2d.getFontMetrics();
  37. FontMetrics direccionfontMetrics = g2d.getFontMetrics();
  38.                 g2d.drawString(RFC, 51, 12);//el 51,12 son las coordenadas en puntos en donde quieres q se dibuje tu registro
  39.                 g2d.setFont(rfcFont);
  40.                 FontMetrics rfcfontMetrics = g2d.getFontMetrics();
  41.                 g2d.drawString(Nombre, 6, 24);
  42.                 g2d.setFont(nombreFont);
  43.                 FontMetrics nombrefontMetrics = g2d.getFontMetrics();
  44.                 g2d.drawString(Direccion, 15, 33);
  45.                 g2d.setFont(direccionFont);
  46.                 FontMetrics direccionfontMetrics = g2d.getFontMetrics();
  47.                                      } catch (BarcodeException ex) {
  48.                 Logger.getLogger(imprimir_caja.class.getName()).log(Level.SEVERE, null, ex);
  49.             } return PAGE_EXISTS;
  50.    }
  51.   }
  52. }

algo asi quedaria

para mas informacion bsca en google o en la red imprimir usando printjob o solo dale click en alguno de los links q aparecen en el codigo

espero y te sirva

suerte