Skip to content

Commit f5f3caa

Browse files
committed
Initial commit
0 parents  commit f5f3caa

File tree

250 files changed

+19807
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

250 files changed

+19807
-0
lines changed

LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 Hélder Duarte
4+
Copyright (c) 2015 Leandro Bitencourt
5+
Copyright (c) 2015 Daniel Rodrigues
6+
Copyright (c) 2015 Jefferson Barreto
7+
8+
Permission is hereby granted, free of charge, to any person obtaining a copy of
9+
this software and associated documentation files (the "Software"), to deal in
10+
the Software without restriction, including without limitation the rights to
11+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12+
the Software, and to permit persons to whom the Software is furnished to do so,
13+
subject to the following conditions:
14+
15+
The above copyright notice and this permission notice shall be included in all
16+
copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
# JasperReports for PHP
2+
3+
Package to generate reports with [JasperReports 6](http://community.jaspersoft.com/project/jasperreports-library) library through [JasperStarter v3](http://jasperstarter.sourceforge.net/) command-line tool.
4+
5+
##Install
6+
7+
Install [Composer](http://getcomposer.org) if you don't have it.
8+
```
9+
composer require lavela/phpjasper
10+
```
11+
Or in your 'composer.json' file add:
12+
13+
```javascript
14+
{
15+
"require": {
16+
"lavela/phpjasper": "1.0",
17+
}
18+
}
19+
```
20+
21+
And the just run:
22+
23+
composer install
24+
25+
and thats it.
26+
```
27+
28+
##Introduction
29+
30+
This package aims to be a solution to compile and process JasperReports (.jrxml & .jasper files).
31+
32+
###Why?
33+
34+
Did you ever had to create a good looking Invoice with a lot of fields for your great web app?
35+
36+
I had to, and the solutions out there were not perfect. Generating *HTML* + *CSS* to make a *PDF*? WTF? That doesn't make any sense! :)
37+
38+
Then I found **JasperReports** the best open source solution for reporting.
39+
40+
###What can I do with this?
41+
42+
Well, everything. JasperReports is a powerful tool for **reporting** and **BI**.
43+
44+
**From their website:**
45+
46+
> The JasperReports Library is the world's most popular open source reporting engine. It is entirely written in Java and it is able to use data coming from any kind of data source and produce pixel-perfect documents that can be viewed, printed or exported in a variety of document formats including HTML, PDF, Excel, OpenOffice and Word.
47+
48+
I recommend using [Jaspersoft Studio](http://community.jaspersoft.com/project/jaspersoft-studio) to build your reports, connect it to your datasource (ex: MySQL), loop thru the results and output it to PDF, XLS, DOC, RTF, ODF, etc.
49+
50+
*Some examples of what you can do:*
51+
52+
* Invoices
53+
* Reports
54+
* Listings
55+
56+
##Examples
57+
58+
###The *Hello World* example.
59+
60+
Go to the examples directory in the root of the repository (`vendor/lavela/phpjasper/examples`).
61+
Open the `hello_world.jrxml` file with iReport or with your favorite text editor and take a look at the source code.
62+
63+
#### Compiling
64+
65+
First we need to compile our `JRXML` file into a `JASPER` binary file. We just have to do this one time.
66+
67+
**Note:** You don't need to do this step if you are using *Jaspersoft Studio*. You can compile directly within the program.
68+
69+
```php
70+
71+
require __DIR__ . '/vendor/autoload.php';
72+
73+
use JasperPHP\JasperPHP;
74+
75+
$input = __DIR__ . '/vendor/lavela/phpjasper/examples/hello_world.jrxml';
76+
77+
$jasper = new JasperPHP;
78+
$jasper->compile($input)->execute();
79+
```
80+
81+
This commando will compile the `hello_world.jrxml` source file to a `hello_world.jasper` file.
82+
83+
**Note:** If you are using Laravel 4 run `php artisan tinker` and copy & paste the command above.
84+
85+
####Processing
86+
87+
Now lets process the report that we compile before:
88+
89+
```php
90+
91+
require __DIR__ . '/vendor/autoload.php';
92+
93+
use JasperPHP\JasperPHP;
94+
95+
$input = __DIR__ . '/vendor/lavela/phpjasper/examples/hello_world.jasper';
96+
$output = __DIR__;
97+
98+
$jasper = new JasperPHP;
99+
100+
$jasper->process(
101+
$input,
102+
$output,
103+
array("pdf", "rtf")
104+
)->execute();
105+
```
106+
107+
Now check the examples folder! :) Great right? You now have 2 files, `hello_world.pdf` and `hello_world.rtf`.
108+
109+
Check the *API* of the `compile` and `process` functions in the file `src/JasperPHP/JasperPHP.php` file.
110+
111+
####Listing Parameters
112+
113+
Querying the jasper file to examine parameters available in the given jasper report file:
114+
115+
```php
116+
117+
require __DIR__ . '/vendor/autoload.php';
118+
119+
use JasperPHP\JasperPHP;
120+
121+
$input = __DIR__ . '/vendor/lavela/phpjasper/examples/hello_world_params.jrxml';
122+
123+
$jasper = new JasperPHP;
124+
$output = $jasper->list_parameters($input)->execute();
125+
126+
foreach($output as $parameter_description)
127+
print $parameter_description . '<pre>';
128+
```
129+
130+
###Advanced example
131+
132+
We can also specify parameters for connecting to database:
133+
134+
```php
135+
136+
require __DIR__ . '/vendor/autoload.php';
137+
138+
use JasperPHP\JasperPHP;
139+
140+
$input = __DIR__ . '/vendor/lavela/phpjasper/examples/hello_world.jrxml';
141+
$output = __DIR__;
142+
143+
$jasper = new JasperPHP;
144+
$jasper->process(
145+
$input,
146+
$output,
147+
array("pdf", "rtf"),
148+
array("php_version" => phpversion()),
149+
array(
150+
'driver' => 'postgres',
151+
'username' => 'vagrant',
152+
'host' => 'localhost',
153+
'database' => 'samples',
154+
'port' => '5433',
155+
)
156+
)->execute();
157+
```
158+
159+
##Requirements
160+
161+
* Java JDK 1.8
162+
* PHP [exec()](http://php.net/manual/function.exec.php) function
163+
* [optional] [Mysql Connector](http://dev.mysql.com/downloads/connector/j/) (if you want to use database)
164+
* [optional] [PostgreSQL Connector](https://jdbc.postgresql.org/download.html) (if you want to use database)
165+
* [optional] [Jaspersoft Studio](http://community.jaspersoft.com/project/jaspersoft-studio) (to draw and compile your reports)
166+
167+
168+
##Installation
169+
170+
###Java
171+
172+
Check if you already have Java installed:
173+
174+
```
175+
$ java -version
176+
java version "1.8.0_65"
177+
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
178+
Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode, sharing)
179+
```
180+
181+
If you get:
182+
183+
command not found: java
184+
185+
Then install it with: (Ubuntu/Debian)
186+
187+
$ sudo apt-get install default-jdk
188+
189+
Now run the `java -version` again and check if the output is ok.
190+
191+
###Using in Laravel 5.1!
192+
193+
```php
194+
use JasperPHP\JasperPHP as JasperPHP;
195+
196+
Route::get('/', function () {
197+
198+
$input = __DIR__ . '/vendor/lavela/phpjasper/examples/hello_world.jrxml';
199+
$output = __DIR__;
200+
201+
$jasper = new JasperPHP;
202+
203+
// Process a Jasper file to PDF and RTF (you can use directly the .jrxml)
204+
$jasper->process(
205+
$input,
206+
$output,
207+
array("pdf", "rtf")
208+
)->execute();
209+
210+
return view('index');
211+
});
212+
213+
###MySQL
214+
215+
We ship the [MySQL connector](http://dev.mysql.com/downloads/connector/j/) (v5.1.34) in the `/src/JasperStarter/jdbc/` directory.
216+
217+
###PostgreSQL
218+
219+
We ship the [PostgreSQL](https://jdbc.postgresql.org/) (v9.4-1203) in the `/src/JasperStarter/jdbc/` directory.
220+
221+
##Performance
222+
223+
Depends on the complexity, amount of data and the resources of your machine (let me know your use case).
224+
225+
I have a report that generates a *Invoice* with a DB connection, images and multiple pages and it takes about **3/4 seconds** to process. I suggest that you use a worker to generate the reports in the background.
226+
227+
##Thanks
228+
229+
Thanks to [Cenote GmbH](http://www.cenote.de/) for the [JasperStarter](http://jasperstarter.sourceforge.net/) tool.
230+
231+
##Questions?
232+
233+
Drop me a line on Skype [leandro.bittencourt16]
234+
Drop me a line on Skype [danielrodrigueslima]
235+
236+
##License
237+
238+
MIT

composer.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "lavela/phpjasper",
3+
"description": "Create Reports in PHP with JasperReports",
4+
"license": "MIT",
5+
"keywords": [
6+
"reports",
7+
"jasper",
8+
"jasperreports",
9+
"reports",
10+
"pdf",
11+
"xml",
12+
"PHP",
13+
"java"
14+
],
15+
"homepage": "https://github.com/lavela/phpjasper",
16+
"authors": [
17+
{
18+
"name": "Leandro Bitencourt",
19+
"email": "leandrocintrabitencourt@gmail.com",
20+
"homepage": "http://www.leandrobitencourt.zz.mu",
21+
"role": "Developer"
22+
},
23+
{
24+
"name": "Daniel Rodrigues",
25+
"email": "danielrodrigues-ti@hotmail.com",
26+
"role": "Developer"
27+
},
28+
{
29+
"name": "Jefferson Barreto",
30+
"email": "jefferson.barreto@gmail.com",
31+
"role": "Developer"
32+
}
33+
],
34+
"minimum-stability": "dev",
35+
"require": {
36+
"php": ">=5.6.0"
37+
},
38+
"autoload": {
39+
"psr-0": {
40+
"JasperPHP": "src/"
41+
}
42+
}
43+
}

examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hello_world.jasper
2+
hello_world.pdf

examples/hello_world.jrxml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Created with Jaspersoft Studio version last-->
3+
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Characterset-Test" language="groovy" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="527ae3c1-c10e-4b41-b983-14305308c942">
4+
<property name="ireport.zoom" value="1.5"/>
5+
<property name="ireport.x" value="0"/>
6+
<property name="ireport.y" value="0"/>
7+
<background>
8+
<band/>
9+
</background>
10+
<title>
11+
<band height="72">
12+
<frame>
13+
<reportElement mode="Opaque" x="-20" y="-20" width="595" height="92" backcolor="#006699" uuid="3501dac6-be9b-47b1-bf09-8b25fbc6c79f"/>
14+
<staticText>
15+
<reportElement x="20" y="20" width="349" height="45" forecolor="#FFFFFF" uuid="2464c9ca-82a1-48c9-87ea-b68192294c4a"/>
16+
<textElement>
17+
<font fontName="Arial" size="34" isBold="true"/>
18+
</textElement>
19+
<text><![CDATA[PHPjasper Test]]></text>
20+
</staticText>
21+
</frame>
22+
</band>
23+
</title>
24+
<pageHeader>
25+
<band height="50">
26+
<line>
27+
<reportElement x="-20" y="49" width="595" height="1" forecolor="#666666" uuid="a511fbdc-5dd2-4d02-9b49-f7d8f8b0feb3"/>
28+
</line>
29+
<staticText>
30+
<reportElement x="14" y="19" width="521" height="30" uuid="6f85b46e-f5b1-4f07-b38c-aa0f6bf985e3"/>
31+
<textElement>
32+
<font fontName="Arial"/>
33+
</textElement>
34+
<text><![CDATA[Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum]]></text>
35+
</staticText>
36+
</band>
37+
</pageHeader>
38+
<columnHeader>
39+
<band height="5"/>
40+
</columnHeader>
41+
<detail>
42+
<band height="400">
43+
<staticText>
44+
<reportElement x="14" y="15" width="521" height="24" uuid="c15d0e17-2850-4010-b65a-e4822a371ba3"/>
45+
<textElement>
46+
<font fontName="Arial" size="15"/>
47+
</textElement>
48+
<text><![CDATA[Hello World !!!]]></text>
49+
</staticText>
50+
</band>
51+
</detail>
52+
<columnFooter>
53+
<band/>
54+
</columnFooter>
55+
<pageFooter>
56+
<band height="17">
57+
<textField>
58+
<reportElement mode="Opaque" x="0" y="4" width="515" height="13" backcolor="#E6E6E6" uuid="470071d6-9789-41e5-b8f6-3e4340cc0ab2"/>
59+
<textElement textAlignment="Right"/>
60+
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
61+
</textField>
62+
<textField evaluationTime="Report">
63+
<reportElement mode="Opaque" x="515" y="4" width="40" height="13" backcolor="#E6E6E6" uuid="f64278b8-d5b7-41e6-a40d-0e8929c0b848"/>
64+
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
65+
</textField>
66+
<textField pattern="EEEEE dd MMMMM yyyy">
67+
<reportElement x="0" y="4" width="100" height="13" uuid="2696db9f-481e-441c-8557-40163e951201"/>
68+
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
69+
</textField>
70+
</band>
71+
</pageFooter>
72+
<summary>
73+
<band/>
74+
</summary>
75+
</jasperReport>

0 commit comments

Comments
 (0)