Beiträge getagged mit birt
openSUSE 10.3 und Ghostscript
Gestern ging mir der Hintern geringfügig auf Grundeis: am morgigen Freitag ist Rollout unseres ZABOS-Systems, die letzten Bugs sind soweit gefixt gewesen. Nach Ende einer Alarmierung (Details zu ZABOS gibt es unter http://www.zabos.info) sollte automatisch ein Abschluss-Report gedruckt werden. An sich auch gar kein Problem, da die mit BIRT erzeugten Reporte per lpr gedruckt werden sollten.
Allerdings lief auf dem Server noch Ghostscript in der Version 8.1.x, die bei der pdf2ps-Konvertierung den Fehler
**** Warning: An error occurred while reading an XREF table. **** The file has been damaged. This may have been caused **** by a problem while converting or transferring the file. **** Ghostscript will attempt to recover the data.
schmiss. Grund dafür war, dass die installierte Ghostscript-Version noch nicht mit dem PDF-Format 1.5 klar kommt. BIRT erzeugt aber die PDFs in diesem Versions-Format. Eine Möglichkeit, eine ältere PDF-Formatsversion zu benutzen, habe ich nicht gefunden.
Ich hatte also nun die Option, das komplette, auf openSuSE basierende System, von 10.3 auf 11.2 zu upgraden oder aber die aktuelle Ghostscript-Version 8.70 zu kompilieren, in der der Fehler gefixt war.
Das Upgrade von 10.3 auf 11.2 mit Hilfe von zypper schlug fehl, da mir zypper ein std::bad_alloc() lieferte. Im Internet wurde ich nicht fündig, und die Zeit für das Debuggen hatte ich nicht.
Somit wurde die Option ersetzt durch “Server frisch aufsetzen und die komplette Umgebung anpassen”.
Da ich eher der Debian/Ubuntu-Mensch bin, hatte ich da so meine Abneigung gegen. Deshalb versuchte ich, Ghostscript manuell zu kompilieren. Als Paketabhängigkeiten müssen tiff-*-devel und cups-*-devel per YaST installiert werden, ein make && make install führte dann auch zum Erfolg.
Using BIRT and PHP without Zend Plaform
Verfasst von Schakko unter Arbeit, Java, Open Source, PHP, Publikationen am 24. April 2007
Oh well… my first blog entry in English, because I think this article is interesting for all the PHP developers out there – including non-German people
Every developer will reach the point generating reports for the running project. Making reports with Java oder .NET is relatively easy. Products like Crystal Reports (commercial) or BIRT (open source) support developers in designing and creating pleasant reports.
PHP can be extended with the function of BIRT with buying the Zend Platform. But in most cases the minority of people is able to buy this product. Zend Platform costs around 1000$ – 1500$ for a one year license.
Our development team had the problem of generating reports with PHP more than one time. In our last project we used FOP + XSL/XSLT from the Apache Foundation and triggered the report building by using exec() and command line.
The problem with FOP is that it is highly memory intensive and the building of XSLT templates is time consuming – if you do not have nice tools for that.
Last week I investigated and evaluated BIRT for using it in a J2EE/GWT-based application we are programming. The BIRT Designer is a nice tool for creating reports in HTML and/or PDF and we will (hopeley) include it in our project.
I demonstrated the results Christoph who was really amazed of it. Christoph said “Well… it would be so nice using BIRT with PHP for ZABOS (ZABOS is our SMS Alert System). But Zend Platform is sooo expensive.” (mimimi)
It was friday afternoon and nothing more was to do so I decided to look for reporting mechanisms in PHP. The results were… let’s say: poor
The next idea was triggering BIRT from command line via PHP exec()’s method. I wrote a wrapper class in Java, which could be used to start BIRT from command line (using java -jar de.ecw.birt.BIRTRunner –help).
After some minutes of coding and testing this class worked like a charme. I was happy, but I thought “Woah… It would be nice using Java directly from PHP”. I remembered that there was a PHP module called php_java which could access Java through the JNI (Java Native Interface). But all the comments on php.net said the old php_java module is more than deprecated and does not work. The newer commentator said that the php/Java-Bridge was a worth checking at. Hm… I read the documentation of the php/Java-Bridge and was enthusiastic: This was exactly what I needed.
I downloaded the latest release and was a little bit confused about the different files and JARs.
The solution is easy: Unpack the JavaBridge.war archive. The folder /java is needed in your PHP project path and includes all classes for connecting to the JavaBridge-server.
The file /WEB-INF/lib/JavaBridge.jar must be extracted to a directory of your choice (= $path-to-java-bridge). Please create inside this directory another directory called ‘lib’.
Your folder must look like this:
/java-bridge
JavaBridge.jar
/lib
Afterwards I started the server:
cd $path-to-java-bridge java.exe -Dphp.java.bridge.base=$path-to-java-bridge -jar JavaBridge.jar SERVLET:8080 6 php-java-brige.log
The log file did not show any error so I tried a simple “Hello world” in Java and PHP:
<?php
// index.php
require_once("java/Java.inc");
$aString = new Java("java.lang.String", "Hello world");
print $aString;
?>
Really nice: PHP connected to the local JavaBridge server. The JavaBridge instantiates a new String-object an called the toString() method. This was exactly what I needed for using php/Java-bridge with BIRT.
I refactored my own BIRTRunner class so that I just needed to call 4 methods and I got the desired result.
The appended .jar file must be extracted to the $path-to-java-bridge/lib, and you must restart the JavaBridge AND Apache. There seems to be an issue with UTF-8/JavaBridge/Apache.
My index.php had to be refactored too:
<?php
// index.php
// require JavaBridge interface
require_once("java/Java.inc");
// set encoding to UTF-8
java_set_file_encoding("UTF-8");
// remove try-/catch-block if not using PHP5
try
{
// where our reports are stored
$targetFile = "d:/result.html";
// ConcreteTask encapsulate the logic
$birtTask = new Java("de.ecw.birt.task.ConcreteTask");
// the home of your BIRT-runtime directory
$birtTask->setEngineHome('D:\Development\BIRT_Runtime\ReportEngine');
// the path of your BIRT report design
$birtTask->setReportPath('D:\Development\BIRT\workspace\CAPlan\user.rptdesign');
// create new render options
$htmlRenderOptions = new Java("org.eclipse.birt.report.engine.api.HTMLRenderOption");
$htmlRenderOptions->setOutputFileName($targetFile);
$birtTask->setRenderOption($htmlRenderOptions);
// run the BIRT task
$birtTask->run();
// get file content and print to browser
$content = file_get_contents($targetFile);
echo $content;
}
catch (JavaException $e)
{
print $e->getMessage();
}
?>
To my surprise it worked. I had not really expected it – but I was really able to use PHP and BIRT without buying Zend Platform.
There are so many possibilities and TODOs I want to mention:
* You can create the .rptdesign on-the-fly using Smarty
* You cold write a wrapper class on PHP side so it is much easier to create reports
* … to be continued
Sag was!