Realizar PDF SPLIT desde JAVA Usando JASPERREPORTS
Hoy he decidió compartir con toda la comunidad un método de java que a partir de una factura general de 50 hojas las divide cada una en 50 archivos por separado.
Bueno en qué consiste primero compilamos el reporte;
dataSourceName:nombre del archivo JRXML
tenemos que hacer un reporte en blanco y pasarle una consulta que traiga así sea un registro:
bueno aquí tienen el método si alguna duda me preguntan y con gusto les contesto
public boolean jasperReport2(String ruta, InputStream dataSourceName,InputStream reporteBlanco,LinkedListlistaObjetos, Map params,Connection conn) throws ClassNotFoundException, JRException, Exception {
this.reporte=JasperCompileManager.compileReport(dataSourceName);
// JasperReport
rep=JasperCompileManager.compileReport(Principal.class.getResourceAsStream("/reporte/blank.jrxml"));
JasperReport rep=JasperCompileManager.compileReport(reporteBlanco);
this.print = JasperFillManager.fillReport(this.reporte, params, conn);
jasperPrintAux=JasperFillManager.fillReport( rep, null,conn);
if(this.print.getPages().isEmpty()){
return false;
}
LinkedList lista= listaObjetos;
int cont=-1,cuenta=1;
while(cuenta>0){
cont++;
jasperPrintAux.getPages().clear();
jasperPrintAux.addPage(this.print.removePage(0));
int permisos =PdfWriter.ALLOW_PRINTING;
JRExporter jtrtf= new JRPdfExporter();
jtrtf.setParameter(JRPdfExporterParameter.IS_ENCRYPTED, Boolean.TRUE);
jtrtf.setParameter(JRPdfExporterParameter.IS_128_BIT_KEY, Boolean.TRUE);
jtrtf.setParameter(JRPdfExporterParameter.PERMISSIONS, permisos);
jtrtf.setParameter(JRExporterParameter.JASPER_PRINT, this.jasperPrintAux);
jtrtf.setParameter(JRExporterParameter.OUTPUT_FILE_NAME,ruta+"-No "+(cont+1)+"-"+lista.get(cont)+".pdf"); jtrtf.exportReport();
cuenta= this.print.getPages().size();
}
return true;
}
|
No hay comentarios:
Publicar un comentario