Sie sind auf Seite 1von 34

PDF printing with APEX

|> A cost-free alternative


Dietmar Aust
Opal-Consulting, Germany / Cologne
www.opal-consulting.de

Agenda
PDF Printing with APEX
Your Choices

JasperReports / iReport Designer


Integration

Introducing Opal
Consulting
Building Web Applications for 12 years
Portal, Reports, OWA Toolkit, now APEX!

Dipl.-Inform. Dietmar Aust, Freelance Consultant


Master's Degree in Computer Science (MSCS)

1997-2000: Consultant at Oracle Germany


Since 09/2000: Freelance Consultant
Blog
http://daust.blogspot.com/

Why PDF?
What do we need PDF for?
Customers have reason to want print-quality
Forms, orders, invoices, proposals
Standard company reports (widely distributed)
Pixelperfect designs adhering to the corporate layout
High-end Reporting
Complex
Control over each pixel
Logos / images
Dynamic content
Hide / Show information conditionally
Authorization (internal / external view, e.g. proposal)

Why PDF?
Could use pl/pdf
Write plsql code to generate the report
Complexity is growing fast
Many lines of code with a lot of formatting information
Logic mixed with layout

Hard to maintain
Changing the report
Lack of easy formatting, alignment, grouping,
previews

=> dont program your reports!

Samples

Your Choices
URL Interfaces

APEX Standard Support


(Apache FOP / Cocoon)

PDF Generation
with APEX

JasperReports /
iReport Designer

APEX Advanced Support


(BI-Publisher)

APEX Standard Support


Printing of report regions
Enabled on a report
Choose format
(only PDF and RTF)

Choose layout
Define basic print attributes declaratively
Which columns to include and their width
Header, footer, etc.
Fonts, sizes, colors, etc.

APEX Standard Support


Printing of report queries
Define a report query (and session
variables)
Multiple queries possible

Custom layouts using


XSLT syntax

APEX Standard Support


Apache /
mod_plsql

How does it work?

1
APEX

1: Client clicks on a link


APEX retrieves the layout
(in XSL) and generates the
data (in XML) for the report

Client

2: APEX posts the data and the


report definition to a J2EE Server together
3: Merge both via an XSLT transformation
XSL/FO (PDF)
Cocoon (PDF + RTF)

J2EE Server

APEX Standard Support


Conclusion
Complex reports hard to achieve
No layout tool available for xsl-fo
Very limited control over appearance
Business logic hard to implement (only in
xsl)
=> painful

APEX Advanced Support


BI-Publisher features:
APEX Standard Support
RTF templates using MS Word
Identical architecture as Standard Support

Pros
Dont have to rebuild a look-alike template
Business users can specify their reports

Expensive
Technically elegant solution

URL-Interfaces
Using ANY reporting engine that provides a web gateway
Crystal reports, Oracle Reports, etc.
http://<server>/<gateway>?
r=<reportName>&p=<parameters>&f=<reportFormat>

Design your report using a report design tool


Easy to integrate using a plain hyperlink:
<a href=
http://<server>/<gateway>?r=<reportName>&p=<parameters>
&f=<reportFormat>>run
report</a>

Problems:
Authentication Who am I?
Authorization May I run this report / see this data?

URL Interface with


HTTP Tunnel Integration
Using an URL-Interface securely?
APEX works as a proxy between the user
and the reporting engine
Only APEX communicates directly with
Apache /
mod_plsql
1
the reporting engine
APEX
using UTL_HTTP
Client
2
Hide J2EE server behind firewall
Authentication
Authorization
J2EE / Tomcat
Berichtsdefinitionen
Daten aus Oracle mit
JDBC

URL Interface with


HTTP Tunnel Integration
How does the JasperIntegration work?

Apache /
mod_plsql

1: Client clicks on a link

APEX
Client

2: APEX calls the JasperIntegration in


the J2EE Server (Tomcat) and passes
just the parameters (report_name,
connect information, report parameters)
3: JasperReports starts a database connection
and generates the report

J2EE / Tomcat
Report
Definition file

JasperReports
JasperReports
Very popular reporting engine (BIRT /
JasperReports)
Java library, to integrate / embed reporting
functions into your java application
Many open source projects and large
customers are using it and shipped as part
of JBOSS

Report definition in XML (report.jrxml)

JasperReports - Functions
Features
Data sources: JDBC, XML, OLAP, TEXT,
Multiple data sources per report
Output formats: PDF, XLS, HTML, CSV, TEXT, RTF, ODF
Matrix reports
Report trigger
Subreports / modularization
Reusuability / company header in a single file

Conditional formatting (styles)


Conditional rendering (Java, Groovy, Javascript)
Fonts, Unicode, NLS

JasperReports - Samples

JasperReports - Samples

JasperReports - Samples

iReport Designer
iReport Designer
Graphical editor to create the XML
definition file for JasperReports visually

Download
http://ireport.sourceforge.net/

iReport Designer - GUI

iReport Designer - Demo


Demo

Integration as external
report
Integration into your APEX application
Report definition in the J2EE application
Call from APEX
URL for the onDemandProcess

f?
p=&APP_ID.:0:&APP_SESSION.:APPLICATION_PROCESS=prc_show_url:::F_TMP_1:&F
_TMP_1.

OnDemand Prozess prc_show_url

xlib_http_pck.display_url_raw(p_url =>
'http://localhost:8080/jasperIntegration/report?_repName=Departments' ||
'&p_deptno=' || v('F_TMP_1'));

Integration
Implementing the HTTP
Tunnel

BEGIN
l_http_request := UTL_HTTP.begin_request (p_url);

DBMS_LOB.createtemporary (l_blob, FALSE);


BEGIN
LOOP
UTL_HTTP.read_raw (l_http_response, l_raw, l_buffer_size);
DBMS_LOB.writeappend (l_blob, UTL_RAW.LENGTH (l_raw), l_raw);
END LOOP;
EXCEPTION
WHEN UTL_HTTP.end_of_body
THEN
UTL_HTTP.end_response (l_http_response);
END;
HTP.p ('Content-length: ' || DBMS_LOB.getlength (l_blob));
OWA_UTIL.http_header_close;
WPG_DOCLOAD.download_file (l_blob);
DBMS_LOB.freetemporary (l_blob);
END;

Integration
Implementing the
Servlet
/ J2EE app
Skeleton
for implementing the servlet
// get a connection from the connection pool
ds = (DataSource) initContext.lookup("java:comp/env/jdbc/"
+ dataSource);
conn = ds.getConnection();
// fill the report with the data
jasperPrint = JasperFillManager.fillReport(reportFileName
+ ".jasper", reportParams, conn);
ServletOutputStream out = response.getOutputStream();
// Export the report into a PDF stream
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporter.exportReport();

Demo of the packaged


integration
Demo of the simplified API / packaged
integration
http://www.opal-consulting.de/apex/f?
p=120

Usage of the API


Display directly in the browser
Return BLOB
Send email
Insert into database table

XML Feed Integration


XML Feed integration
Still experimental, emulation of what the BIPublisher does
Real replacement of the BI-Publisher

XML Feed Integration


Create a report query in APEX
Export the XML definition
Create a report layout in iReportDesigner based on
this XML file
Upload the report layout (.jrxml)
Define the report layout on a region
J2EE application:
Compiles the XML file into a binary (.jrxml => .jasper)
Fills the report with the XML feed
Returns the result

XML Feed Integration


Demo
http://www.opal-consulting.de/apex/f?
p=116

Summary
Dont program your reports !!!
JasperReports: cost-free, stable, performant and
flexible (API)
iReport Designer: cost-free, intuitive, powerful and
straightforward to use
Integration in APEX: easy and secure
RTF Export not perfect
Textfields / Frames not easy editable
No margins in the document
Still a learning curve, but not too steep

Available for FREE!


Giving back to the community
For a download contact me at:
Dietmar.aust@opal-consulting.de

The package will be available in a few


weeks

Q&A

Q&A
Contact:

Opal-Consulting Dietmar Aust


Web: http://www.opal-consulting.de
Blog: http://daust.blogspot.com/
E-Mail: dietmar.aust@opal-consulting.de

Das könnte Ihnen auch gefallen