Avalados por :

Cómo exportar un informe de Crystal Report a PDF con Java sin servidor

  • Creado 01/03/2024
  • Modificado 01/03/2024
  • 1 Vistas
0
Cargando...

Pregunta: ¿Puedo exportar un informe de Crystal Report a PDF utilizando un programa independiente de Java (sin utilizar una aplicación web o un servidor)?

Requisito: Quiero exportar un informe de Crystal Report a un archivo PDF utilizando una aplicación independiente de Java. Puedo hacerlo utilizando SAP Crystal Report 2013 en mi escritorio. Para Java, he descargado la biblioteca crjava-runtime_12.2.220 y estoy utilizando el siguiente código.

        
            import com.crystaldecisions.reports.sdk.*;
            import com.crystaldecisions.sdk.occa.report.lib.*;
            import com.crystaldecisions.sdk.occa.report.exportoptions.*;
            //Importaciones de Java

            import java.io.*;
            public class JRCExportReport {
            static final String REPORT_NAME = "C:/abc.rpt";
            static final String EXPORT_FILE = "C:/abc.pdf";

            public static void main(String[] args) {
            try {
            //Abrir informe
            ReportClientDocument reportClientDoc = new ReportClientDocument();
            reportClientDoc.open(REPORT_NAME, ReportExportFormat._PDF);

            //NOTA: Si se requieren parámetros o credenciales de inicio de sesión de la base de datos, deben establecerse antes.
            //Llamando al método export de PrintOutputController.

            //Exportar informe y obtener un flujo de entrada que se puede escribir en el disco.
            //Consulte la Guía del desarrollador de componentes de informes de Java para obtener más información sobre las enumeraciones de formatos de exportación admitidos posibles con el JRC.
            ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) reportClientDoc.getPrintOutputController().export(ReportExportFormat.PDF);

            //Cerrar informe.
            reportClientDoc.close();

            //Usar las bibliotecas de E/S de Java para escribir el contenido exportado en el sistema de archivos.
            byte byteArray[] = new byte[byteArrayInputStream.available()];
            //Crear un nuevo archivo que contendrá el resultado exportado.
            File file = new File(EXPORT_FILE);
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(byteArrayInputStream.available());
            int x = byteArrayInputStream.read(byteArray, 0, byteArrayInputStream.available());
            byteArrayOutputStream.write(byteArray, 0, x);
            byteArrayOutputStream.writeTo(fileOutputStream);
            //Cerrar flujos.
            byteArrayInputStream.close();
            byteArrayOutputStream.close();
            fileOutputStream.close();

            System.out.println("Informe exportado correctamente a " + EXPORT_FILE);

            } catch (ReportSDKException ex) {

            ex.printStackTrace();

            } catch (Exception ex) {

            ex.printStackTrace();

            }
            }
            }
        
    
Obteniendo la siguiente excepción en la línea (reportClientDoc.open(REPORT_NAME, ReportExportFormat._PDF)): log4j: ADVERTENCIA No se pudieron encontrar apéndices para el registrador (com.crystaldecisions.reports.common.engine.config). log4j: ADVERTENCIA Por favor inicialice correctamente el sistema log4j. com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: Índice: 0, Tamaño: 0 ---- Código de error: -2147467259 Nombre del código de error: fallido en com.businessobjects.reports.sdk.JRCCommunicationAdapter.(SourceFile:285) en com.businessobjects.sdk.erom.jrc.a.(SourceFile:43) en com.businessobjects.sdk.erom.jrc.ReportAgentFactory.createAgent(SourceFile:46) en com.crystaldecisions.proxy.remoteagent.RemoteAgent$a.(SourceFile:703) en com.crystaldecisions.proxy.remoteagent.RemoteAgent.a(SourceFile:662) en com.crystaldecisions.proxy.remoteagent.RemoteAgent.a(SourceFile:632) en com.crystaldecisions.sdk.occa.report.application.ClientDocument.if(SourceFile:504) en com.crystaldecisions.sdk.occa.report.application.ClientDocument.open(SourceFile:669) en com.crystaldecisions.reports.sdk.ReportClientDocument.open(SourceFile:80) en JRCExportReport.main(JRCExportReport.java:33) Causado por: java.lang.IndexOutOfBoundsException: Índice: 0, Tamaño: 0 en java.util.ArrayList.rangeCheck(Unknown Source) en java.util.ArrayList.get(Unknown Source) en com.crystaldecisions12.reports.dataengine.h.h.if(SourceFile:2219) en com.crystaldecisions12.reports.dataengine.h.h.i(SourceFile:255) en com.crystaldecisions12.reports.dataengine.h.h.a(SourceFile:2065) en com.crystaldecisions12.reports.dataengine.h.h.try(SourceFile:1878) en com.crystaldecisions12.reports.reportdefinition.ReportDocument.a(SourceFile:2378) en com.crystaldecisions12.reports.reportdefinition.ReportDocument.a(SourceFile:1716) en com.crystaldecisions12.reports.common.Document.a(SourceFile:689) en com.crystaldecisions12.reports.common.Document.do(SourceFile:651) en com.crystaldecisions12.reports.reportdefinition.ReportDocument.a(SourceFile:2325) en com.crystaldecisions12.reports.reportdefinition.ReportDocument.a(SourceFile:1716) en com.crystaldecisions12.reports.common.Document.a(SourceFile:521) en com.crystaldecisions12.reports.common.Document.loadDocument(SourceFile:437) en com.crystaldecisions12.reports.reportdefinition.ReportDocument.loadDocument(SourceFile:1516) en com.crystaldecisions12.reports.reportdefinition.ReportDocument.LoadDocument(SourceFile:1479) en com.businessobjects.reports.reportconverter.v12.c.a(SourceFile:59) en com.businessobjects.reports.reportconverter.v12.V12SaveLoader.a(SourceFile:159) en com.businessobjects.reports.loader.ReportLoader.a(SourceFile:205) en com.businessobjects.reports.sdk.JRCReportLoader.a(SourceFile:137) en com.businessobjects.reports.sdk.JRCReportLoader.a(SourceFile:76) en com.businessobjects.reports.sdk.requesthandler.ReportDocumentRequestHandler.a(SourceFile:137) en com.businessobjects.reports.sdk.JRCCommunicationAdapter.(SourceFile:228) ... 9 más
Pedro Pascal
Se unió el 07/03/2018
Pinterest
Telegram
Linkedin
Whatsapp

4 Respuestas

0
Cargando...

danielleevandenbosch - En realidad, esta sigue siendo una pregunta abierta para mí.

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019
0
Cargando...

Estoy teniendo el mismo problema exacto. ¿Pudiste resolverlo alguna vez?

Respondido el 15/04/2024
LUCIANO RIOJA GHIOTTO
Se unió el 13/07/2019

contacto@primeinstitute.com

(+51) 1641 9379
(+57) 1489 6964

© 2024 Copyright. Todos los derechos reservados.

Desarrollado por Prime Institute

¡Hola! Soy Diana, asesora académica de Prime Institute, indícame en que curso estas interesado, saludos!
Hola ¿Puedo ayudarte?