the pdf file is created but cannot be opened

313 views Asked by At

From my PHP page I want to create/launch a BIRT report :

...
new runReport("rptPrixParDaty.rptdesign", array(), "prixpardaty");

The report is based on a view.

Code of runReport which is inside /birt/ :

<?php

include("../config.inc.php");
require_once("java/Java.inc");

class runReport {

    function runReport($report, $param, $output) {

        header("Content-type: application/pdf");
        header("Content-Disposition: attachment; filename=".$output.".pdf");

        $report_name = RP_REPORT . $report;
        $ctx = java_context()->getServletContext();
        $birtReportEngine = java("org.eclipse.birt.php.birtengine.BirtEngine")->getBirtEngine($ctx);
        java_context()->onShutdown(java("org.eclipse.birt.php.birtengine.BirtEngine")->getShutdownHook());

        try{

            $connect = new Java("connectDb");

            $report = $birtReportEngine->openReportDesign($report_name);
            $task = $birtReportEngine->createRunAndRenderTask($report);

            foreach ($param as $key => $value) {
                $task->setParameterValue($key, new java("java.lang.String",$value));
            }

            $taskOptions = new java("org.eclipse.birt.report.engine.api.PDFRenderOption");
            $outputStream = new java("java.io.ByteArrayOutputStream");
            $taskOptions->setOutputStream($outputStream);
            $taskOptions->setOutputFormat("pdf");

            $task->setRenderOption( $taskOptions );
            $task->getAppContext()->put("OdaJDBCDriverPassInConnection", $connect->getConnection(BDD_SERVER, BDD_PORT, BDD_NAME, BDD_USER, BDD_PWD));
            $task->run();
            $task->close();


        } catch (JavaException $e) {

            echo $e; //"Error Calling BIRT";
        }

        echo java_values($outputStream->toByteArray());

    }
}
?>

The config.inc.php file contains constants , it resides in the root directory of the web project. The log file generated by the web app contains this warning line : PHP Warning: include(../config.inc.php): failed to open stream: No such file or directory in D:\wamp\www\bazarmada\birt\runReport.php on line 3 Although the file config.inc.php resides in the root directory and the runReport.php file is inside /birt directory !

At runtime the download executes and the pdf file has 3Kb as size , but the pdf file cannot be opened ! So what is wrong ?

1

There are 1 answers

0
hvb On BEST ANSWER

This is not a BIRT question, but a PHP question.

Probably the "PDF" in the result contains an exception traceback, a HTML error page or something similar.

What you should do now is:

  • Fix the PHP import error! While I don't know PHP, I guess the config.inc.php file should be placed in D:\wamp\www\bazarmada !?

  • Save the response to a local file and look at this file with a hex editor or text editor. This should help you to find out what else is going wrong in your script.