Last active
November 16, 2022 20:04
-
-
Save vacax/98f4ab2432b1f30e9d426752c037fed6 to your computer and use it in GitHub Desktop.
Convertir JasperReports a Base64 PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String convertirJasperaBase64(String conduce){ | |
String pdfBase64 = "" | |
//Obteniendo la conexion. | |
Sql con = Sql.newInstance("jdbc:sqlserver://xxxxxxxx;databaseName=xxxxxxx", "xxxxxxx", "xxxxxxx") | |
//Parametros. | |
HashMap<String, Object> parametros=new HashMap<>(); | |
parametros.put("conduce", conduce) | |
parametros.put("logo", this.getClass().getResourceAsStream("/reportes/logo_stonewood.jpg")) | |
//Cargando el reporte desde el Jar del proyecto. Reporte compilado. | |
JasperReport reporte = (JasperReport) JRLoader.loadObject(this.getClass().getResource("/reportes/DocumentoRetorno.jasper")); | |
//Mandando a ejecutar el proyecto. | |
JasperPrint print = JasperFillManager.fillReport(reporte, parametros ,con.connection); | |
byte[] pdf = JasperExportManager.exportReportToPdf(print) | |
pdfBase64 = Base64.encoder.encodeToString(pdf) | |
/*//creando el archivo | |
def archivo = File.createTempFile("reporte_",".pdf") | |
archivo.bytes = pdf*/ | |
return pdfBase64 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment