jueves, 14 de abril de 2011

Breve apunte de programación con Java. Impresión con JasperReports a doble cara

Otro breve apunte de programación con Java. Hoy trataremos el tema de imprimir a doble cara usando JasperReports.

Para imprimir algo a doble cara, la forma más sencilla es decirle al driver de impresora que se ponga en modo duplex e imprimir normalmente (el driver se encarga de hacer la impresión a doble cara).

El problema está en que si estamos imprimiendo continuamente cosas a doble cara y cosas que no van a doble cara, que sea el usuario quien cambie las funciones de impresión en cada impresión no es lo más recomendable, por lo que la opción más adecuada es que sea el programa el que indique al driver que vamos a imprimir en duplex, imprimamos como lo haríamos normalmente y sea el driver quien se encargue del duplex y al finalizar el informe deje el tema duplex como antes del mismo.

Con un ejemplo se verá más claro:

jreport = JasperCompileManager.compileReport(new FileInputStream("miReport.jrxml"));

Map parametros = new HashMap(); parametros.put("misql", "select * from clientes order by razon_social"); JasperPrint print = JasperFillManager.fillReport(jreport, parametros, conn);

JRExporter exporter = new JRPrintServiceExporter(); 

exporter.setParameter(JRExporterParameter.JASPER_PRINT, print); 

PrintRequestAttributeSet attrSet = new HashPrintRequestAttributeSet(); attrSet.add(Sides.DUPLEX); 

exporter.setParameter( JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, attrSet);


En el ejemplo anterior observamos varias cosas: El report recibe un parámetro (que debemos haber indicado en la creación del mismo) llamado misql, el cuál contiene la SQL que recupera los datos del report.

Una vez tenemos el objeto JasperPrint podemos imprimirlo normalmente o bien crear un objeto JRExporter para aplicarle ciertos parámetros de impresión (en este caso, la impresión DUPLEX).

Finalmente con exporter.exportReport() lo que hacemos es imprimir con los parámetros fijados en exporter.

4 comentarios:

  1. The finest bonuses will offer large payouts on minimal deposits. w88 login No deposit bonus and more than 4.000 games for your entertainment. Nothing beats the excitement of online on line casino slot machines and the countless options it consists of.

  2. With video poker’s increasing recognition, the world’s high on-line casinos are continuously releasing new and exciting video games to the market. We are always on the hunt for the video 메리트카지노 games offering gamers the best game and return on their bet, and these are 5 of our favorites for November 2022. Try your luck on considered one of our greater than 1,100 slot, video poker and multi-game machines with denominations starting from $0.01 to $100. For Slot gamers, Luxor has lots of of choices from which to decide on}. From conventional "reel" slot machines to the latest video reel machines to hit the market. Players may go after single machine progressives, or try for the massive bucks on considered one of our machines with a multi-million dollar high award.

  3. Each is unique, with completely different themes, codecs, bonuses and even sound effects. The finest on-line on line casino sites ship hundreds, even thousands, of different titles. 토토사이트 With some four,000+ games, Betmaster outperforms lots of its rivals on this space. Launched back in 2007, 1XBet has long delivered one of the best on-line on line casino sites round.

  4. We work with all manufacturing and equipment industries and strive to meet your supply, high quality, and value objectives. ASAP is the corporate you can to|you possibly can} depend on to get Fingerprint Deadbolt Door Locks your job accomplished with quick, reliable lead occasions and reliable high quality. We’ve supplied services for an extensive range of clients including company businesses, commercial operators, public or non-public institutions, and extra. Whether it's commercial, Industrial, or residential we'll make customized metallic fabrication for anybody.