This discussion is archived
4 Replies Latest reply: Aug 29, 2011 7:29 AM by 857053 RSS

Trouble with Printable Interface

857053 Newbie
Currently Being Moderated
Hello forum people!

I have a problem to print an order through the Printable interface.
The print () method calls to other methods do they print header data, summaries, barcodes, etc..
That's what it does well, but when I need to print a ResultSet with the items of the order, nothing prints, there is the space reserved for items in blank.
I've controlled outputs to the console, and the method usually runs through the ResultSet, but does not print.
Some of you will bring an example of printing a ResultSet?

Thanks for your attention.

Gustavo Echenique
  • 1. Re: Trouble with Printable Interface
    EJP Guru
    Currently Being Moderated
    Suppose you show us what you tried.
  • 2. Re: Trouble with Printable Interface
    857053 Newbie
    Currently Being Moderated
    Yes, forgiveness, and hit the code:

    the print() code:
         public int print (Graphics g, PageFormat f, int pageIndex){
    
              g2 = (Graphics2D) g;  //Vamos a usar el Java2D como entorno gráfico para imprimir las páginas
    
              //if(todosImpresos){
              //     return Printable.NO_SUCH_PAGE;
              //}
    
    
              /**
              Vamos a dibujar un rectángulo con los máximos puntos imprimibles
              de la hoja A4
              */
              Double valorInicialX = f.getImageableX();
              Double valorInicialY = f.getImageableY();
              Double maximoAncho = f.getImageableWidth();
              Double maximaAltura = f.getImageableHeight();
    
              //Este rectángulo es de pruebas, para ver los márgenes máximos de impresión.
              Rectangle2D rectanguloPruebas = new Rectangle2D.Double(f.getImageableX(),f.getImageableY(), f.getImageableWidth(), f.getImageableHeight());
              g2.draw(rectanguloPruebas);
    
              //Imprimimos el primer rectángulo (Encabezado de la Factura)
              g2.translate(valorInicialX, valorInicialY);
    
              Rectangle2D rectangulo = new Rectangle2D.Double(79.1504, 59.9781, 477.7292, 74.2586);
              //Hacemos las subdivisiones del encabezado
              Rectangle2D rectanguloIzquierda = new Rectangle2D.Double(79.1504, 59.9781, 220.4904, 74.2586);
              Rectangle2D rectanguloCentro = new Rectangle2D.Double( 299.6408, 59.9781, 31.0948, 31.0948);
              Rectangle2D rectanguloDerecha = new Rectangle2D.Double( 330.7356, 59.9781, 226.144, 74.2586);
    
              //Ahora imprimimos el segundo rectángulo, el mayor, el cuerpo de la factura. Luego hay que hacer las subdivisiones
              Rectangle2D rectangulo1 = new Rectangle2D.Double(8.4804, 134.2367, 548.3992, 354.1564);
              //Hacemos las subdivisiones del segundo rectángulo
              Rectangle2D rectanguloDatos = new Rectangle2D.Double(8.4804, 134.2367, 548.3992, 28.561);
    
              Rectangle2D rectanguloFecha = new Rectangle2D.Double(8.4804, 134.2367, 70.67, 11.4244);
              Rectangle2D rectanguloFecha1 = new Rectangle2D.Double(8.4804, 134.2367, 70.67, 28.561);
              Rectangle2D rectanguloRuta = new Rectangle2D.Double(79.1504, 134.2367, 81.9772, 11.4244);
              Rectangle2D rectanguloRuta1 = new Rectangle2D.Double(79.1504, 134.2367, 81.9772, 28.561);
              Rectangle2D rectanguloAsociado = new Rectangle2D.Double(161.1276, 134.2367, 53.7092, 11.4244);
              Rectangle2D rectanguloAsociado1 = new Rectangle2D.Double(161.1276, 134.2367, 53.7092, 28.561);
              Rectangle2D rectanguloPeriodo = new Rectangle2D.Double(214.8368, 134.2367, 84.804, 11.4244);
              Rectangle2D rectanguloPeriodo1 = new Rectangle2D.Double(214.8368, 134.2367, 84.804, 28.561);
    
              //Acá vamos a imprimir  el recuadro que va a contener los recuadros de Servicio, Período Leído, Días, Lectura Actual, Lectura Anterior, Multiplicador, Consumo, Tarifa, Importe Consumo
              Rectangle2D rectanguloServicio = new Rectangle2D.Double(8.4804, 197.0709, 548.3992, 34.2732);
              Rectangle2D rectanguloServicio1 = new Rectangle2D.Double(8.4804, 197.0709, 548.3992, 8.5683 );     //Rectángulo donde irán los títulos arriba indicados
              Rectangle2D rectanguloServ = new Rectangle2D.Double(8.4804, 197.0709, 25.4412, 25.7049 );
              Rectangle2D rectanguloMedidor = new Rectangle2D.Double(33.9216, 197.0709, 65.0174, 25.709);
              Rectangle2D rectanguloPeriodoLeido = new Rectangle2D.Double(98.939, 197.0709, 96.1112, 25.709);
              Rectangle2D rectanguloDias = new Rectangle2D.Double(195.0502, 197.0709, 28.268, 25.709);
              Rectangle2D rectanguloLecturaActual = new Rectangle2D.Double(223.3182, 197.0709, 53.7092, 25.709);
              Rectangle2D rectanguloLecturaAnterior = new Rectangle2D.Double(277.0274, 197.0709, 56.536, 25.709);
              Rectangle2D rectanguloMultiplicador = new Rectangle2D.Double(333.5634, 197.0709, 45.2288, 25.709);
              Rectangle2D rectanguloConsumo = new Rectangle2D.Double(378.7922, 197.0709, 48.0556, 25.709);
              Rectangle2D rectanguloCategoria = new Rectangle2D.Double(426.8478, 197.0709, 73.4968, 25.709);
              Rectangle2D rectanguloTitulos = new Rectangle2D.Double(8.4804, 222.7758, 548.3992, 8.5683 );          //Rectángulo donde irán los títulos de los conceptos
    
              //Rectángulo que al pintarse, genera dos espacios que son los que contienen los conceptos
              Rectangle2D rectanguloConceptos = new Rectangle2D.Double(8.4804, 197.0709, 268.546, 239.9124);
    
              //Rectángulo resumen, donde se muestra el vencimiento y el importe a pagar
              Rectangle2D rectanguloResumen = new Rectangle2D.Double(8.4804, 436.9833, 548.3992, 19.9997);
              Rectangle2D rectanguloResTotalimp = new Rectangle2D.Double(448.6631, 436.9833, 108.2664,19.9997);
    
              //Rectángulos donde figuran los vencimientos programados y el tipo de entrega
              Rectangle2D rectanguloRecargos1 = new Rectangle2D.Double(155.474, 456.983, 401.4056, 11.4244);
              Rectangle2D rectanguloRecargos2 = new Rectangle2D.Double(155.474, 468.4074, 401.4056, 9.9963);
              Rectangle2D rectanguloRecargos3 = new Rectangle2D.Double(155.474, 478.4037, 401.4056, 9.9963);
              //Rectángulos que contienen los vencimientos programados, tipo de entrega y el importe total
              Rectangle2D rectanguloRecRecargo = new Rectangle2D.Double(155.474, 456.983, 59.9781, 31.417);
              Rectangle2D rectanguloRecImporte = new Rectangle2D.Double(215.4521, 456.983, 60.7762, 31.417);
              Rectangle2D rectanguloRecNul = new Rectangle2D.Double(276.2283, 456.983, 59.3628, 31.417);
              Rectangle2D rectanguloRecNul1 = new Rectangle2D.Double(335.5911, 456.983, 56.536, 31.417);
              Rectangle2D rectanguloRecHasta = new Rectangle2D.Double(392.1271, 456.983, 56.536, 31.417);
    
              //Rectangulo de Mensaje
              Rectangle2D rectanguloMensaje = new Rectangle2D.Double(8.4804, 162.7977, 548.3992, 34.2732);
    
              //Sector intermedio de la factura
              Rectangle2D rectanguloIntermedio = new Rectangle2D.Double(8.4804, 513.0642, 548.3992, 157.0855);
              Rectangle2D rectanguloIntIzquierda = new Rectangle2D.Double(8.4804, 513.0642, 175.2616, 113.072);
              Rectangle2D rectanguloIntDerecha = new Rectangle2D.Double(359.0036, 513.0642, 197.876, 157.0855);
              Rectangle2D rectanguloIntIzqTitulo = new Rectangle2D.Double(8.4804, 513.0642, 175.2616, 15.70855);
              Rectangle2D rectanguloIntIzqTitulo1 = new Rectangle2D.Double(8.4804, 528.77285, 175.2616, 7.14025);
              Rectangle2D rectanguloIntDerTitulo = new Rectangle2D.Double(359.0036, 513.0642, 197.876, 8.5683);
              Rectangle2D rectanguloIntDerTitulo1 = new Rectangle2D.Double(359.0036, 521.6325, 197.876, 8.5683);
              Rectangle2D rectanguloIntDerecha1 = new Rectangle2D.Double(359.0036, 591.60595, 197.876, 78.54375);
              Rectangle2D rectanguloIntDerTitulo2 = new Rectangle2D.Double(359.0036, 591.60595, 197.876, 8.5683);
              Rectangle2D rectanguloIntDerTitulo3 = new Rectangle2D.Double(359.0036, 600.17425, 197.876, 8.5683);
    
              //Talón izquierdo de la Factura
              Rectangle2D rectanguloTalonIzquierdo = new Rectangle2D.Double(8.4804, 676.8957, 344.8696, 134.2367);
              Rectangle2D rectanguloTalonIzqSup     = new Rectangle2D.Double(8.4804, 676.8957, 344.8696, 37.1293);
              Rectangle2D rectanguloTalonIzqVenc = new Rectangle2D.Double( 14.136, 751.1543, 158.3008, 37.1293);
              Rectangle2D rectanguloTalonIzqVenc1 = new Rectangle2D.Double(14.136, 751.1543, 84.804, 37.1293);
              Rectangle2D rectanguloTalonIzqCheq = new Rectangle2D.Double( 178.0884, 742.586, 172.4348, 45.6976);
              Rectangle2D rectanguloTalonIzqCheq1 = new Rectangle2D.Double(178.0884, 742.586, 172.4348, 11.4244);
              Rectangle2D rectanguloTalonIzqCheq2 = new Rectangle2D.Double(178.0884, 742.586, 172.4348, 22.8488);
              Rectangle2D rectanguloTalonIzqCheq3 = new Rectangle2D.Double(178.0884, 742.586, 172.4348, 34.2732);
    
              //Talón derecho de la factura
              Rectangle2D rectanguloTalonDerecho = new Rectangle2D.Double(359.0036, 676.8957, 197.876, 134.2367);
              Rectangle2D rectanguloTalonDerSup     = new Rectangle2D.Double(359.0036, 676.8957, 197.876, 37.1293);
              Rectangle2D rectanguloTalonDerVenc = new Rectangle2D.Double(359.0036, 714.025, 158.3008, 37.1293);
              Rectangle2D rectanguloTalonDerVenc1 = new Rectangle2D.Double(359.0036, 714.025, 88.804, 37.1293);
    
              g2.setColor(Color.black);   // Page 1 : print a rectangle
              g2.setStroke( new BasicStroke(0.5f));
              g2.draw(rectangulo);
              g2.draw(rectanguloIzquierda);
              g2.draw(rectanguloCentro);
              g2.draw(rectanguloDerecha);
              //g2.drawString( "Valor Inicial del eje X:" + valorInicialX, 100, 200 );
              //g2.drawString( "Valor Inicial del eje Y:" + valorInicialY, 100, 220 );
              //g2.drawString( "Máximo ancho de Impresión:" + maximoAncho, 100, 240 );
              //g2.drawString( "Máxima Altura de Impresión:" + maximaAltura, 100, 260 );
              g2.draw(rectangulo1);
              g2.draw(rectanguloDatos);
              g2.draw(rectanguloFecha);
              g2.draw(rectanguloRuta);
              g2.draw(rectanguloAsociado);
              g2.draw(rectanguloPeriodo);
              g2.draw(rectanguloFecha1);
              g2.draw(rectanguloRuta1);
              g2.draw(rectanguloAsociado1);
              g2.draw(rectanguloPeriodo1);
              g2.draw(rectanguloMensaje);
    
              //Acá imprimimos los rectángulos de Servicio, Número de Medidor, Días de Lectura, Lectura Actual, etc.
              g2.draw(rectanguloServicio);
              g2.draw(rectanguloServicio1);
              g2.draw(rectanguloServ);
              g2.draw(rectanguloMedidor);
              g2.draw(rectanguloPeriodoLeido);
              g2.draw(rectanguloDias);
              g2.draw(rectanguloLecturaActual);
              g2.draw(rectanguloLecturaAnterior);
              g2.draw(rectanguloMultiplicador);
              g2.draw(rectanguloConsumo);
              g2.draw(rectanguloCategoria);
              //Ahora imprimimos los títulos que van en cada uno de los recuadros
              g2.setFont(new Font("Arial", Font.BOLD, 6));
              g2.drawString("SERV.", 12.134f, 204f);
              g2.drawString("NRO. MEDIDOR", 42.402f, 204f);
              g2.drawString("PERÍODO LEÍDO", 121.5524f, 204f);
              g2.drawString("DÍAS", 200.7028f, 204f);
              g2.drawString("LECT. ACTUAL", 228.9708f, 204f);
              g2.drawString("LECT. ANTERIOR", 279.8532f, 204f);
              g2.drawString("LECT. X", 344.8696f, 204f);
              g2.drawString("CONSUMO", 387.2716f, 204f);
              g2.drawString("CATEGORÍA", 445.221f, 204f);
              g2.drawString("IMP. CONSUMO", 505.9972f, 204f);
    
              g2.draw(rectanguloTitulos);
    
              g2.draw(rectanguloConceptos);
              g2.draw(rectanguloResumen);
              Color colorAnterior = g2.getBackground();
              //g2.setBackground(Color.lightGray);
              g2.draw(rectanguloResTotalimp);
              //g2.fill(rectanguloResTotalimp);
              g2.setBackground(colorAnterior);
    
              g2.draw(rectanguloRecargos1);
              g2.draw(rectanguloRecargos2);
              g2.draw(rectanguloRecargos3);
              g2.draw(rectanguloRecRecargo);
              g2.draw(rectanguloRecImporte);
              g2.draw(rectanguloRecNul);
              g2.draw(rectanguloRecNul1);
              g2.draw(rectanguloRecHasta);
    
              g2.setFont(new Font("Arial", Font.PLAIN, 8));
              g2.drawString("FECHA FACTURA", 10, 143 );
              g2.drawString("RUTA-CUENTA", 90, 143 );
              g2.drawString("ASOCIADO", 168, 143 );
              g2.drawString("PERÍODO", 233,143 );
              g2.setFont(new Font("Arial", Font.PLAIN, 7));
              g2.drawString("Usted tiene derecho a reclamar una indemnización si le facturamos sumas o conceptos indebidos o reclamos de pago de facturas ya abonadas, según Ley 24.240", 10, 170);
              g2.drawString("La presente factura es la notificación previa a los fines de producir el corte de suministro por falta de pago en término (Artículo 55 del Reglamento de Suministro)", 10, 177);
              g2.drawString("Dicho corte de suministro se activará 48 horas después del Primer Vencimiento de la Segunda factura impaga", 10, 184);
              g2.setFont(new Font("Arial", Font.BOLD, 10));
              g2.drawString("EVITE RECARGOS Y SUSPENSIONES. ABONE EN TÉRMINO", 150, 195);
    
              //Creamos el intermedio de la factura
              g2.draw(rectanguloIntermedio);
              g2.draw(rectanguloIntIzquierda);
              g2.draw(rectanguloIntDerecha);
              g2.draw(rectanguloIntIzqTitulo);
              g2.draw(rectanguloIntIzqTitulo1);
              g2.setFont(new Font("Arial", Font.BOLD, 8));
              g2.drawString("DETALLE DE COMPROBANTES PENDIENTES", 8.5004f, 523.875325f);
              g2.setFont(new Font("Arial", Font.PLAIN, 6));
              g2.drawString("FACTURA", 14.134f, 534.96875f);
              g2.drawString("VENCIMIENTO", 67.8432f, 534.96875f);
              g2.drawString("IMPORTE ORIGINAL", 124.3792f, 534.96875f);
    
              g2.draw(rectanguloIntDerTitulo);
              g2.draw(rectanguloIntDerTitulo1);
              g2.draw(rectanguloIntDerecha1);
              g2.draw(rectanguloIntDerTitulo2);
              g2.draw(rectanguloIntDerTitulo3);
    
              g2.setFont(new Font("Arial", Font.BOLD, 7));
              g2.drawString("RESUMEN POR SERVICIO", 412.7128f, 519.8102f);
              g2.drawString("ESTADÍSTICA DE SUS CONSUMOS DE ENERGÍA", 375.9644f, 598.35295f);
    
              g2.drawString("E", 361.8304f, 536.398537f);
              g2.drawString("A", 361.8304f, 546.880424f);
              g2.drawString("S", 361.8304f, 557.362311f);
              g2.drawString("I", 361.8304f, 567.844208f);
              g2.drawString("G", 361.8304f, 578.326085f);
              g2.drawString("O", 361.8304f, 588.807972f);
    
              g2.setFont(new Font("Arial", Font.PLAIN, 7));
              g2.drawString("(Energía)", 367.484f, 536.398537f);
              g2.drawString("(Agua", 367.484f, 546.880424f);
              g2.drawString("(Serv. Soc.)", 367.484f, 557.362311f);
              g2.drawString("(Internet)", 367.484f, 567.844208f);
              g2.drawString("(Gas)", 367.484f, 578.326085f);
              g2.drawString("(Otros)", 367.484f, 588.807972f);
    
              g2.setFont(new Font("Arial", Font.PLAIN, 7));
              g2.drawString("Servicio", 367.484f, 528.3785f);
              g2.drawString("Neto", 432.5004f, 528.3785f);
              g2.drawString("I.V.A. - Otros", 457.9416f, 528.3785f);
              g2.drawString("TOTAL", 520.1312f, 528.3785f);
    
              String codBarrasNacion = calculaBarrasNacion(rsCabeceras);
              g2.setFont(new Font("IDAutomationSC128M", Font.PLAIN, 10));
              g2.drawString(codBarrasNacion, 11.3072f, 654.0469f);
    
              //Creamos el talón izquierdo de la factura
              g2.draw(rectanguloTalonIzquierdo);
              g2.draw(rectanguloTalonIzqSup);
              g2.draw(rectanguloTalonIzqVenc);
              g2.draw(rectanguloTalonIzqVenc1);
              g2.draw(rectanguloTalonIzqCheq);
              g2.draw(rectanguloTalonIzqCheq1);
              g2.draw(rectanguloTalonIzqCheq2);
              g2.draw(rectanguloTalonIzqCheq3);
              g2.setFont(new Font("Arial", Font.PLAIN, 7));
              try{
                   g2.drawString("RUTA-CUENTA: " + rsCabeceras.getString(17), 11.3072f, 685.464f);
                   g2.drawString("SOCIO: " + rsCabeceras.getString(16), 141.34f, 685.464f);
                   g2.drawString( rsCabeceras.getString(8), 203.5692f, 685.464f);
                   g2.drawString("FACTURA - LIQUIDACIÓN: ", 11.3072f, 699.7445f);
                   g2.drawString(rsCabeceras.getString(6), 113.072f, 699.7445f);
                   g2.drawString(formatoSuc4Digitos.format(rsCabeceras.getInt(3)) + " - " + formatoNroCbte.format(rsCabeceras.getInt(7)), 124.3792f, 699.7445f);
                   g2.drawString("PERÍODO:" +  rsCabeceras.getString(18), 11.3072f, 711.1689f);
                   g2.drawString("FECHA: " + rsCabeceras.getString(19), 141.34f, 711.1689f);
    
                   String codigoBarras = rsCabeceras.getInt(2) + formatoSuc3Digitos.format(rsCabeceras.getInt(3)) + rsCabeceras.getString(4) + rsCabeceras.getString(5) + rsCabeceras.getString(6) + formatoNroCbte.format(rsCabeceras.getInt(7));
                   g2.setFont(new Font("3 of 9 Barcode", Font.PLAIN, 20));
                   g2.drawString("*" + codigoBarras + "*", 14.134f, 748.2982f);
    
                   g2.setFont(new Font("Arial", Font.BOLD, 7));
                   g2.drawString("Hasta el:" + rsCabeceras.getString(21), 19.7876f, 759.7226f);
                   g2.drawString("Hasta el:" + rsCabeceras.getString(23), 19.7876f, 772.57505f);
                   g2.drawString("Hasta el:" + rsCabeceras.getString(25), 19.7876f, 785.4275f);
                   float topeX = 163.9544f;
                   FontMetrics metricaFuente = g2.getFontMetrics();
                   g2.drawString(formatoMoneda.format(rsCabeceras.getDouble(22)), topeX - metricaFuente.stringWidth(formatoMoneda.format(rsCabeceras.getDouble(22))), 759.7226f);
                   g2.drawString(formatoMoneda.format(rsCabeceras.getDouble(24)), topeX - metricaFuente.stringWidth(formatoMoneda.format(rsCabeceras.getDouble(24))), 772.57505f);
                   g2.drawString(formatoMoneda.format(rsCabeceras.getDouble(26)), topeX - metricaFuente.stringWidth(formatoMoneda.format(rsCabeceras.getDouble(26))), 785.4275f);
    
                   g2.setFont(new Font("Arial", Font.PLAIN, 5));
                   g2.drawString("Cheque Número", 195.0492f, 749.1543f);
                   g2.drawString("Nombre del Banco", 274.1996f, 749.1543f);
                   g2.drawString("SI LA PRESENTE FACTURA ES ABONADA CON CHEQUE/S, SERÁ CANCELADA UNA VEZ EFECTIVIZADO/S EL/LOS VALOR/ES DE REFERENCIA", 10.00f, 796.8519f);
    
                   g2.setFont(new Font("Arial", Font.BOLD, 7));
                   g2.drawString( "TALON PARA LA COOPERATIVA", 28.268f, 805.2763f);
                   g2.drawString( "SELLAR AL DORSO", 220.4904f, 805.2763f);
    
                   //Creamos el talón derecho de la factura
                   g2.setFont(new Font("Arial", Font.PLAIN, 7));
                   g2.draw(rectanguloTalonDerecho);
                   g2.draw(rectanguloTalonDerSup);
                   try{
                        g2.drawString("RUTA-CUENTA: " + rsCabeceras.getString(17), 361.8304f, 685.464f);
                        g2.drawString("SOCIO: " + rsCabeceras.getString(16), 494.69f, 685.464f);
                        g2.drawString( rsCabeceras.getString(8), 203.5692f, 685.464f);
                        g2.drawString("FACTURA - LIQUIDACIÓN: ", 361.8304f, 699.7445f);
                        g2.drawString(rsCabeceras.getString(6), 463.5952f, 699.7445f);
                        g2.drawString(formatoSuc4Digitos.format(rsCabeceras.getInt(3)) + " - " + formatoNroCbte.format(rsCabeceras.getInt(7)), 474.9024f, 699.7445f);
                        g2.drawString("PERÍODO:" +  rsCabeceras.getString(18), 361.8304f, 711.1689f);
                        g2.drawString("FECHA: " + rsCabeceras.getString(19), 491.8632f, 711.1689f);
    
                        g2.draw(rectanguloTalonDerVenc);
                        g2.draw(rectanguloTalonDerVenc1);
    
                        float topeX1 = 551.226f;
                        FontMetrics largoFuente = g2.getFontMetrics();
                        g2.drawString(rsCabeceras.getString(1), topeX1 - largoFuente.stringWidth(rsCabeceras.getString(1)), 771.147f);
    
                        g2.setFont(new Font("Arial", Font.BOLD, 7));
                        g2.drawString("Hasta el: " + rsCabeceras.getString(21), 364.6572f, 722.5933f);
                        g2.drawString("Hasta el: " + rsCabeceras.getString(23), 364.6572f, 734.0177f);
                        g2.drawString("Hasta el: " + rsCabeceras.getString(25), 364.6572f, 745.4421f);
    
                        float topeX2 = 511.3044f;
                        FontMetrics largoFuente1 = g2.getFontMetrics();
                        g2.drawString(formatoMoneda.format(rsCabeceras.getDouble(22)), topeX2 - largoFuente1.stringWidth(rsCabeceras.getString(22)), 722.5933f);
                        g2.drawString(formatoMoneda.format(rsCabeceras.getDouble(24)), topeX2 - largoFuente1.stringWidth(rsCabeceras.getString(24)), 734.0177f);
                        g2.drawString(formatoMoneda.format(rsCabeceras.getDouble(26)), topeX2 - largoFuente1.stringWidth(rsCabeceras.getString(26)), 745.4421f);
    
                        g2.setFont(new Font("Arial", Font.BOLD, 7));
                        g2.drawString("TALÓN PARA EL BANCO", 409.886f, 805.2763f);
    
                        //(359.0036, 714.025, 88.804, 37.1293)
                        //011.15.5009.5267
    
                   }
                   catch(SQLException sqle){
                     JOptionPane.showMessageDialog(null, "Error al imprimir los datos de la cabecera", "Atención", JOptionPane.INFORMATION_MESSAGE);
                   }
    
    
              }
              catch(SQLException sqle){
                   JOptionPane.showMessageDialog(null, "Error al imprimir los datos de la cabecera", "Atención", JOptionPane.INFORMATION_MESSAGE);
              }
    
    
              JOptionPane.showMessageDialog(null, "Valor de pageIndex: " + pageIndex + "\nValor de paginaActual: " + paginaActual, "Atención", JOptionPane.INFORMATION_MESSAGE);
              //while(pageIndex <= saltosDePagina){
    
                   inicializarVariablesConceptos();
    
                   paginaActual = pageIndex;
                   JOptionPane.showMessageDialog(null, "Valor de Puntero: " + puntero, "Atención", JOptionPane.INFORMATION_MESSAGE);
                   //JOptionPane.showMessageDialog(null, "Valor de pageIndex: " + pageIndex + "\nValor de paginaActual: " + paginaActual, "Atención", JOptionPane.INFORMATION_MESSAGE);
                   imprimirCabecera();
    
                   try{
                        imprimirConsumos(rsCabeceras.getInt(15));
                   }
                   catch(SQLException sqle){
                        JOptionPane.showMessageDialog(null, "Error al imprimir los consumos", "Método: print()", JOptionPane.INFORMATION_MESSAGE);
                   }
    
                   try{
                        rsConceptos.last();
                        rsConceptos.beforeFirst();
                        rsConceptos.absolute(puntero1);
                        while(!todosImpresos){
    
                             puntero1 = rsConceptos.getRow();
                             imprimirConceptos(rsConceptos, puntero1);
    
                             puntero1 = rsConceptos.getRow();
    
                             if(rsConceptos.getInt(6) == 1){
                                  renglones++;
                             }
    
                             if(renglones > 20){
                                  renglones = 0;
                                  inicializarVariablesConceptos();
                                  return Printable.PAGE_EXISTS;
                             }
    
                             rsConceptos.next();
    
                             if(rsConceptos.isAfterLast()){
                             //     JOptionPane.showMessageDialog(null, "Se pasó el final del ResultSet", "Método: print()", JOptionPane.INFORMATION_MESSAGE);
                                  //todosImpresos = true;
                                  return Printable.PAGE_EXISTS;
    
                             }
    
                        }
    
                        //return NO_SUCH_PAGE;
                        //if(rsConceptos.isAfterLast()){
                        //     JOptionPane.showMessageDialog(null, "Se pasó el final del ResultSet", "Método: print()", JOptionPane.INFORMATION_MESSAGE);
                        //     todosImpresos = true;
                        //     return Printable.PAGE_EXISTS;
                        //}
                   }
                   catch(SQLException sqle){
                        JOptionPane.showMessageDialog(null, "Error al imprimir los conceptos de la factura", "Método: print()", JOptionPane.INFORMATION_MESSAGE);
                   }
    
              //}
    
              return Printable.NO_SUCH_PAGE;
    
         }
    the code for print the items:
         public void imprimirConceptos(ResultSet rsConceptos, int puntero1){
    
              //float puntoXConcepto = 28.268f;
              //float puntoXDescripcion = 33.9216f;
              //float puntoXImporte = 274.1996f;
              //float puntoXConsumo = 127.206f;
              //float puntoXImporteConsumo = 169.608f;
              //float puntoY = 240.0563f;
              //float puntoXConcepto1 = 296.814f;
              //float puntoXDescripcion1 = 302.4676f;
              //float puntoXImporte1 = 551.226f;
              //float puntoY1 = 240.0563f;
              //float dY = 8f;
              //boolean lado1;
              //int largoCadena = 0;
              largoCadena = 0;
    
              //renglones = 1;
    
              //if(paginaActual == 0){
              //     saltosDePagina = 0;
              //}
              int puntero2 = 0;
              puntero2 = puntero1;
              //puntero1 = puntero;
    
              Double netoEnergia = 0.00, ivaEnergia = 0.00, totalEnergia = 0.00;
              Double netoAgua = 0.00, ivaAgua = 0.00, totalAgua = 0.00;
              Double netoSociales = 0.00, ivaSociales = 0.00, totalSociales = 0.00;
              Double netoInternet = 0.00, ivaInternet = 0.00, totalInternet = 0.00;
              Double netoGas = 0.00, ivaGas = 0.00, totalGas = 0.00;
              Double netoOtros = 0.00, ivaOtros = 0.00, totalOtros = 0.00;
    
              g2.setFont(new Font("Arial", Font.PLAIN, 7));
              FontMetrics tamanioFuente = g2.getFontMetrics();
    
              try{
                   //rsConceptos.last();
                   //rsConceptos.beforeFirst();
                   //rsConceptos.absolute(puntero2);
                   JOptionPane.showMessageDialog(null, "Valor de Puntero al entrar:" + puntero2 + "\nRegistro en proceso: " + rsConceptos.getRow(), "Método: imprimiConceptos()", JOptionPane.INFORMATION_MESSAGE);
                   //while(rsConceptos.isAfterLast() != true){
    
                        if(rsConceptos.getInt(6) == 1){
                             largoCadena = tamanioFuente.stringWidth(formatoConcepto.format(rsConceptos.getInt(1)));
                             g2.drawString(formatoConcepto.format(rsConceptos.getInt(1)).toString(), puntoXConcepto - largoCadena, puntoY);
                             g2.drawString(rsConceptos.getString(3), puntoXDescripcion, puntoY);
                             largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(rsConceptos.getDouble(5)));
                             g2.drawString(formatoMoneda.format(rsConceptos.getDouble(5)), puntoXImporte - largoCadena, puntoY);
                             if(rsConceptos.getInt(1) == 5 || rsConceptos.getInt(1) == 10 || rsConceptos.getInt(1) == 30 || rsConceptos.getInt(1) == 31 || rsConceptos.getInt(1) == 32 || rsConceptos.getInt(1) == 43 || rsConceptos.getInt(1) == 60){
                                  largoCadena = tamanioFuente.stringWidth(formatoConsumo.format(rsConceptos.getDouble(4)));
                                  g2.drawString(formatoConsumo.format(rsConceptos.getDouble(4)), puntoXConsumo - largoCadena, puntoY);
                                  largoCadena = tamanioFuente.stringWidth(formatoImporte.format(rsConceptos.getDouble(7)));
                                  g2.drawString(formatoImporte.format(rsConceptos.getDouble(7)), puntoXImporteConsumo - largoCadena, puntoY);
                             }
                             puntoY += dY;
                             lado1 = true;
                             //renglones ++;
                             JOptionPane.showMessageDialog(null, "Procesando Renglones del lado 1, número de renglón: " + rsConceptos.getRow(), "Método: imprimiConceptos()", JOptionPane.INFORMATION_MESSAGE);
                        }
                        else{
                             largoCadena = tamanioFuente.stringWidth(formatoConcepto.format(rsConceptos.getInt(1)));
                             g2.drawString(formatoConcepto.format(rsConceptos.getInt(1)), puntoXConcepto1 - largoCadena, puntoY1);
                             g2.drawString(rsConceptos.getString(3), puntoXDescripcion1, puntoY1);
                             largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(rsConceptos.getDouble(5)));
                             g2.drawString(formatoMoneda.format(rsConceptos.getDouble(5)), puntoXImporte1 - largoCadena, puntoY1);
                             puntoY1 += dY;
                             lado1 = false;
                        }
    
                        switch(rsConceptos.getInt(8)){
                             case 1:
                                  if(rsConceptos.getDouble(6) == 1){
                                       netoEnergia += rsConceptos.getDouble(5);
                                  }
                                  else{
                                       ivaEnergia += rsConceptos.getDouble(5);
                                  }
                                  totalEnergia += rsConceptos.getDouble(5);
                                  break;
                             case 2:
                                  if(rsConceptos.getDouble(6) == 1){
                                       netoAgua += rsConceptos.getDouble(5);
                                  }
                                  else{
                                       ivaAgua += rsConceptos.getDouble(5);
                                  }
                                  totalAgua += rsConceptos.getDouble(5);
                                  break;
                             case 3:
                                  if(rsConceptos.getDouble(6) == 1){
                                       netoSociales += rsConceptos.getDouble(5);
                                  }
                                  else{
                                       ivaSociales += rsConceptos.getDouble(5);
                                  }
                                  totalSociales += rsConceptos.getDouble(5);
                                  break;
                             case 4:
                                  if(rsConceptos.getDouble(6) == 1){
                                       netoInternet += rsConceptos.getDouble(5);
                                  }
                                  else{
                                       ivaInternet += rsConceptos.getDouble(5);
                                  }
                                  totalInternet += rsConceptos.getDouble(5);
                                  break;
                             case 5:
                                  if(rsConceptos.getDouble(6) == 1){
                                       netoGas += rsConceptos.getDouble(5);
                                  }
                                  else{
                                       ivaGas += rsConceptos.getDouble(5);
                                  }
                                  totalGas += rsConceptos.getDouble(5);
                                  break;
                             default:
                                  if(rsConceptos.getDouble(6) == 1){
                                       netoOtros += rsConceptos.getDouble(5);
                                  }
                                  else{
                                       ivaOtros += rsConceptos.getDouble(5);
                                  }
                                  totalOtros += rsConceptos.getDouble(5);
                        }
    
                        //if(renglones > 10){
                        //     puntero = rsConceptos.getRow();
                        //     puntero1 = puntero;
                        //     JOptionPane.showMessageDialog(null, "Valor de Puntero al Corte: " + puntero + "\nRegistro en proceso: " + rsConceptos.getRow() + "\nValor de Puntero1: " + puntero1, "Método: imprimirConceptos()", JOptionPane.INFORMATION_MESSAGE);
                        //     return;
                        //}
                        System.out.println("Registro: " + rsConceptos.getRow());
                        //rsConceptos.next();
                        JOptionPane.showMessageDialog(null,"Pasó un registro: " + rsConceptos.getRow(), "Método: imprimirConceptos()", JOptionPane.INFORMATION_MESSAGE);
                   //}
    
                   /**
                   float puntoXNeto = 449.4612f;
                   float puntoXIva = 494.69f;
                   float puntoXTotal = 554.0528f;
    
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(netoEnergia));
                   g2.drawString(formatoMoneda.format(netoEnergia), puntoXNeto - largoCadena, 536.398537f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(ivaEnergia));
                   g2.drawString(formatoMoneda.format(ivaEnergia), puntoXIva - largoCadena, 536.398537f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(totalEnergia));
                   g2.drawString(formatoMoneda.format(totalEnergia), puntoXTotal -largoCadena, 536.398537f);
    
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(netoAgua));
                   g2.drawString(formatoMoneda.format(netoAgua), puntoXNeto - largoCadena, 546.880424f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(ivaAgua));
                   g2.drawString(formatoMoneda.format(ivaAgua), puntoXIva - largoCadena, 546.880424f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(totalAgua));
                   g2.drawString(formatoMoneda.format(totalAgua), puntoXTotal -largoCadena, 546.880424f);
    
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(netoSociales));
                   g2.drawString(formatoMoneda.format(netoSociales), puntoXNeto - largoCadena, 557.362311f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(ivaSociales));
                   g2.drawString(formatoMoneda.format(ivaSociales), puntoXIva - largoCadena, 557.362311f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(totalSociales));
                   g2.drawString(formatoMoneda.format(totalSociales), puntoXTotal -largoCadena, 557.362311f);
    
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(netoInternet));
                   g2.drawString(formatoMoneda.format(netoInternet), puntoXNeto - largoCadena, 567.844208f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(ivaInternet));
                   g2.drawString(formatoMoneda.format(ivaInternet), puntoXIva - largoCadena, 567.844208f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(totalInternet));
                   g2.drawString(formatoMoneda.format(totalInternet), puntoXTotal -largoCadena, 567.844208f);
    
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(netoGas));
                   g2.drawString(formatoMoneda.format(netoGas), puntoXNeto - largoCadena, 578.326085f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(ivaGas));
                   g2.drawString(formatoMoneda.format(ivaGas), puntoXIva - largoCadena, 578.326085f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(totalGas));
                   g2.drawString(formatoMoneda.format(totalGas), puntoXTotal -largoCadena, 578.326085f);
    
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(netoOtros));
                   g2.drawString(formatoMoneda.format(netoOtros), puntoXNeto - largoCadena, 588.807972f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(ivaOtros));
                   g2.drawString(formatoMoneda.format(ivaOtros), puntoXIva - largoCadena, 588.807972f);
                   largoCadena = tamanioFuente.stringWidth(formatoMoneda.format(totalOtros));
                   g2.drawString(formatoMoneda.format(totalOtros), puntoXTotal -largoCadena, 588.807972f);
    
                   //rsConceptos.close();
                   //return;
                   */
              }
              catch(SQLException sqle){
                   JOptionPane.showMessageDialog(null, "Ha ocurrido un error al imprimir los conceptos", "Método: imprimirConceptos()", JOptionPane.INFORMATION_MESSAGE);
              }
    
         }
    Edited by: user5294656 on 25/08/2011 20:27
  • 3. Re: Trouble with Printable Interface
    EJP Guru
    Currently Being Moderated
    rsConceptos.last();
    rsConceptos.beforeFirst();
    rsConceptos.absolute(puntero1);
    while(!todosImpresos){
    puntero1 = rsConceptos.getRow();
    imprimirConceptos(rsConceptos, puntero1);
    puntero1 = rsConceptos.getRow();
    ...
    What's all that for? You don't need all that. You're probably failing to process the ResultSet at all with all that mucking around. And is 'todosImpresos' ever false?
    while (rsConceptos.next())
    {
      imprimirConceptos(rsConceptos, rsConceptos.getRow());
      if(rsConceptos.getInt(6) == 1){
        renglones++;
      }
      if(renglones > 20){
        renglones = 0;
        inicializarVariablesConceptos();
        return Printable.PAGE_EXISTS;
      }
    }
    return Printable.PAGE_EXISTS;
  • 4. Re: Trouble with Printable Interface
    857053 Newbie
    Currently Being Moderated
    Hi EJP, first of all, I apologize for the delay in answering your message, but I was traveling.
    I tried the code you sent me, but I only print the first two items of the ResultSet, and I know that in this case are 32 items.
    The truth is I do not understand why it works this way.
    I modified the code so that at one point doing the same, but the last two items.
    Is there any other way to put it less work?
    Thank you very much for answering.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points