Since it's introduction, Oracle APEX has evolved from a basic toolkit for small applications to an enterprise-ready platform for applications of almost any size. However, one area has been at almost a standstill since its inception: printing.
This session will discuss how to integrate PL/PDF - a 3rd party PL/SQL-based printing solution - with Oracle APEX, so that you can provide your end users with beautiful PDF reports in almost no time. It will use real-world examples and discuss now only basic reports, but also charts, templates and bar codes.
3. About the Presenter
Scott Spendolini
scott.spendolini@enkitec.com
@sspendol
Ex-Oracle Employee of 10 years
Senior Product Manager for Oracle APEX
from 2002 through 2005
Founded Sumner Technologies
in October 2005
Co-Founded Sumneva in January 2010
Joined Enkitec in June 2012
Oracle Ace Director
Co-Author, Pro Oracle Application Express
Author, Secure APEX Development Best
Practices
“Scott” on OTN Forums
3
4. About Enkitec
Oracle Platinum Partner
Established in 2004
Headquartered in Dallas, TX
Locations throughout the US & EMEA
Specialties include
Exadata Implementations
Development Services
PL/SQL / Java / APEX
DBA/Data Warehouse/RAC
Business Intelligence
4
7. APEX & Printing
APEX is over 10 years old
Initial code was started on 4-AUG-1999
As much as it has advanced over the years, there
is still no de-facto,“go to” printing solution
7
8. Poll
What printing technology do you use in
conjunction with APEX?
“Printer Friendly” Mode
Apache FOP
Crystal Reports
Jasper Reports
Oracle BI Publisher
PL/PDF
File > Print
Other
8
9. Options
Add’l
Name Ease of Use Power Cost
Server
Printer Friendly
★★★★★ Free
Mode
Apache FOP ★★★★★ ★★ ✔ Free
Jasper Reports ★★★★ ★★★★ ✔ $$
Crystal Reports ★★★★ ★★★★ ✔ $$$
Oracle BI
★★★★ ★★★★★ ✔ $$$$$
Publisher
PL/PDF ★★★ ★★★★ $
9
10. What is PL/PDF?
Third party product designed by Oranext
http://plpdf.com
Provides a set of PL/SQL based APIs that can
generate PDF files from the Oracle database
Easy to securely integrate with APEX
Can be called from a Page or Application Process
10
11. PL/PDF Features
Robust reporting engine
Charts
Bar, Line & Pie
Barcode Printing
Use Existing PDF files as Templates
TrueType Font Embedding
Encrypted PDF Documents
Native Support for PNG & JPEG images
Other types supported via Oracle InterMedia
11
12. Licensing
Licensed per instance of Oracle
$600 per instance
Can download a trial for free
5 Page Maximum
Watermark Appears on all pages
No additional hardware is required
PL/PDF installs into the same database as APEX
12
13. The BLOB!
Result of PL/PDF is nothing more than an Oracle
BLOB
Thus, you can do anything with PL/PDF output
that you can with an Oracle BLOB:
E-Mail it as an attachment
Download it to a browser
Store it in a table
Index it with Oracle Text
Schedule a procedure to
generate and e-mail PDF files
13
16. Layout & Control
All layout is handled via API calls
There is no GUI tool to design a PL/PDF report
Seems limiting, and can be at times
Template feature allows you to use any tool to create the
structure of a document and use PL/PDF APIs only to
populate the data
Also, there are APIs that minimize the amount of code
required when creating reports
16
17. Sweet Spots
PL/PDF is the best solution when:
The core report definition does not change often
End Users do not need to create one-off reports
You have an abundance of PL/SQL resources and little
money
17
19. Installation Options
PL/PDF comes with a Windows-based installer
Can use to install on any target OS
Need to be able to connect to the target database via
SQL*Net
Alternatively, you can run the scripts manually via
command prompt
In either case, installation should take about 5-10
minutes
19
20. Where to Put It
Since PL/PDF is a set of PL/SQL objects, you’ll
need to select a schema to put it in
Typically use PLPDF, but can name the schema anything
Best to use its own schema and then create
grants & synonyms to access from other schemas
You’ll need to do this manually
Start with just PLPDF & PLPDF_TYPE; synonyms for other
objects can be added as needed
20
22. APEX Integration
Once installed and the corresponding grants are
created to your parse as schema, there is
NOTHING ADDITIONAL TO CONFIGURE in order to
integrate PL/PDF with APEX
PL/PDF - like APEX - is PL/SQL
Thus, as long as your parse-as schema can access the
PL/PDF objects, that’s all you’ll need
Seriously.
There’s nothing else to configure.
Try it. You’ll see.
22
23. APEX Integration
PL/PDF must be called as part of the Page
Rendering process in APEX
And it must occur before anything else
Best Practice:
Create an On Load PL/SQL Process that calls PL/PDF
Set the Condition to Request = Expression 1
Add a button/link to that page which sets the Request to
trigger the PL/PDF call
23
26. Common APIs
PL/PDF is nothing more than a set of PL/SQL APIs
Like any other API set, there’s a learning curve
Most APIs have default values on most
parameters
Thus you only need to pass values to those you wish to set
Use param => value notation for best results
Refer to the documentation for full details
26
28. init
Called once to initialize PL/PDF
Parameters:
p_orientation
p_unit
p_format
28
29. newPage
Creates a new page
Called anytime a new page is needed
PL/PDF will automatically create a new page when
needed if data overflows the current page
Parameters:
p_orientation
29
30. setPrintFont
Sets the font family and style used for text
Parameters:
p_family
p_style
p_size
30
31. printCell
Prints a line of text on the page
Parameters:
• p_w • p_align
• p_h • p_fill
• p_txt • p_link
• p_border • p_clipping
• p_ln
31
38. setColor4Text
Sets the font color used for text
Parameters:
p_r
p_g
p_b
Alternatively:
p_color
38
39. setColor4Filling
Sets the background color used for text
Parameters:
p_r
p_g
p_b
Alternatively:
p_color
39
40. API for the API
In some cases, you may want to create your own
API to simplify the number of PL/PDF API calls
required
For example, a single API can consolidate the
following three PL/PDF APIs:
setPrintFont
setColor4Text
setColor4Filling
40
41. set_font API
PROCEDURE set_font
(
p_family IN VARCHAR2 DEFAULT 'Arial',
p_size IN NUMBER DEFAULT 10,
p_style IN VARCHAR2 DEFAULT NULL,
p_r IN NUMBER DEFAULT 0,
p_g IN NUMBER DEFAULT 0,
p_b IN NUMBER DEFAULT 0,
p_r_bkg IN NUMBER DEFAULT 255,
p_g_bkg IN NUMBER DEFAULT 255,
p_b_bkg IN NUMBER DEFAULT 255
)
IS Called without parameters, the font will
be set to Arial 10 normal (black on white)
BEGIN
41
43. Download File API
You can also create a single procedure to handle
file downloads
Pass in the BLOB and filename
All PL/PDF reports can call this procedure
In fact, it is recommended that PL/PDF reports
be based on a package
Reusability
Security
43
47. Note on Privileges
The procedure named in the header and footer
calls must be able to be called by the schema in
which PL/PDF is installed
Not a problem is PL/PDF is installed in the same schema
as your PL/SQL
You can not pass parameters to this procedure
directly, but can do so via SYSCONTEXT
47
50. Printing a Report
Whether you’re printing a report that is 1 or 100
pages, there are better, more specific APIs for
that
QUERY_PRINT
Pass a SQL Statement, get a report
ROW_PRINT
Allows you to loop through a SQL statement or Dynamic SQL and have
more control over the resulting report
50
51. query_print
Designed to enable developers to quickly take a
SQL statement and generate a PDF document
from it
Limited formatting options and control
Eight different variations are available: QUERY_PRINT_01
through QUERY_PRINT_08
51
52. query_print
Technically a one-off API not included in the
PL/PDF Distribution
Can be downloaded from PL/PDF’s site
For Developers > Examples > PLPDF-SDK > Complex
Examples > Query Print
52
55. row_print
ROW_PRINT allows for a lot more flexibility than
QUERY_PRINT
Typically called from inside a loop
FOR X IN (SELECT * FROM ...)
DBMS_SQL
Four different variations are available:
ROW_PRINT through ROW_PRINT4
55
58. Table of Contents
PL/PDF allows you to automatically crete a Table
of Contents
You can add “bookmarks” throughout your application that
link back to the main table of contents
Fully automated; no need to calculate anything
58
61. Extras
In addition to its core APIs, PL/PDF offers a
number of extra features
Templates
Charts
Bar, Line & Pie
Bar Codes
Encryption
OpenOffice Forms
TrueType Font Support
61
62. Templates
PL/PDF allows you to include a PDF template as a
background for any page
No need to use PL/PDF to create the structure of a
document; focus on filling in the data
Any PDF document can be used
Easy to create PDF documents from Word, Acrobat, etc.
62
66. Charts
sumnevaSERT
Settings Summary 28 out of 37 possible points 75.68%
Session Duration
0% Authentication Scheme: 1
0 out of 2 possible points
Security
60%
6 out of 10 possible points
Application Settings
84.62%
11 out of 13 possible points Session Duration: 2 Security: 4
Authentication Scheme
91.67%
11 out of 12 possible points
Application Settings: 2
Exceptions Awaiting Approval
No Data Found
Stale Exceptions
No Data Found
66
70. Summary
PL/PDF provides a robust, cost effective
solution for producing high quality PDF
documents from any APEX application
Not always the right tool for every job; but in many cases,
it works quite well
Low cost and zero footprint means that it should at least
be seriously considered
70
71. Download
This and all other Enkitec presentations can be
downloaded for free from:
http://enkitec.com/presentations
71